Documentation

analytics.js

Quick start

This tutorial will help you to start sending data from your website to poder.IO and any of our integrations, using our Analytics.js library.

Step 1: Copy the Snippet

Installing poder.IO is easy, just paste this code snippet between the <head> and </head> tags of your web page:

<script type="text/javascript">
!function(P,o,d,e,r,I,O){function f(q, n){q[n]=function(){return q.push([n].concat([].slice.call(arguments))),q}}
if(P.analytics)P.console&&console.error&&console.error("poder.IO pixel included twice.");else{for(r=P.analytics=[],
I=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready",
"alias","debug","page","once","off","on"];I.length>0;)f(r,I.shift());I=o.createElement(d);I.async=!0;I.src=
'//cat.poder.io/analytics.js/v1/'+e+'/analytics.min.js';O=o.getElementsByTagName(d)[0];O.parentNode.insertBefore(I, O)}
}(window,document,'script','YOUR_WRITE_KEY');
analytics.page();
</script>

NOTE: You may already have other existing code between the <head> tags, so just place the pixel code underneath that, but above </head>.

When you paste it, you’ll need to replace YOUR_WRITE_KEY with your poder.IO project’s Write Key, which is provided by our customer success team.

That’s it! The basic setup is finished and you are tracking page views now.

NOTE: The snippet loads analytics.js asynchronously but already provides you an access to analytics.js API. So it won’t affect your page load speed and allows you to call analytics.js API methods while analytics.js is still being loaded.

Step 2: Identify Users

By default we automatically assign an anonymousId to all visitors. This is how we know that for example page and track events came from the same visitor.

To tell poder.IO more about your know users, call User ID and any optional traits to identify method.

An example how you would sent data about the user who is recognised in you system by ID 'f02321dka' and whose name and email you already know:

analytics.identify('f02321dka', {
name: 'Max Fresh',
email: 'mxfresh@example.com'
});

To provide actual user data to identify API call you may use two strategies:

Step 3: Track Actions

To tell poder.IO more about actions what performed by your users on your site call the track method. The track method tells us a name of “event” and also may include properties associated with that event.

For example this snippet is telling us that your user triggered Search event and the user is looking for 'Wristwatch':

analytics.track('Searched', {
query: 'Wristwatch'
});

You may track any user actions and send events which indicates metrics valuable for you business, like Signed Up, Item Searched or Added To Cart.

Keep on reading to know more about analytics.js API.

Analytics.js API

Read more about methods provided by analytics.js.

Anonymous ID

analytics.js takes care to track all visitors of your site. For visitors who are not identified in you system yet analytics.js will automatically generate an anononymousId and will pass it along with all events triggered by the user event after user is identifyed.

Identify

The identify method is how you tell poder.IO that a user is recognized in your system by userId and traits.

Definition:

analytics.identify([userId], [traits], [options]);

Arguments:

userId optionalStringThe ID of the user in you system.
traits optionalObjectAn object with data known about the user, like their age or name.
options optionalObjectAn options object for analytics.js tuning. Note: If you do not have traits for the user, pass an empty object (ie, ‘{}’) before options.

Track

The track method lets you record what actions performed by a users on your site.

Definition:

analytics.track(event, [properties], [options]);

Arguments:

eventStringThe name of the event you’re tracking.
properties optionalObjectAn object with data associated with the event. If the event was 'Purchased', it might have properties like item, category and price.
options optionalObjectAn options object for analytics.js tuning. Note: If you do not have traits for the user, pass an empty object (ie, ‘{}’) before options.

The only required argument to track in analytics.js is an event name string.

Example track call:

analytics.track('Added Extras', {
item: 'Breakfast + Вinner',
price: '20.0',
});

Page

The page method lets you record page views and optional extra information about the page being viewed on your website.

By default a page call is present at the end of the analytics.js snippet. You may modify this page call options described below.

Definition:

analytics.page([category], [name], [properties], [options]);

Arguments:

category optionalStringThe category of the page. Useful for cases like ecommerce where many pages might live under a single category. Note: if you pass only one string to page it is assumed to be name. You must include a name to send a category.
name optionalStringThe name of the page.
properties optionalObjectAn object with properties describing the page.
options optionalObjectAn options object for analytics.js tuning. Note: If you do not have traits for the user, pass an empty object (ie, ‘{}’) before options.

With each page event analytics.js will include url, title, referrer and path properties by default. For example:

analytics.page('Special offers');

would be equal to the following but don’t require any extra work from you:

analytics.page('Special offers', {
title: 'Offer of the week',
url: 'https://example.com/offers',
path: '/offers',
referrer: 'https://example.com/catalog'
});

You can override default value if you pass property with same key.

Reset / Logout

Calling reset will reset the anonymousId and userId (for the identified user). New events will be recorded for the new anonymous user.

analytics.reset();