i am trying wrap my head around how to track some custom user activity. Things like button clicked or any html element clicked. i need to send in a bunch of custom data along with it. I would also like all these events to have all the info about the client as possible… like user agent etc. The way I see it, there are 2 ways to do this.
1 - call the updatePageActivity manually and attach with it the business data as custom contexts. The client/useragent info should come with when i set the webpage:true in argmap during tracker initilization.
2 - call the trackSelfDescribingEvent with the business data.
Question re: solution 1 -
How can i send custom context data with updatePageActivity event? It doesn’t seem to be on the method definition
Question re: solution 2 -
Will trackSelfDescribingEvent bring with it client/useragent info if i set it in argmap during initializtion?
Can i also send custom contexts here if i want to reuse a subset schema across events?
Hi @vish
Your best bet here is option 2. You can call trackSelfDescribingEvent and UserAgent information will be automatically sent with the request. Setting the webpage context to true will add a UUID that will allow you to track seperate page views with each event (Events sent on the same page view will all have the same Page View ID).
There are two main ways to add custom contexts with the JavaScript tracker. You can add them per event and you can add them globally. Both the per event and global custom contexts will be combined when the event is sent.
You can append them when sending the event by adding an extra function parameter containing an array of contexts:
Or if you wish to add a set of custom contexts that are tracked along with ALL events, you can add global contexts. These will be sent with every event but you can also append additional contexts using the method I described above and both sets of custom contexts will be sent. An example of setting global contexts:
To remove some: window.snowplow_name_here('removeGlobalContexts', [array of global contexts])
To remove all: window.snowplow_name_here('clearGlobalContexts')