Last active
August 29, 2015 14:24
-
-
Save JohnMorales/7242505d0e360a77695f to your computer and use it in GitHub Desktop.
This file contains 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
//https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers | |
ga('create', 'UA-54906935-2', 'auto', {'name': 'lifefuelsTracker'}); | |
ga('require', 'ec'); | |
ga('ec:setAction', 'purchase', { | |
'id': 'SET_TRANS_ID_HERE', // (Required) Transaction id (string). | |
'revenue': 'SET_TOTAL_HERE', // Revenue (currency). | |
'coupon': 'SET_COUPON_HERE' // Transaction coupon (string). | |
}); | |
ga('lifefuelsTracker.send', 'event', 'preorders', 'completed purchase'); |
This file contains 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
// Adding new tracker to send lifefuels specific events. | |
//https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced#multipletrackers | |
ga('create', 'UA-54906935-2', 'auto', {'name': 'lifefuelsTracker'}); | |
$('.tilt_modal input, .tilt_modal select') | |
.on('blur', function(e) { | |
'use strict'; | |
var obj = e.currentTarget; | |
var value = obj.value; | |
if (obj.name.match(/^(card_number|security_code)$/) && value) { | |
value = '(omitted)'; | |
} | |
ga('lifefuelsTracker.send', 'event', 'preorders', 'form-input', obj.name + ': ' + value); | |
}); | |
$('.tilt_modal button') | |
.click(function(e) { | |
'use strict'; | |
var obj = e.currentTarget; | |
// run in next tick so that the form can be validated, 0 moves this function to the end of the execution loop. | |
setTimeout(function() { | |
var invalidFields = $('input.error, select.error', obj.form).map(function(idx, elem) { return elem.name; }).get(); | |
if (invalidFields.length > 0) { | |
ga('lifefuelsTracker.send', 'event', 'preorders', 'form-invalid', invalidFields.join(', ')); | |
} | |
else { | |
ga('lifefuelsTracker.send', 'event', 'preorders', 'preorder-submit'); | |
} | |
}, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment