Last active
April 4, 2023 18:36
-
-
Save stugoo/4994538 to your computer and use it in GitHub Desktop.
Google analytics custom event tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var track = function (args) { | |
args = args || {}; | |
var category = args.category, | |
action = args.action, | |
label = args.label, | |
value = args.value || null; | |
if (_gaq) { | |
_gaq.push(['_trackEvent', category, action, label, value]); | |
} | |
}; | |
/* http://support.google.com/analytics/bin/answer.py?hl=en-GB&answer=1136920 */ | |
var trackOutboundLink = function(link, category, action) { | |
try { | |
_gaq.push(['_trackEvent', category , action]); | |
} catch(err){ | |
} | |
setTimeout(function() { | |
document.location.href = link.href; | |
}, 100); | |
}; | |
var trackReporting = function(e) { | |
var tracking = document.getElementsByName('reportReason'); | |
var i = 0, | |
length = tracking.length; | |
for (i = 0; i < length; i++) { | |
var r = tracking[i], id; | |
if (r.checked) { | |
id = r.id; | |
track({ | |
category: 'post', | |
action: 'report', | |
label: id | |
}); | |
} | |
} | |
}; | |
/*usage */ | |
track({ | |
category: 'Deed', | |
action: 'Submit', | |
label: '' | |
value: '' // Optional | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe include an option to pass-in an
object
forargs.label
and stringify it?