The received script will look something like this (the site parameter will differ per site):
<!-- OPENTRACKER HTML START --> <script src="//script.opentracker.net/?site=mysite.com&onload=false"></script> <!-- OPENTRACKER HTML END -->
Frequently you want the script to collect default data (for instance screen colors, browser, etc.) but wait before sending the data to the logging servers. The following script shows how to turn off the default behavior, setup the data for sending, manipulate the data, and then send it. This will enable you to add extra data and trigger the sending of the data at a later stage. The script will define a variable (_otmap) with all data already filled. The following example illustrates a use case for segments:
<!-- OPENTRACKER HTML START --> <script src="//script.opentracker.net/?site=mysite.com&onload=map"></script> <!-- OPENTRACKER HTML END --> <script> _otmap.put("salesChannel!", "West coast ads"); // define a variable called salesChannel, which is a segment (!) OTLogService.sendEvent(_otmap); // send the map </script>
notice the ! after the property-name, this needs to be added to make a property a segment. The OTLogService.sendEvent() method is called to send events. This can have several forms:
<!-- OPENTRACKER HTML START --> <script src="//script.opentracker.net/?site=mysite.com"></script> <!-- OPENTRACKER HTML END --> <script> _otmap.put("salesChannel!", "West coast ads"); // define a segment (!) called salesChannel OTLogService.sendEvent(_otmap); // send the preloaded (_otmap) OTLogService.sendEvent("Just a simple event"); // send a title event OTLogService.sendEvent("Just a simple event", _otmap); // send a title and a map OTLogService.sendEvent("Just a simple event", _otmap, false); // send a title and a map, don't update the session state </script>
The above script actually sends five events. Once when the page loads, and four coded events. Sending events will be discussed further underneath.
This will add an event to user's session with a clickstream title,
your event title
You can add this anywhere you like. In this example, a button is pressed on a form:
<input type="button" id="myButton" value="myButton label" onclick='OTLogService.sendEvent("myButton was clicked")' />
If you decide to give no title for a event, the following can be done:
OTLogService.sendEvent("", map, false);
OTLogService.sendEvent(undefined, map, false);
both give a line in the event stream with title: NO TITLE
map.put insert event into an object (map) as a property name/ value pair.
map.get read a previous value set with
map.clear used to clear a map's data
map.remove use to remove specific property from a map
OTLogService.sendEvent("your event title", map); : This function will send (submit) the data to our log servers.
var map = new OTMap(); map.put("name", "Brad Shaw"); map.put("email", "firstname.lastname@example.org"); OTLogService.sendEvent("User signup", map);
There are pre-defined properties that trigger certain behavior in a) the way an event is processed and b) displayed in the reporting interface. For example, the property called "email" will add the value of that property to clickstream user-profiles and appear in the Top Emails report, which is a list of all known email addresses on your site or app.
For some events you may want to turn off this default functionality, which is accomplished by adding a false value to the OTLogService.sendEvent() function:
OTLogService.sendEvent("title", map, false);
otuiplease review reserved properties
Opentracker's events engine includes counting functionality with segmentation within the API calls.
var map = new OTMap(); map.put("item", "Panasonic Lumix DMC-TZ30"); map.put("brand!", "Panasonic"); map.put("price", "257"); map.put("item-type", "camera[+257]"); OTLogService.sendEvent("Checkout complete", map);
Notice the domain and script name have changed and the server parameter has been added (for sites added prior to January 2013). Static scripts need to be updated when a new version of the script is introduced. Static scripts need to be loaded only once by the browser, and are geographically located close to the user.