Expand my Community achievements bar.

SOLVED

DTM Property or Variable Watcher

Avatar

Level 2

I want to track a variable which is populated by the IT team on a page. How do I keep a watch of that variable availability using DTM? which function need to be used?

1 Accepted Solution

Avatar

Correct answer by
Level 9

First, create a Data Element of  Type `JS Object`.  For Path, specify the JS variable you want to "watch" for.  Note that it must be a variable within the global (`window`) scope.

Next, Create an Event Based Rule. In the Conditions > Event section, select Event Type `dataelementchanged`, and select your Data Element from the dropdown.

At this point, the rule will now trigger whenever the value of your JS variable changes.  If you want it to only trigger on certain values, then under Rule Conditions > Criteria, Select `Data : Data Element Value`, and click Add Criteria.  Then select your data element from the Data Element dropdown, and specify your expected value in the Value field.

General note:  `dataelementchanged` works by using `window.setTimeout` to poll the data element every ~100ms to compare the current value with the previous value. So there is site performance to consider with this type of event, especially if you plan on using it for many rules.

View solution in original post

4 Replies

Avatar

Level 10

How/when is the variable populated? Is there a forum submission, page load, custom event, or other trigger that indicates the variable has been populated? Also, is this a simple javascript variable?

Avatar

Correct answer by
Level 9

First, create a Data Element of  Type `JS Object`.  For Path, specify the JS variable you want to "watch" for.  Note that it must be a variable within the global (`window`) scope.

Next, Create an Event Based Rule. In the Conditions > Event section, select Event Type `dataelementchanged`, and select your Data Element from the dropdown.

At this point, the rule will now trigger whenever the value of your JS variable changes.  If you want it to only trigger on certain values, then under Rule Conditions > Criteria, Select `Data : Data Element Value`, and click Add Criteria.  Then select your data element from the Data Element dropdown, and specify your expected value in the Value field.

General note:  `dataelementchanged` works by using `window.setTimeout` to poll the data element every ~100ms to compare the current value with the previous value. So there is site performance to consider with this type of event, especially if you plan on using it for many rules.

Avatar

Level 10

A Chouhan

Did the above replies answer your question? If so, can you mark the answer correct?

Thanks,

Jantzen

Avatar

Level 9

followup: not sure when (or more importantly, why..@adobe - change it back! or better, add a field in the EBR to specify! ) but FYI  `dataelementchanged` now polls every 1000ms (1 second).