Sitecatalyst - event tracking and data source

Gold Contributor
Gold Contributor
in data source we can create a matching between the variable pageEvents and a set of events. I suppose it is something like "if pageEvents=XXX then u.addEvent(YYY)". How can I do if I need to have "contains" instead of "equals" in that condition? I'd like to populate the pageEvents with multiple events, for instance "page-view,prod-out-of-stock,...." so I can combine different events
8 REPLIES 8

Sitecatalyst - event tracking and data source

Tealium Employee

Hi Jarno,

 

If you are checking one event, then you can use the indexOf syntax. Something like so:

 

if(b['pageEvents'].indexOf('XXX') > -1) { u.addEvent('YYY'); }

 

If you want to check multiple events at a time, you'll probably want to do a loop and go through all the different events. Maybe something like so:

 

var pageEvents = "eventA,eventB".split(","); for(key in pageEvents){ if(pageEvents[key] == "eventA") u.addEvent("XXX"); else if (pageEvents[key] == "eventB") u.addEvent("YYY");

}

 

I personally like to use the object syntax though it is more complicated:

 

var events = {

eventA: "XXX",

eventB: "YYY" };

var pageEvents = "eventA,eventB".split(",");

for(key in pageEvents){

if(events[key]) u.addEvent(events[key]);

}

Sitecatalyst - event tracking and data source

Employee Emeritus

Hi Jarno,

 

In order to do what you describe, the approach I would take is to create a separate extension for each event. So the process would be:

1. Create set data value extension, scope it to your SiteCat tag

2. Set the 'condition' to your contains condition. For example, variable 'pageEvents' CONTAINS 'prod-out-of-stock'

3. Create a var named sc_events and set the value to JS code

4. Set the JS code value to: u.addEvent(["event1","event2","scView"]); or any other events you'd like to fire on this condition.

5. Repeat 1-4 for any other 'condition' you'd like to fire other events on.

 

If you can't get this to work please contact your Account Manager so we can help you through this.

Sitecatalyst - event tracking and data source

Tealium Employee
I would also recommend this for ease of use unless you have a large amount of events (like 20+) that need to be checked.

Sitecatalyst - event tracking and data source

Employee Emeritus
I agree with Son's approach. It is much easier to read and understand for other people working in the profile. It is also much easier to maintain in the long run. You can also add multiple calls to u.addEvent within the same Set Data Values Extension. If multiple events should fire for the same condition, then those events can be configured within the same Extension.

Sitecatalyst - event tracking and data source

Gold Contributor
Gold Contributor
thank you all, great suggestions! Actually I'm struggling on this issue: custom code or pre-built extension? I see the huge benefit of pre-built exts, because every variable name is dinamically managed, but I'm concerned on creating +100 exts.... but it's probably the best way in a long term

Sitecatalyst - event tracking and data source

Tealium Employee
This is why I like the object approach in a javascript when there is a massive amount of events. It's easier to setup and it will run much faster since it's a hash lookup instead of a full loop. When you do 100+ extensions, every single one is going to run regardless. It will be more readable, but from a performance standpoint, doing an object (hash) lookup will be fastest.

Sitecatalyst - event tracking and data source

Gold Contributor
Gold Contributor

I realized now that u.addEvent should be used only as scoped with a specific tag, and it makes sense because the name of events are only related to specific tag.

 

I'd like to create something at very top level, available for all tags.

 

Probably I need an array:

Events['Order']=['enabled'=1, 'fired'=0, 'sitecatalyst'='purchase', 'googleanalytics'='customX']

 

then I use an extension (tag scoped) to fire u.addEvent within a loop as you suggested.

 

am I in a right way?

Sitecatalyst - event tracking and data source

Tealium Employee
Yup! Since this is very custom tracking, you would have something similar to above to house your different event needs, then loop through what is being set on your page and match things up. The last step will be to fire the actual events as needed either with u.addEvent for SiteCatalyst, mappings for Google Analytics, and usually mappings for other tags as needed.
Public