Close

JavaScript SDK

Omniata loads the library onto the page asynchronously, this keeps your page loading smoothly.

Contents:

Installation and Upgrade

The latest available SDK can be found below:

Platform Links Version Release Date
JavaScript Source code
API details
1.0.0 9 Mar 2016

Place the following code snippet inside the <HEAD> tag of your website you wish to add tracking to:

<script>
(function(document,a){window.omniata=a;var js,fjs;js=document.createElement("script");
js.type="text/javascript";js.async=!0;js.src="https://s3.amazonaws.com/js-sdk.omniata.com/omniata-1.0.0.js";
fjs=document.getElementsByTagName("script")[0];fjs.parentNode.insertBefore(js,fjs);a._q=[];
a.init=function(options){function def(obj,fn_name){var fn_name_parts=fn_name.split(".");
2==fn_name_parts.length&&(obj=obj[fn_name_parts[0]],fn_name=fn_name_parts[1]);
obj[fn_name]=function(){obj._q.push([fn_name].concat(Array.prototype.slice.call(arguments,0)))}}fn_names=["init","track","trackPage"];
for(i=0;i<fn_names.length;i++)def(a,fn_names[i]);a.init(options)};a.SNIPPET_VERSION=1})(document,window.omniata||[]); </script>

Note that the version and name of the js file might be different in your case.

Integrating the JavaScript SDK

Initialization

Initialize the library by calling the init function with the identifier of the user and the API key provided on your project’s summary page.

<script>
    omniata.init({api_key:"YOUR_API_KEY",uid:"7"}); 
    omniata.track('om_load'); 
</script>

Tracking Events

You can use the template below to construct events. In all omniata.track method calls the UID and API key specified in init will be added and sent automatically.

<script>
    omniata.track('viewed_house', { cost: 1186504, type: 'condo', bed: 2, bath: 2, sqft: 1337, location: 'Hollywood', zip: 90028 });
</script>

Callbacks

Callbacks are useful if you want to trigger an action after an event has been tracked. For example, perhaps you want to track an event so a user will be placed in a segment and then run an ad targeted to that segment.

The code below illustrates an usage example:

<script>
    // uid and api key from init will be sent automatically.
    omniata.track('viewed_house', { cost: 1186504, type: 'condo', bed: 2, bath: 2, sqft: 1337, location: 'Hollywood', zip: 90028 }, function(){ alert('event sent'); });    
    omniata.track('foo', function(){ alert('foo event sent'); });
    omniata.track({ om_event_type: 'foo', bar: 'baz' }, function(){ alert('foo event sent'); });
</script>

This article was last updated on April 21, 2017 15:54. If you didn't find your answer here, search for another article or contact our support to get in touch.