Expand my Community achievements bar.

SOLVED

Event based Data Elements

Avatar

Level 4

We have a legacy pattern in links that we need to parse into a Google Analytics call.

<a class="ga gainfo-[category]-[action]-[label]-[value]"/>Link</a>

There are unlimited numbers of these links.

I can envision using Data Elements to populate the tracker, but don't know how to add a global element that can be used for events like this.  

Any ideas on how to do this in DTM?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Trench,

When defining the criteria for an event based rule, within the custom code block   we can dynamically capture the value of the event, and you can set it within that code block using:        

Var  str= $(this).attr("class");// This line will fetch the class of the link clicked i.e.  ga gainfo-[category]-[action]-[label]-[value] Var res=str.split("-");   //  This line will split the string into an array on the basis of "-" Hence we will have an array of length 5 and res[1] =[category] , res[2]=[action] etc. _satellite.setVar('Categ',res[1]); _satellite.setVar('action',res[2]); _satellite.setVar('label',res[3]); _satellite.setVar('val',res[4]);You can then create a data element, and within the custom code block for the data element you can retrieve your variable using:
var  element_category= _satellite.data.customVars.categ; var  element_action= _satellite.data.customVars.action; var  element_label= _satellite.data.customVars.label; var  element_value= _satellite.data.customVars.val;

 

These data element will now be available like any other within the interface using %Element_categoryVar%

Please do let me know if you have any questions or queries.

Thanks & Regards

Parit Mittal

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Hi Trench,

When defining the criteria for an event based rule, within the custom code block   we can dynamically capture the value of the event, and you can set it within that code block using:        

Var  str= $(this).attr("class");// This line will fetch the class of the link clicked i.e.  ga gainfo-[category]-[action]-[label]-[value] Var res=str.split("-");   //  This line will split the string into an array on the basis of "-" Hence we will have an array of length 5 and res[1] =[category] , res[2]=[action] etc. _satellite.setVar('Categ',res[1]); _satellite.setVar('action',res[2]); _satellite.setVar('label',res[3]); _satellite.setVar('val',res[4]);You can then create a data element, and within the custom code block for the data element you can retrieve your variable using:
var  element_category= _satellite.data.customVars.categ; var  element_action= _satellite.data.customVars.action; var  element_label= _satellite.data.customVars.label; var  element_value= _satellite.data.customVars.val;

 

These data element will now be available like any other within the interface using %Element_categoryVar%

Please do let me know if you have any questions or queries.

Thanks & Regards

Parit Mittal