DTM Property or Variable Watcher | Community
Skip to main content
New Participant
October 17, 2017
Solved

DTM Property or Variable Watcher

  • October 17, 2017
  • 4 replies
  • 1760 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by jdonley

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.

4 replies

New Participant
November 18, 2017

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). 

jantzen_b
Employee
November 17, 2017

A Chouhan

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

Thanks,

Jantzen

jdonleyAccepted solution
New Participant
October 19, 2017

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.

jantzen_b
Employee
October 18, 2017

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?