Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Dmitry-Klymenko/ccea478677117ce91e30af7b47480bf1 to your computer and use it in GitHub Desktop.
Save Dmitry-Klymenko/ccea478677117ce91e30af7b47480bf1 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Example</title>
</head>
<body dir="ltr">
Blah blah blah
<script>
(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','http://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-46076570-1', 'auto');
ga('require', 'dAKTestPlugin');
ga('send', 'pageview');
</script>
<script>
//this script could and should be loaded async
// Assign the ga variable to the Google Analytics global function
var ga = window[window['GoogleAnalyticsObject'] || 'ga'];
// Helper function for registering the Plugin
var providePlugin = function(pluginName, pluginConstructor) {
if(ga) {
ga('provide', pluginName, pluginConstructor);
}
}
// Constructor for dAKTestPlugin
// Copies payload to custom host
var dAKTestPlugin = function(tracker) {
this.tracker = tracker;
// Copy the original hit dispatch function
var originalSendHitTask = this.tracker.get('sendHitTask');
// Modify the existing hit dispatcher to send a local copy of the hit
this.tracker.set('sendHitTask', function(model) {
var hitPayload = model.get('hitPayload');//.replace('2560x1440', '800x600');
// Updates the hitPayload string for the current hit.
hitPayload += '&cd1=myUniqueVal' //this is our marker: we add constant value for Custom Dimension with index 1
model.set('hitPayload', hitPayload, true);
originalSendHitTask(model); // Send the original hit as usual
});
};
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment