madelinelise
1/4/2017 - 6:46 PM

Handling multiple google analytics accounts

Handling multiple google analytics accounts

var current_path = window.location.pathname.toLowerCase();
var url_list = [
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x'],
  ['str', 'UA-xxxxxxxx-x']
];
for (var i = 0; i < url_list.length; i++) {
  if (current_path.indexOf(url_list[i][0]) > -1) {
    var tracking_ID = url_list[i][1]; break;
  } else {
    tracking_ID = "UA-xxxxxxx-xx";
  }
}
 
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})
(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', tracking_ID, 'auto');
ga('send', 'pageview');