Icontem

File: examples/example_async.html

Recommend this page to a friend!
  Classes of Arturs Sosins  >  Countly Web SDK  >  examples/example_async.html  >  Download  
File: examples/example_async.html
Role: Documentation
Content type: text/plain
Description: Documentation
Class: Countly Web SDK
Track site accesses and errors the Countly API
Author: By
Last change: Merge pull request #32 from frknbasaran/ga-adapter

[sdk] ga and countly queue implementation.
Date: 11 months ago
Size: 1,227 bytes
 

Contents

Class file image Download
<html>
<head>
<script type='text/javascript'>
//some default pre init
var Countly = Countly || {};
Countly.q = Countly.q || [];

//provide countly initialization parameters
Countly.app_key = "YOUR_APP_KEY";
Countly.url = "https://try.count.ly"; //your server goes here
Countly.debug = true;

//start pushing function calls to queue
//track sessions automatically
Countly.q.push(['track_sessions']);
  
//track sessions automatically
Countly.q.push(['track_pageview']);

//load countly script asynchronously
(function() {
	var cly = document.createElement('script'); cly.type = 'text/javascript'; 
	cly.async = true;
	//enter url of script here
	cly.src = '../lib/countly.js';
	cly.onload = function(){Countly.init()};
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(cly, s);
})();
</script>
</head>
<body>
<script type='text/javascript'>
//send event on button click
function clickEvent(ob){
	Countly.q.push(['add_event',{
		key:"buttonClick", 
		"segmentation": {
			"id": ob.id
		}
	}]);
}
</script>
<input type="button" id="testButton" onclick="clickEvent(this)" value="Test Button">
<p><a href='http://count.ly/'>Count.ly</a></p>
</body>
</html>