Events & Contexts - Beginner clarification

Hi All,

Before I explain the issue i am facing, I must say I am a relative newbie and I am still learning the ropes here.

I understand the basics of events and contexts and I am able to build pipeline to ensure I get all the predefined events for the web javascript tracker. (plus some enrichments like page performance)

However I am unable to understand how to set up the tracker to send events like Ecommerce transactions (for which there are predefined fields tr and ti).

Taking ecommerce transaction as an example: There are 3 main steps as far as I understand: 1) Create a transaction object ( addTrans) 2) Add items to the transaction ( addItem) 3) Submit the transaction to Snowplow ( trackTrans)

What i cannot understand is how would the addTrans method be called with the parameters based on actual data (total, tax, orderId etc.) Does this involve firing additional methods from the html code of the website based on events like check out success?

The example given is:

snowplow('addTrans',
    '1234',           // order ID - required
    'Acme Clothing',  // affiliation or store name
    '11.99',          // total - required
    '1.29',           // tax
    '5',              // shipping
    'San Jose',       // city
    'California',     // state or province
    'USA',            // country
    'USD'             // currency
  );

And the total and orderId fields are required.

I hope i am able to present my case (and my noob-ness in this field) clearly

Hi Kabita,

You basically have the right idea - these methods are manually called so you would instrument your own javascript to fire the addTrans and trackTrans methods at the appropriate moments on your site, filling in the data manually. So yes, for example you would fire the trackTrans method at checkout success.

In all honesty, these methods aren’t the simplest to use - they do accommodate more complicated user journeys, but this comes at the cost of leaving the door open to difficulties in instrumenting them.

Since you say you’re new to Snowplow, my gut says that actually using the in-built method in this case might not be the best option. Instead, there are two approaches that might be a simpler way forward for now:

  1. Use custom events, and/or custom contexts

Using the trackSelfDescribingEvent method, you can track a custom event. This involves creating a schema for your event first, then uploading to Iglu.

You could define a ‘checkout_success’ event, and track all of the information you need about the transaction there.

  1. Use structured events

Normally, we advise against using structured events for most cases, because they tend to make life more complicated later on (since the same data represent different things). However the advantage of the trackStructEvent method is that it’s very simple to instrument. So you do have the option of tracking transactions using this method.

For either approach, you can also track information about the items in the transaction via a custom context.

There would be nothing wrong with using the in-built methods either, by the way - I just thought I’d mention these alternatives as options. :slight_smile: