vigetlabs / trackomatic

A high-performance tracking enhancement for Google Analytics.
Apache License 2.0
33 stars 4 forks source link

Trackomatic cause not sending tracking data to GA servers #38

Open arcao opened 8 years ago

arcao commented 8 years ago

Hi guys,

I am trying to integrate trackomatic at one of my web, but when I try to add trackomatic as a GA plugin via ga('require', 'trackomatic'); it cause not sending tracking data back to GA server.

There is my test HTML content:

<!DOCTYPE html>
<html lang="cs">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <title>test</title>
  <!-- Google Analytics -->
  <script src="https://d1lmnvs8gamzin.cloudfront.net/1.1.1/trackomatic.dev.js"></script>
  <script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'UA-123456-123456', {
      'siteSpeedSampleRate': 50
    });
    ga('require', 'trackomatic', {debug: true});
    ga('require', 'linkid');
    ga('send', 'pageview');
  </script>
  <script async src='https://www.google-analytics.com/analytics.js'></script>
  <!-- /Google Analytics -->
</head>
<body></body>
</html>

Note: I am using dev version because of debugging. I know that for production should be used minified version.

The same HTML is placed on this webpage: http://test.arcao.com/trackomatic-test.html

When I comment ga('require', 'trackomatic', {debug: true}); line, the tracking data are successfully sent to GA server.

Thank you for any help.

awavering commented 8 years ago

Hi Martin, thanks for the ticket! I've had a busy few weeks, but I'll try to check this out later this week.

Cheers.

arcao commented 8 years ago

Hi @awavering, any news?

awavering commented 8 years ago

Hey @arcao, thanks for the bump. Commenting out the trackomatic line works because the GA snippet no longer waits for the trackomatic javascript to load. This is actually a pretty simple fix - because of the way the GA plugin system is architected, plugin javascript needs to be loaded after the main GA snippet:

`

` "Because both the analytics.js library and analytics.js plugins are loaded asynchronously, it can be a challenge to know when plugins are fully loaded and ready to be used. The analytics.js library solves this problem by halting the execution of the command queue when it encounters a require command for a plugin that isn't yet loaded. Once the plugin is loaded, queue execution continues as normal. As a result, it's extremely important that you test the plugins you're using to ensure they load and run correctly. If a plugin fails to load or has an error, it will prevent all subsequent analytics.js commands from executing." - https://developers.google.com/analytics/devguides/collection/analyticsjs/using-plugins