The Customer Analytics Blog

Actionable advice on optimizing the customer lifecycle

Introducing Woopra Javascript Tracking Code (Version 4)

Woopra News - July 31st, 2013 by Billy Vong.

29 Flares Twitter 9 Facebook 17 Google+ 2 LinkedIn 1 29 Flares ×

js-tracking-v4The dev team has been working hard here at Woopra to continuously improve and deliver a great experience. We know that customization and ease of use are important to our customers so we’ve launched a brand new version of our tracking code designed to deliver both.

Do I have to update to the new code?

No, you don’t. The previous versions of the tracking code will continue to work and we’ll continue maintaining them. Though, we highly recommend that you update your code to the new version to take advantage of the new features.

What’s New?

The new version of the tracking continues to be asynchronous and allows you to start queueing your tracking events before the asynchronous script loads. You don’t have to manually create arrays of events or even handle your configuration and tracking events inside the previous woopraReady callback function.

The new tracking code allows you to create multiple instances of the tracking code as well, which allows you track your events on multiple accounts. The new tracking code looks like this:

<script>
(function(){
var t,i,e,n=window,o=document,a=arguments,s="script",r=["config","track","identify","visit","push","call"],c=function(){var t,i=this;for(i._e=[],t=0;r.length>t;t++)(function(t){i[t]=function(){return i._e.push([t].concat(Array.prototype.slice.call(arguments,0))),i}})(r[t])};for(n._w=n._w||{},t=0;a.length>t;t++)n._w[a[t]]=n[a[t]]=n[a[t]]||new c;i=o.createElement(s),i.async=1,i.src="//static.woopra.com/js/w.js",e=o.getElementsByTagName(s)[0],e.parentNode.insertBefore(i,e)
})("woopra");
 
// configure tracker:
woopra.config({
    domain: 'mybusiness.com'
});

// identify logged in customers:
woopra.identify({
    email: 'email@customerbusiness.com',
    name: 'John Doe',
    company: 'Customer Business'
});

// track a pageview event:
woopra.track();

// or even track custom events as follows:
woopra.track('purchase', {
    amount: 199.95,
    currency: 'USD'
});
</script>

Multiple Instances

To create multiple instances, add an instance name as an argument to the script loader as follows:

(function(){
var t,i,e,n=window,o=document,a=arguments,s="script",r=["config","track","identify","visit","push","call"],c=function(){var t,i=this;for(i._e=[],t=0;r.length>t;t++)(function(t){i[t]=function(){return i._e.push([t].concat(Array.prototype.slice.call(arguments,0))),i}})(r[t])};for(n._w=n._w||{},t=0;a.length>t;t++)n._w[a[t]]=n[a[t]]=n[a[t]]||new c;i=o.createElement(s),i.async=1,i.src="//static.woopra.com/js/w.js",e=o.getElementsByTagName(s)[0],e.parentNode.insertBefore(i,e)
})("woopra", "woopra2");
 
// configure both instances:
woopra.config({
    domain: 'mybusiness.com'
});

woopra2.config({
    domain: 'myotherinstance.com'
});

// track on both instances:
woopra.track();
woopra2.track();

Tracking event callbacks

If you want to know when the event is tracked successfully, you can add a callback function to your track function. Here’s an example:

woopra.track('purchase', {
    amount: 199.95,
    currency: 'USD'
}, function() {
    console.log('purchase event tracked');
});

Identifying visitors without a tracking event

In version 4 of the tracking code, you can now identify customers on the fly without sending a tracking event using the push function. Example below:

woopra.identify({
    email: 'email@customerbusiness.com',
    name: 'John Doe',
    company: 'Customer Business'
}).push();

Need help? Read the documentation or email our support team anytime at support@woopra.com

29 Flares Twitter 9 Facebook 17 Google+ 2 LinkedIn 1 29 Flares ×