@tsteur opened this Pull Request on November 21st 2016 Owner

refs https://github.com/piwik/piwik/issues/10878

This is PR for Piwik 3 for https://github.com/piwik/piwik/pull/10888

To test use eg

<script type="text/javascript" src="//apache.piwik/piwik.js"></script>

Then initialize tracker after document was loaded via _paq.push. You will see a console message and no created tracker. When using _paq.push for tracking, the Tracker needs to be configured upfront. Otherwise bugs may occur.

@tsteur commented on November 21st 2016 Owner

Updated PR to still track but also log a message

@tsteur commented on November 21st 2016 Owner

Updated PR again to not track when tracker is not initialized upfront

@mattab commented on December 1st 2016 Owner
  • Ideally when the user calls setTrackerUrl and setSiteId even after the tracker was initialised, the tracker should initialise without error. Ie. the following code should not trigger an error but currently it does:
<!-- Piwik -->
<script type="text/javascript">
  var u="//localhost/piwik-master/";

  (function() {
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);

  var _paq = _paq || [];

setTimeout(function() {
  _paq.push(['setTrackerUrl', u+'piwik.php']);
  _paq.push(['setSiteId', '1']);
  _paq.push(["setCustomVariable", 1, "", "", "visit"]);
}, 1000);
<!-- End Piwik Code -->
  • If we don't init tracker when setSiteId/setTrackerUrl were called in the right order (even after tracker init), then we should track the data for sure, or alternatively not merge PR for now

  • Suggested message: Piwik Analytics error: _paq.push() was used before the Piwik tracker was correctly initialized. To initialise the tracker please make sure to first call the two methods 'setTrackerUrl' and 'setSiteId' via _paq.push(). Alternatively, if you do not use _paq.push you may intialise the Piwik tracker via: 'Piwik.getTracker( trackerUrl, siteId )' and call methods on the object returned by getTracker.

  • you wrote in the message: but it may fully work as tracker methods may not be executed in the correct order. for the Piwik.addTracker() method -> do you maybe have an example?
@tsteur commented on December 1st 2016 Owner

There are plenty of reasons why it won't fully work just search for issues in the issue tracker that are related to order. Eg we create cookies even though we shouldn't , or create cookies wrong domain etc.

I can't do anything else here. Happy to close PR and it just won't keep working for users. Here was suggestion on top for https://github.com/piwik/piwik/issues/10797#issuecomment-263140282 but I likely won't find any time to work on it

@tsteur commented on December 1st 2016 Owner

Also see comments where we discussed it. Eg custom tracker plugins won't be working with it etc

This Pull Request was closed on December 13th 2016
Powered by GitHub Issue Mirror