Shoora
9/7/2014 - 3:57 AM

page_tracking.js

page_tracking.js

/**
  Sets up the PageTracking hook.
**/
Discourse.addInitializer(function() {
  var pageTracker = Discourse.PageTracker.current();
  pageTracker.start();

  // Out of the box, Discourse tries to track google analytics
  // if it is present
  if (typeof window._gaq !== 'undefined') { 
    pageTracker.on('change', function() {
      window._gaq.push(['_trackPageview']);
    });
  }

  // Also use Universal Analytics if it is present
  if (typeof window.ga !== 'undefined') { 
    pageTracker.on('change', function() {
      console.log('update');
      window.ga('send', 'pageview');
    });
  }
  console.log('foo');
  if (typeof window.ga !== 'undefined') {
    console.log('bar');
    var real_ga = window.ga;

    window.ga = function () {
      console.log('changenew');
      Discourse.ajax("/google/dimensions", {
        type: "GET",
        data: { path: window.location.pathname }
      }).then(function (data) {
        console.log(data);

      });
      return real_ga.call(arguments);
    }
  }
});