Created
September 30, 2013 18:12
-
-
Save eskfung/6767787 to your computer and use it in GitHub Desktop.
Two examples of using the 'record' API call, within the KISSmetrics support site.
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
<!-- KISSmetrics --> | |
<script type="text/javascript"> | |
var _kmq = _kmq || []; | |
var _kmk = _kmk || 'foo'; | |
function _kms(u){ | |
setTimeout(function(){ | |
var d = document, f = d.getElementsByTagName('script')[0], | |
s = d.createElement('script'); | |
s.type = 'text/javascript'; s.async = true; s.src = u; | |
f.parentNode.insertBefore(s, f); | |
}, 1); | |
} | |
// Don't load KM locally | |
if (!window.location.host.match(/localhost/)) { | |
_kms('//i.kissmetrics.com/i.js'); | |
_kms('//doug1izaerwt3.cloudfront.net/' + _kmk + '.1.js'); | |
} | |
/* When the page loads, this script will execute, which will record this KISSmetrics event. | |
* This is an example of recording an event upon page load. | |
*/ | |
_kmq.push(['record', 'Viewed Support Article', {'Support Article Viewed URL':'/learn/recording-your-first-js-event.html','Support Article Viewed Title':'Step 2 - Recording Your First KISSmetrics Event with Our JavaScript'}]); | |
</script> |
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
/* You can combine the 'record' API call with other APIs. | |
* This example taps into Wistia's video playback API to show you can record events not just on page load, | |
* but when other JS events happen. | |
*/ | |
function loadKMTrackableVideo (id, name) { | |
wistiaEmbed = Wistia.embed(id); | |
// Begin binding KISSmetrics tracking | |
wistiaEmbed.bind("play", function() { | |
_kmq.push(['record', 'Played video - ' + name]); | |
}); | |
wistiaEmbed.bind("pause", function() { | |
_kmq.push(['record', 'Paused video - ' + name]); | |
}); | |
wistiaEmbed.bind("end", function() { | |
_kmq.push(['record', 'Finished video - ' + name]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment