Tracking custom activity on page

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?

What argmap context name should be set to true to send along the ua_parser_context data I do not see one here https://github.com/snowplow/snowplow/wiki/1-General-parameters-for-the-Javascript-tracker#predefined-contexts

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.

  1. You can append them when sending the event by adding an extra function parameter containing an array of contexts:
window.snowplow_name_here('trackSelfDescribingEvent', {
    schema: 'iglu:com.acme_company/button_clicked/jsonschema/2-0-0',
    data: {
        buttonName: 'myButton',
    }
},
[{
    schema: "iglu:com.example_company/page_info/jsonschema/1-2-1",
    data: {
        pageType: 'test',
        lastUpdated: new Date(2020,1,1)
    }
},
{
    schema: "iglu:com.example_company/user/jsonschema/2-0-0",
    data: {
      userType: 'tester'
    }
}]);

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:

window.snowplow_name_here('addGlobalContexts', [{
    schema: "iglu:com.example_company/user/jsonschema/2-0-0",
    data: {
      userType: 'tester'
    }
}])

To remove some: window.snowplow_name_here('removeGlobalContexts', [array of global contexts])
To remove all: window.snowplow_name_here('clearGlobalContexts')

1 Like