General
API
Language libraries
External Services
Other
Track Stats with JavaScript
1. Put this code in the HEAD section of an HTML page:
<script type="text/javascript"> var _StatHat = _StatHat || []; _StatHat.push(['_setUser', 'YOUR_CLASSICKEY']); (function() { var sh = document.createElement('script'); sh.type = 'text/javascript'; sh.async = true; sh.src = '//www.stathat.com/javascripts/api.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(sh, s); })(); </script>
2. Since anyone can view the source of your javascript files, we recommend using the Classic API for client-side JavaScript. This means you have to create a stat with the web interface first.
3. After creating a stat, it will show you the keys you need on the stat details page in the Code snippet section. Say your stat key is XXXXXXXXX, post the stat with this code:
<script type="text/javascript"> _StatHat.push(['_trackValue', 'XXXXXXXXXX', 3.14159]); </script>
4. Go to the stats page to see your stats!