Adobe DTM Data Element Updating

2020-03-06 11:53发布

问题:

I'm looking for a way to dynamically update a pre-defined data element in DTM. Once the page loads and the data elements are initialized it is not possible to update them, _sattelite.setVar() does not work. I can create a Data Element on the fly but it won't persist from page to page.Example:

var currElementName = this.getAttribute('data-analytics-tracking-name');
_satellite.setVar('custom link name', currElementName);

Any suggestions? I'm asking this because I'm going to be working with a MVC framework and I'd like to store some of the data in DTM data elements and update as views change. Thanks!

回答1:

In order to set a persistent data element to a new value, you need to first update whatever source the data element is based off of, and then use _satellite.getVar('element_name_here') to force evaluation of the data element.

The key here is that on page load, the order of operations for a persistent data element is basically:

  1. Look for the satellite cookie and return that value
  2. Look for the specified target for the type (e.g. path (js var) for type JS Object) and return that value
  3. Return the default value

But when you explicitly call _satellite.getVar('Example'), the order of operations is instead:

  1. Look for the specified target for the type (e.g. path (js var) for type JS Object) and return that value
  2. Look for the satellite cookie and return that value
  3. Return the default value

Data Element Example:

Name: Example

Type: JS Object

Path: someVariable

Default Value: default value

Remember this value for: Session

So let's say I have on the page the following (set prior to DTM script tag):

someVariable = 'foo';

This will make available a data element named "Example" which you can reference with %Example% or _satellite.getVar('Example'), depending on the context.

For the duration of the session, the data element will have that value "foo". So to change it, you would do the following:

someVariable='bar';
_satellite.getVar('Example');

You can call this within your own script somewhere, or if you want to throw this into the mix for e.g. a page load rule, you can add it as a condition inside a Criteria > Data > Custom code box (note: if you put it here, add a return true; as 3rd line), etc..

As an alternative, if you are feeling more adventurous, or need a work-around for your data element setup (e.g. your data element is type Custom Script and you need to sidestep the logic in there)..

When you have a data element configured to be persistent, it sets a cookie named

_sdsat_[data element name]

So in the example above, it sets a cookie named

_sdsat_Example

So, if you really wanted to, you can instead just update the cookie with the new value, and just let the default order of operations return the (now updated) cookie value. (note: since it's not possible with javascript to get the expiration of a cookie, if you are setting the scope to "Visitor", you can set the expiration to 2 years, which is what DTM does)