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.
The Raptor tracking script contains two main parts:
- Head script to be inserted in the <head></head> section of your website
- Main script goes after the head script and cookie consent
Once these are implemented, the following parameters must also be set up:
- Track Visit Events
- Track Basket Events
- Track Buy Events
- Track Itemclicks
Optionally, you can transmit UserIDs to Raptor as well:
7. Track UserIDs
1: 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.
2: 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.
3: Track Product Visit Events
Visit events track 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 IDs 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) |
4: 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 IDs in the basket, fired with 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. |
5: Track Buy Events
The buy event is placed on the final page in the payment process, after 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. Optional - should be used only on Buy Events. |
6: 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, 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. |
7: 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")
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 productId's in the basket.
- For buy events, we need a productId, 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, you can immediately see the trackings generated on the website by clicking into the Raptor Control Panel.
Locate the Live Tracking Stream under Integrations, and you will find a realtime, constantly-updated view of the tracking flow received by the Raptor Engine.
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.
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 |
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
Comments
0 comments
Please sign in to leave a comment.