Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not possible to create multiple Piwik tracker instances having different API urls #42

Closed
wants to merge 1 commit into from

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Feb 4, 2019

if (empty($this->trackerUrl) && !empty(self::$URL)) {
// for BC
$this->trackerUrl = self::$URL;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think $URL should override $this->trackerUrl? I'm thinking of the following situation:

$tracker = new PiwikTracker('http://mymatomo1.com/piwik.php'); // trackerUrl property set to mymatomo1.com
...
PiwikTracker::$URL = 'http://myothermatomo2.com/piwik.php';
$tracker->doTrackPageView(...); // trackerUrl overrides $URL so mymatomo1 is used instead of myothermatomo2.com

Actually I'm not too sure how to fix this... Maybe there needs to be two properties, $originalTrackerUrl set in the constructor and $trackerUrl set by the method. Where $trackerUrl overrides everything, but if not set, self::$URL is used? This isn't as simple as I thought it was...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm not sure either. That's why I mentioned BC and being difficult. The problem is the next tracker creation new Tracker() would also call ::$URL = '...' and overwrite that... was thinking to remove self::$URL = ... in constructor but then we regress there. Not sure what is used more than the other... maybe we need to wait for Matomo 4 with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could add an options parameter like this:

$tracker = new PiwikTracker($idSite, 'myurl', [ 'doNotUseGlobalUrl' => true ]);

And maybe issue a warning or notice when doNotUseGlobalUrl isn't set to true?

Then in Matomo 4 we get rid of the option. At least this way, the bug doesn't cause problems in the meantime.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we need to set it to false by default re BC? Users wouldn't be aware they need to change this parameter when they update (even when we mention it in changelog it would go mainly unnoticed). But at least with the option there be a way to restore old behaviour. Let's see what @mattab thinks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, would need to be false by default. I think this solution would mostly be for us not running into it, though if we could issue a warning of some kind w/o causing any issues, users might notice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but don't know what is the best solution here. But sounds good to throw a warning to help people notice their code might be mis-behaving.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsteur any new thoughts on this conversation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't do anything before Matomo 4 I reckon

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll remove this from the current sprint.

@diosmosis diosmosis modified the milestones: Current sprint, Backlog Nov 5, 2019
@tsteur tsteur removed the request for review from mattab December 5, 2022 06:44
@tsteur
Copy link
Member Author

tsteur commented Dec 5, 2022

I'll close this one. If someone continues working on #14 this could be reused and the same changes could be applied to MatomoTracker

@tsteur tsteur closed this Dec 5, 2022
@tsteur tsteur deleted the 14 branch December 5, 2022 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not possible to create multiple Piwik tracker instances having different API urls
3 participants