Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Custom Integration link is a 404 page... #630

Open
gzcheng opened this issue Mar 27, 2020 · 1 comment
Open

Custom Integration link is a 404 page... #630

gzcheng opened this issue Mar 27, 2020 · 1 comment

Comments

@gzcheng
Copy link

gzcheng commented Mar 27, 2020

The custom integration link
https://gist.github.com/cyberwombat/11008970
leads to a 404 page...

@patotoma
Copy link

Not sure why the gist was removed but I think I found the same thing on stackoverflow:

https://stackoverflow.com/a/23142642/2568259

And also pasting it directly here:

// Create a dummy analytics object until real loaded
window.analytics || (window.analytics = []);
window.analytics.methods = ['identify', 'track', 'trackLink', 'trackForm', 'trackClick', 'trackSubmit', 'page', 'pageview', 'ab', 'alias', 'ready', 'group', 'on', 'once', 'off'];
window.analytics.factory = function(method) {
  return function() {
    var args = Array.prototype.slice.call(arguments);
    args.unshift(method);
    window.analytics.push(args);
    return window.analytics;
  };
};
for (var i = 0; i < window.analytics.methods.length; i++) {
  var method = window.analytics.methods[i];
  window.analytics[method] = window.analytics.factory(method);
}

// Load analytics async
analytics.load = function(callback) {
  if (document.getElementById('analytics-js')) return;

  // We make a copy if our dummy object
  window.a = window.analytics;
  var script = document.createElement('script');
  script.async = true;
  script.id = 'analytics-js';
  script.type = 'text/javascript';
  script.src = ('https:' === document.location.protocol ? 'https://' : 'http://') + 'path/to/your/analytics.min.js';
  script.addEventListener('load', function(e) {
    if (typeof callback === 'function') {
      callback(e);
    }
  }, false);
  var first = document.getElementsByTagName('script')[0];
  first.parentNode.insertBefore(script, first);
};

analytics.load(function() {

  // On load init our integrations
  analytics.initialize({
    'Google Analytics': {
      trackingId: 'UA-XXXXXX-1'
    }
  });  
  // Now copy whatever we applied to our dummy object to the real analytics
  while (window.a.length > 0) {
    var item = window.a.shift();
    var method = item.shift();
    if (analytics[method]) analytics[method].apply(analytics, item);
  }
});

analytics.page();

Enjoy!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants