Product Id tracking

Hi,
I am successfully tracking URL clicks using js tracker. Data I stored in Redshift after processing

<script type="text/javascript">
    ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
     p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
  };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
  n.src=w;g.parentNode.insertBefore(n,g)}} . 
 (window,document,"script","//xxxxx.cloudfront.net/2.9.2/sp.js","snowplow"));

 window.snowplow('newTracker', 'cf', 'xxxxxxx.cloudfront.net', { // Initialise a tracker - point to 
   cloudfront that serves S3 bucket w/ pixel
   appId: 'web',
   cookieDomain: null,
   gaCookies: true
 });
window.snowplow('enableLinkClickTracking', null, true, true);
window.snowplow('enableActivityTracking', 30, 10);
window.snowplow('trackPageView');
window.snowplow('setUserId', '12345');

In my case, click on a URL is a click on a particular product.

Question:
What is the way to track clicks of a particular product? I mean in Redshift URLs are stored but what is the way to analyze not URL but products.

Should I parse URLs and extract product id?

Is there an example or best practices.

Thanks
Oleg.

You will want to avoid parsing URLs as much as possible as this can be quite an expensive operation.

Instead it would be worth developing a self-describing event e.g., product_click that captures the properties you need.

For example

window.snowplow('trackSelfDescribingEvent', {
    schema: 'iglu:com.acme/product_click/jsonschema/1-0-0',
    data: {
        product_id: 123
    }
});

with an example schema

{
  "self": {
    "vendor": "com.acme",
    "name": "product_click",
    "format": "jsonschema",
    "version": "1-0-0"
  },
  "$schema": "http://iglucentral.com/schemas/com.snowplowanalytics.self-desc/schema/jsonschema/1-0-0#",
  "description": "This event fires each time a product is clicked",
  "type": "object",
  "properties": {
    "product_id": {
      "type": "integer",
      "description": "Unique product identifier",
      "minimum": 0,
      "maximum": 2147483647
    }
  },
  "additionalProperties": false,
  "required": [
    "product_id"
  ]
}

Ok , thanks Mike.

window.snowplow(‘trackSelfDescribingEvent’, {
schema: ‘iglu:com.acme/product_click/jsonschema/1-0-0’,
data: {
product_id: 123
}
});

in your code example, product_id is hardcoded but in a real scenario, product id is dynamic. for 2 different users, it will be shown products with different ids.

Question:
How in this case how implementation should be to handle dynamic product id?

The ultimate goal is to track impressions and clicks. I’ve found a good example https://snowplowanalytics.com/blog/2016/03/07/ad-impression-and-click-tracking-with-snowplow/
but this example also works with hardcoded attributes.

I definitely missing something but how to organize the code to work with dynamic attributes?

Thanks
Oleg.

This depends on what platform you are tracking on but typically the best practice on web for example is to use a tag manager / dataLayer where product_id is either a variable that is set by the codebase or is alternately retrieved from a dataLayer that is defined on the page.

Thanks, Mike. We are on a web platform. My assumption was that it is required to write a custom javascript code, but I can’t find any example.

In your example

  window.snowplow('trackSelfDescribingEvent', {
    schema: 'iglu:com.acme/product_click/jsonschema/1-0-0',
    data: {
        product_id: 123
    }
});

or the example from the documentation for tracking

window.adTracker('trackAdImpression:' + rnd,
    '67965967893',            // impressionId
    'cpa',                    // costModel - 'cpa', 'cpc', or 'cpm'            
    10,                       // cost - requires costModel
    'http://www.example.com', // targetUrl
    '23',                     // bannerId
    '7',                      // zoneId
    '201',                    // advertiserId
    '12'                      // campaignId
);

Question:
is there any code example how to implenent required logic for dynamic tracking impression and clicks of product attribute?

I also try to understand conceptually what kind of logic should we implement. Is it a code that parses the html page based on tag_id? ( sorry for dummy questions - it is just first time we are doing such implementation)

Thanks
Oleg.

hi, Oleg
You can use GoogleTag to invoke tracker to send snowplow requests.
If you already have GT implementation on your pages you must go to Google Tag interface. Then you add new Tag (name it snowplow for example). Choose Custom HTML and PageView options .
Basically, follow this instructions.https://github.com/snowplow/snowplow/wiki/Integrating-javascript-tags-with-Google-Tag-Manager

Hi luliia.
We are using Google tag manager and I can successfully track page view and link clicks. What I don’t know how to track is impressions and clicks for a particular product and extracting the attributes related to the product.

window.adTracker('trackAdImpression:' + rnd,
    '67965967893',            // impressionId
    'cpa',                    // costModel - 'cpa', 'cpc', or 'cpm'            
    10,                       // cost - requires costModel
    'http://www.example.com', // targetUrl
    '23',                     // bannerId
    '7',                      // zoneId
    '201',                    // advertiserId
    '12'                      // campaignId
);

in my case all the attributes will be different per user.
Question:
how to track using snowplow impressions and clicks for a particular product.

Thanks
Oleg.

Hi Oleg
you have to prepare the impression object on the site of your application and make it accessible in Google tag. So just put in some variable in global scope when rendering page.
for example, we put it in dataLayer object and call this in Google Tag.
You can simply output on your webpage

<script>
var product = ['id': productId, 'costModel' : 'cpc', ....];
</script>

and in GoogleTag

var product = product || [];
if (product ! = []) {
window.adTracker('trackAdImpression:' + rnd,
    product.id,            // impressionId
    product.costModel,                    // costModel - 'cpa', 'cpc', or 'cpm'            
    product.cost,                       // cost - requires costModel
...
);
}
1 Like

Hey, Oleg
So I just get you wrong, my bet :slight_smile: But I still don’t get the actions you want to track. so you have a shop, and people click on the links that are product links, correct? Does the link add product to the cart or refer to the page with product? you want to track that the product was shown or bought?

Also look at this, maybe it would help: https://github.com/snowplow/snowplow/wiki/Integrating-javascript-tags-with-Google-Tag-Manager#ecommerce

Hi Oleg,

You’ll need to push the values you’re interested in to the datalayer. There are a range of ways to send them to Snowplow but it sounds like the most fitting for your case will be to define a custom context and attach it to your event.

Best,

1 Like

Ok ,I slowly starts to understand the way it should be done. the impression is relatively easy. but how to track the clicks? May you give an example?

Yes lullia , you right. we want to track as detailed activity as possible, but it will be on the next steps. Meanwhile I try to track user_id , impression and clicks on the product. We have a web site and we show different products to different users on the web pages. All the examples are showing the hardcoded attributes tracking the impression and clicks. but I think it is not realistic. Suppose you have an ad space and each time there will be different advertisement with different attributes + different advertisement is showing to the different users , so I need a way to track the dynamic attributes :-).

Thanks
Oleg.

Thanks Colm ,
I try to understand the approach, pushing to datalayer is always done from the web site part, right? It is not an extensions of SnowPlow js tracker code? Am I understand correct - there will be a code which will consolidate all the impressions in json format / json array and push it to data layer - it is for impressions.
For clicks there will be the code that will listen on events and extract the information from product (product in our case is url with different attributes ) and push it to data layer too?

Guys , @mike and @Iuliia
I am sure I am missing something but implementing the logic above it looks like to write additional js tracker? right? but it is not from snowplow side ( it is from website side)

I will explore the custom context, it looks promising for my case.

Thanks
Oleg.