Expand my Community achievements bar.

Help shape the future of AI assistance by participating in this quick card sorting activity. Your input will help create a more effective system that better serves your needs and those of your colleagues.
SOLVED

DTM: Any possibility to access the target of an Event based rule from within a Custom data element?

Avatar

Level 1

Hi

I am trying to assign some of the Event rule based target's attributes to some props. To do this, I would like to assign Data elements to the props in the interface, not insert Custom Code for each Event.

The idea would be to define Custom Code Data elements which return the desired attributes of the target element, but I don't know how to access the target from within the Data elements code.

Is this possible?

Many thanks

Marco

1 Accepted Solution

Avatar

Correct answer by
Level 3

I'm reading the original question again and I think I misunderstood what was being asked.  So, first, if you are trying to reference the element being targeted by the event based rule, the 'this' object will refer to that element.  You can then get what you need in a variety of ways.  If you want any of the attributes that are already Javascript properties, such as 'href', you can simply reference 'this.href' to get that value.  To put that value in an event, you could put %this.href% and it will replace it with the actual 'href' value. You don't need to even create data elements in this case.

If you need access to a custom attribute that doesn't have a Javascript property already, you could do this: %this.getAttribute(attribute_name)%

Simply replace attribute_name in the example above with the actual name of the attribute you want (and do not wrap it in quotes like you might expect) and this will give you what you need.

Best,
Shawn

View solution in original post

3 Replies

Avatar

Level 3

Marco,

Because of the way the different pieces of code are scoped in the engine, the exact scenario you describe isn't possible. However, you could do something like this:

1) Create the data element(s) you want. Instead of referencing the target object directly, reference a copy of it (let's use "myTarget" in this example).  We'll want to scope myTarget at the global level so it can be accessed anywhere.  So, your data element might return something like "window.myTarget.href" if you wanted to return the URL of whatever link triggered a particular event based rule.

2) In your rules where you want to use these data elements, add a Custom criteria that contains the following:

var myTarget = this.target; return true;

This will make the "myTarget" object available globally, which means your data element(s) will be able to see it.

3) Use the data element normally within the rule UI using the %DataElementName% syntax.

So it does require a few more steps, but this would accomplish what you want. Hope this helps!

Best,
Shawn

Avatar

Level 2

Hi Shawn,

That's just the message which I'm searching and sounds so good that you've explained, but unfortunatly (for me), tried to do it with a non good results, let me to explain. 

So, as far as I know, right now Appmesurment haven't any method for deduplicate hits when having enable an automatic tracking links (Adobe Analytics UI on DTM) and also a one rule created for same purpose ( I'm referring solution like http://microsite.omniture.com/t2/help/en_US/sc/implement/link_functions.html), I've decided to use only the second one, meaning, on rule for detect a download links. That's seemed good for me, but the problem is when I need to assign a friendly name to my download link, seems DTM compels me use your UI, and for put into it a parameter that depending of the link ( like last slash parameter or whatever) I need use a Data Element, and is just for do that what I need apply your trick.

I tried to replicate exactly that you explained, but obviously something am doing wrong, attached you see screen of my rule and Data Element (And custom code into rule for filter different kind of dowloads). I'll very grateful if you can help me.

[img]Screen Shot 2014-08-13 at 09.47.49.png[/img]

 

[img]Screen Shot 2014-08-13 at 09.48.44.png[/img]

 

[img]Screen Shot 2014-08-13 at 09.51.00.png[/img]

 

Many thanks,

 

Juli.

Avatar

Correct answer by
Level 3

I'm reading the original question again and I think I misunderstood what was being asked.  So, first, if you are trying to reference the element being targeted by the event based rule, the 'this' object will refer to that element.  You can then get what you need in a variety of ways.  If you want any of the attributes that are already Javascript properties, such as 'href', you can simply reference 'this.href' to get that value.  To put that value in an event, you could put %this.href% and it will replace it with the actual 'href' value. You don't need to even create data elements in this case.

If you need access to a custom attribute that doesn't have a Javascript property already, you could do this: %this.getAttribute(attribute_name)%

Simply replace attribute_name in the example above with the actual name of the attribute you want (and do not wrap it in quotes like you might expect) and this will give you what you need.

Best,
Shawn