Skip to content

Commit

Permalink
Merge pull request #113 from Vmadmax/master
Browse files Browse the repository at this point in the history
Add function to set api url
  • Loading branch information
sgiehl committed Mar 7, 2023
2 parents 78932f6 + 196dc8e commit 23cea26
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MatomoTracker.php
Expand Up @@ -172,6 +172,11 @@ public function __construct($idSite, $apiUrl = '')
$this->incomingTrackerCookies = [];
}

public function setApiUrl(string $url)
{
self::$URL = $url;
}

/**
* By default, Matomo expects utf-8 encoded values, for example
* for the page URL parameter values, Page Title, etc.
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/MatomoTrackerTest.php
Expand Up @@ -71,4 +71,14 @@ public function test_trackingWithPreMatomo4CookieSetsCorrectUrl()
$expected = 'http://mymatomo.com/matomo.php?idsite=1&rec=1&apiv=1&_idts=1583298245&_id=b446c233274f79f0&url=http%3A%2F%2Fsomesite.com&urlref=&action_name=test+title';
$this->assertEquals($expected, $url);
}

public function test_setApiUrl()
{
$newApiUrl = 'https://NEW-API-URL.com';
$tracker = new \MatomoTracker(1, self::TEST_URL);
$tracker->setApiUrl($newApiUrl);
$url = $tracker->getUrlTrackPageView('test title');

$this->assertSame(substr($url, 0, strlen($newApiUrl)), $newApiUrl);
}
}

0 comments on commit 23cea26

Please sign in to comment.