Client-side Tracking

Thomas Garp -

 

The Raptor tracking script contains two main parts:

  1. Head script in the <head></head> section of your website
  2. Main script after the head script, and after cookie consent

Once these are implemented the following parameters must be set up:

  1. Track Visit Events
  2. Track Basket Events
  3. Track Buy Events
  4. Track Itemclicks

The Head Tracking Script

Place the following script in the <head></head> section of your website. 

<script type="text/javascript">

window.raptor||(window.raptor={q:[{event:"trackevent",params:{p1:"pageview"}}],push:function(event,params,options){this.q.push({event:event,params:params,options:options})},customerId:"XXXX"});

</script>

*customerId:”XXXX” = Please locate your specific account id in the Raptor Control Panel and insert it here.

 

The Main Tracking Script

<script type="text/javascript">

(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src="//az19942.vo.msecnd.net/script/raptor-3.0.min.js",g.async="true",s.parentNode.insertBefore(g,s)}(document,"script"));

</script>


The second part of the script, being the main script, can be loaded anywhere on the page after the head script and after cookie consent.

Track Product Visit Events

Visit events are used on the product pages when a product has been viewed.

raptor.push(“trackevent”,{p1:”visit”, p2:”{productid}”,p4:”{categorypath}”});


//Example:

//raptor.push(“trackevent”,{p1:”visit”,p2:”1234”,p3:”Nike Air”,p4:”22#men;33#shoes;44;sport;” ]]);

 

A visit event must contain the following information:

Parameter       Name Description
p2 ProductId The unique id of the viewed product;
p3 ProductName  The product name;
p4 CategoryPath

A semicolon separated list of category id's and names, corresponding to the breadcrumb path of the product. The data format should be: "CategoryId1#  CategoryName1;CategoryId2 #CategoryName2"  (i.e: "25#Herre;11#Efterår;10#Fodtøj;23#Støvler”). If one of the parameters within this breadcrumb path is not available, for example, if the CategoryName is missing, then simply repeat the CategoryId (i.e. “25#25;11#11;10#10”). The same can be done if only the CategoryName is available.

Note: CategoryName cannot contain the following characters: , (comma), ; (semicolon) or ¤ (general currency)

 

Track Basket Events

The basket event is used to track when the content of the basket is updated. That is when an item is added to the basket, removed from the basket or the basket is cleared.

raptor.push("trackEvent", { p1:"basket", p10:"{BasketContent}",p11:"{BasketId}" });

//Example:

//raptor.push("trackEvent", { p1:"basket",p10:"1234,231,334,332,545",p11:"basket-1234"]]);


When a basket event is fired it must contain the following information:

Parameter Name Description
P10 BasketContent A comma separated list of all product id’s in the basket,      fired at every basket event. Only needed for Abandoned  Basket implementations.
P11 BasketId BasketId is used to restore the basket content. Only needed for Abandoned Basket Implementations.


Track Buy Events

The buy event is placed on the final page in the payment process, where the items have been sold. It is important that a buy event is fired for each item bought. Multiple items must have multiple calls to the trackEvent method.

raptor.push("trackEvent", {p1:"buy", p2:"{ProductId}",p3:"{ProductName}",p5:"{Subtotal}",p6:"{Currency}",p13:"{Quantity}"});

/*

 Example:


   raptor.push("trackEvent", {p1:"buy",p2:"1234",p3:"Nike Air",p5:"Subtotal",p6:"Currency",p13:"Quantity"});

 
   Fire one buy event for each item in the basket:


   productsBought.forEach(function(product){


raptor.push("trackEvent", {"buy",--product tracking parameters --});


   }

*/

 

A buy event must contain the following information in the tracking script:

