Highlighted

DTM Dynamic Data Elements

Avatar

Avatar

justin_arak

Avatar

justin_arak

justin_arak

15-10-2015

I know that when you're defining a tag in DTM you can do something like set an event value to %this.@text% to get the inner text of an element.

I am trying to dynamically create a data element called for example linkText that will clean up the text of a link by removing the spaces and making it all lowercase.  This way i can reuse my data element for links in all different scenarios.  The % notation does not work in the custom script for a data element.  Am i heading down the wrong path with this? 

Any guidance would be greatly appreciated, and i'd be happy to provide some more information if that isn't straightforward.

Thanks!

Replies

Highlighted

Avatar

Avatar

Ben_Bytheway

Employee

Avatar

Ben_Bytheway

Employee

Ben_Bytheway
Employee

15-10-2015

Hi Justin,

If I understand correctly, it seems like you are trying to create a custom script data element to use in an event-based rule.  Is that right?

If that is the case, you can think of the code that you put into the editor as the body of a function.  i.e. 

function () { //start code editor in DTM // this is where all of your custom script code gets place return 'data element value you want to return'; //end code editor }

So, in this case, you can just use plain javascript to define this data element.  However, as you have seen, any % will not be replaced inside this function.  The other thing to note is that as far as I can tell, there is no event or element that is passed to this function when getting the data element, therefore, you cannot refer to the currentElement for the event dynamically with only one data element.  You must either create a new data element for each link you want to track, or when you go to track something in the interface, instead of using %dataElementName%, you can use %event.target% or %event.currentTarget% or you could use %target.getAttribute(id)% or (i think) %target.innerText%.   

Thanks,

Ben

Highlighted

Avatar

Avatar

justin_arak

Avatar

justin_arak

justin_arak

15-10-2015

Thanks for the speedy reply Ben, you are correct in the assumptions on what i am trying to accomplish.

I was also trying to figure out a way around lack of an event passed to the function but obviously unsuccessfully.  I do know of the alternative you suggested (FYI innerText will not work and should be %this.@text%) however i was trying to take that text and then transform it so that i could take the text of a link that says "About Us" and set the linkname as "aboutus"  looks like we will have to stick with the given terms in this case.

Being able to pass the event to the data element function would likely be especially helpful in cases where there is no class or id attached to an element i'm trying to track.

Highlighted

Avatar

Avatar

Ben_Bytheway

Employee

Avatar

Ben_Bytheway

Employee

Ben_Bytheway
Employee

15-10-2015

Justin Arak wrote...

Being able to pass the event to the data element function would likely be especially helpful in cases where there is no class or id attached to an element i'm trying to track.

 

I agree with this and would love to see this too!

Highlighted

Avatar

Avatar

justin_arak

Avatar

justin_arak

justin_arak

15-10-2015

FYI I figured out a solution to my problem.  When defining the criteria for an event based rule, within the custom code block you are able to dynamically capture the value of the event, and you can set it within that code block using: 

_satellite.setVar('Name',Value);

You can then create a data element, and within the custom code block for the data element you can retrieve your variable using:

var foo = _satellite.data.customVars.Name;

This data element will now be available like any other within the interface using %FooVar%

Hope this is helpful to anyone trying to accomplish something similar!