trackPageView and enableLinkClickTracking inserting custom events?

Hi, I have a basic function here
function testCustomEvent() { snowplow('trackSelfDescribingEvent', { schema: 'iglu:com.acme/customEvent/jsonschema/1-0-0', data: { customData: 'customDataValue' } } ); }

which happens to work when I attached it to a button and call directly
<button onclick="testUserId()">Test button</button>

What I want is to insert this to a trackPageView or enableLinkClickTracking as context,
let dynamicContext=function(element){return context};let contexts=[dynamicContext];snowplow('enableLinkClickTracking',null,null,contexts)

I tried adding,
snowplow('trackPageView',null,null,function(){return[{schema:"iglu:com.acme/customEvent/jsonschema/1-0-0",data:{customData:'customDataValue'}}]})

on the s3 logs JSON, it does appear but not on the database nor inserted.

but on the “testCustomEvent” alone, it does appear on the database.

anyone can help?

@Aron_Quiray, you can add context (entities) to track... methods. It could be done globally or directly as in

snowplow('trackLinkClick', targetUrl, elementId, elementClasses, elementTarget, elementContent, contexts);
snowplow('trackPageView', null, contexts)

where contexts is an array of self-describing JSON schemas

[
  { 
    schema: 'iglu:com.acme/custom_event/jsonschema/1-0-0', 
    data: { 
      customData: 'customDataValue' 
    }
  },
  . . .
] 

Note I replaced the name of your event customEvent with custom_event. It doesn’t have to be this way but sometimes might cause an issue and it’s best to stick to the latter format.

1 Like