Parameter Name Description
P2 ProductId The unique id of the viewed product.
P3 ProductName The product name.
p5 Subtotal Subtotal is defined as Number of Items sold * Unit Price of the item. The format should be ##.## (i.e 19.50), without currency labels. This information should only be tracked at buy-events.
P6 Currency Currency of the Price (i.e. DKK).
P13 Quantity Number of an item in a order. If there is multiple items of the same product in an order. Should be  used only on Buy events. Is optional.Number of an item in a order. If there is multiple items of the same product in an order. Should be  used only on Buy events. Is optional.

 

Track Itemclick Events

The event should be fired when a user clicks a recommendation. This can be implemented with the Raptor Click Handler tags. 

 

raptor.push("trackEvent", {p1:"itemclick", p2:"{ProductId}"},{moduleName:'clickedModuleNameHere', onComplete:function(){}, redirectUrl:'productUrlHere'});


/* Example

   Here you can take advantage of the onComplete callback that is fired when the tracking is complete, to do the redirect manually


      raptor.push("trackEvent", {p1:"itemclick", p2:"{ProductId}"}, {moduleName: 'GetSimilarItems', onComplete: function(){ //do redirect logic here}]);

or you can just use the redirectUrl and then the redirect will happen when the tracking is completed

     raptor.push("trackEvent", {p1:"itemclick", p2:"1234"}, {moduleName:'GetSimilarItems', redirectUrl:'productUrlHere'}]);

*/

 

Parameter Name Description
P2 ProductId         The unique id of the viewed product.

 

This section addressed how to implement the head and main script as well as the most basic tracking events like visit, basket, buy and item clicks.

If you want any additional parameters tracked be sure to ask our professional service team for advice on a customized setup. If you have any further questions, please contact us at support@raptorsmartadvisor.com. We will be happy to help you in any way we can.

 

Best Practices:

Send us the master product id in the trackings. Then you will get recommendations on the main product, not the variants 

If you have integrated a product feed with our engine, check that the product id matches the product id in the product feed, otherwise the recommendation modules will not be able to find the products in the product catalog.

FAQ

Do I need to send all product information for all events?

The short answer is "No". 

  • For visit events, all we basically need is a productId, and a category path
  • For basket events, we need a list of product id's in the basket.
  • For buy events, we need a product id, the total price of the product (i.e: the product price x quantity), and the currency.

What if the user buys more than one item?

If the user buys multiple items of the same product, just put the total price in the buy event (i.e: the product price x quantity)

If the user buys multiple different items, put a Raptor Buy Event for every item in the basket

 

How can I check that the tracking script works?

When you have finished setting up the tracking script on the web pages, then you can immediately see the trackings generated on the website by clicking into our controlpanel.

Locate the Live Tracking Stream under Recommendations and Integrations and you will find a realtime updated view of the tracking flow in the Raptor Engine.

MicrosoftTeams-image-blur.jpg

 

Which cookies does the Raptor Script set on the client?

The Raptor scripts set the following cookies for different purposes. The main purpose is to add personalization to the raptor module. NOTE: As of the beginning of 2022 it is necessary to set the rsa cookie server side to avoid the cookie being removed in Safari: https://support.raptorsmartadvisor.com/hc/en-us/articles/4414661647890  

rsa Cookie for tracking user behavior

Set on the customer domain

1 year
rsaSession Cookie for tracking user behavior Set on the customer domain 30 minutes
rsa Cookie for tracking user behavior Set on *.raptorsmartadvisor.com domain 1 year
rsaRuid Cookie for tracking user behavior Set on the customer domain 1 year

 

 

Add User ID

A user is typically recognized by their id when they log-in, signs up for a newsletter or buys a product.
When you have recognized a user on your website by their id (email), send it to Raptor by this method:

 

  raptor.push("setRuid","USER_ID_HERE")

       

NOTE: It is necessary to set the rsa cookie server-side to avoid the cookie expiry being set to 7 days in Safari on Mac and iOS (due to Intelligent Tracking Prevention by Apple). See how to make a workaround here  

 

Have more questions? Submit a request

Comments

Powered by Zendesk