Skip to content

Instantly share code, notes, and snippets.

@zenners
Last active September 27, 2019 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zenners/ce17901fee959a270814 to your computer and use it in GitHub Desktop.
Save zenners/ce17901fee959a270814 to your computer and use it in GitHub Desktop.
first try on ga event tracking
// this is the google analytics script that we have
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', 'its the correct number', 'auto');
ga('send', 'pageview');
// start of event tracking
// for keyup events
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
$('#u9067-4').on('click', function(){
ga('send','event','Video', 'open', 'video_open')
})
// click on see a gallery in action
$('#u9374-10').on('click', function() {
ga('send', 'event', 'Gallery', 'open', 'gallery_open');
});
// typing in email box, wait 1 sec after last keyup to send event
$('#widgetu12217_input').on('keyup', debounce(function(){
ga('send','event', 'Email List', 'keyup', 'subscribe_email')
}, 1000));
// track number of times email is submitted
$('#u12235-17').on('click', function(){
ga('send', 'event', 'Email List', 'click', 'subscribe_button')
})
// track typing in trial email field, send 1 sec after last last keyup
$('#widgetu9692_input').on('keyup', debounce(function(){
ga('send', 'event', 'Trial', 'keyup', 'trial_email')
}, 1000));
//track typing in trial credit card, send 1 sec after last last keyup
$('#widgetu9683_input').on('keyup', debounce(function(){
ga('send', 'event', 'Trial', 'keyup', 'trial_cc')
}, 1000));
// track trial sign up button
$('#u9682-17').on('click', function(){
ga('send', 'event', 'Trial', 'sign_up', 'trial_sign_up')
})
// open paid subscription modal
$('#u12013').on('click', function(){
ga('send', 'event', 'Paid Subscription', 'open', 'subscriptions_button')
})
// typing in paid email field, wait for 1 sec before sending event
$('#widgetu12326_input').on('keyup', debounce(function(){
ga('send', 'event', 'Paid Subscription', 'keyup', 'paid_email')
}, 1000));
// tracking changes to plan selection
$('#widgetu12334_input').on('change', function(){
ga('send', 'event', 'Paid Subscription', 'select', 'paid_plan_selection', this.value)
})
// typing in paid cc field, wait for 1 sec before sending event
$('#widgetu12319_input').on('keyup', debounce(function(){
ga('send', 'event', 'Paid Subscription', 'keyup', 'paid_cc')
}, 1000))
// get money
$('#u12306-17').on('click', function(){
ga('send', 'event', 'Paid Subscription', 'sign_up', 'paid_sign_up')
})
@zenners
Copy link
Author

zenners commented May 13, 2015

the event handlers work on the site, for some reason its not getting sent to to GA Dashboard.

@zenners
Copy link
Author

zenners commented May 13, 2015

ga() is loaded.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment