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

Dynamic dataLayer - trigger on hit

Avatar

Level 1

We have a dataLayer embedded within an Angular app that pushes an event and a data object into the dL when a user filters/edits their search. This means that the event object could change during the same pageview, or the same value could be pushed into the dL multiple times:

function(fromDate, toDate, filter) {

var analyticsEvent = function() {

   digitalData.push({

      event: "loadClaimList",

      eventData: {

        fromDate: fromDate,

        toDate: toDate

      }

    });

};

dataelementchanged doesn't work because you cannot limit persistence at the hit level, only pageview. How else can this be configured so the rule will fire every time digitalData.event = 'loadClaimList', including multiple times within the same pageview.

1 Accepted Solution

Avatar

Correct answer by
Level 9

dataelementchanged isn't scoped to eval on pageview.  It works by checking the current value against the previous value every 1000ms (1s). So the problem isn't really with scope, so much as whether or not the value changes (and also there is potential problem with timing, depending on if visitor navigates away from page during the 1s interval).

I'm actually curious how you are even trying to make use of dataelementchanged, seeing as how you are pushing to an array stack... because if your data element just looks at e.g. digitalData[0].event, well that will never change, since you are pushing your data layer payload to a new element [n].  Or maybe you are doing a custom script type that returns from last element?  Anyways..

One thing you can try is create a data element that returns the digitalData.length, and then set your dataelementchanged EBR to look at that, and then add additional conditions to the EBR to eval digitalData[n].event (directly in a custom code condition, or however you've set it up in your current data element, assuming it's properly configured to look at last pushed element)

View solution in original post

3 Replies

Avatar

Correct answer by
Level 9

dataelementchanged isn't scoped to eval on pageview.  It works by checking the current value against the previous value every 1000ms (1s). So the problem isn't really with scope, so much as whether or not the value changes (and also there is potential problem with timing, depending on if visitor navigates away from page during the 1s interval).

I'm actually curious how you are even trying to make use of dataelementchanged, seeing as how you are pushing to an array stack... because if your data element just looks at e.g. digitalData[0].event, well that will never change, since you are pushing your data layer payload to a new element [n].  Or maybe you are doing a custom script type that returns from last element?  Anyways..

One thing you can try is create a data element that returns the digitalData.length, and then set your dataelementchanged EBR to look at that, and then add additional conditions to the EBR to eval digitalData[n].event (directly in a custom code condition, or however you've set it up in your current data element, assuming it's properly configured to look at last pushed element)

Avatar

Level 1

That's super helpful, thank you! Do you have a link to the docs that references the 1000ms check on dataelementchanged? I have yet to see that in the documentation.

Checking for the length works for the rule condition and checking the last object in the array will return the required values for the eVar.

Avatar

Level 9

I have not found it officially stated in documentation either, but

a) I have seen it confirmed by Adobe in Slack #measure > #adobe-dtm

b) I can also see it in the DTM library code:

chrome_2018-02-21_13-40-10 - Copy.png

chrome_2018-02-21_13-41-04 - Copy.png

c) You can do your own quick test to see it in action.

Create a Data Element named current_time.  Make it Custom Script type with following code:

return (new Date()).toString();

Create an Event Based Rule with Event Type of dataelementchanged, referencing the current_time Data Element.

Add a Javascript / Third Party Script with the following:

var current_time = _satellite.getVar('current_time');

console.log('DTM: dataelementchanged test called: current_time: ', current_time);

You can then go to your test page and open the javascript console and see something along the lines of this:

chrome_2018-02-21_14-04-23 - Copy.png