Data Element JS not working in DTM but works in console | Community
Skip to main content
June 8, 2017
Solved

Data Element JS not working in DTM but works in console

  • June 8, 2017
  • 13 replies
  • 8246 views

Hi,

I'm hoping someone could help. I'm trying to get an on page JS variable into a DTM data element. The code works fine in Google Tag Manager and works in the dev console but is undefined in Adobe DTM.

This is what I'm using as the custom JS for the data element:

    var ips4_member_id = ipsSettings.memberID;

    return ips4_member_id;

The JS script on the HTML page is as follows and I'm trying to get the member ID:

<script type='text/javascript'>

   var ipsSettings = {

  disableNotificationSounds: false,

  useCompiledFiles: true,

  links_external: 1,

  memberID: 0,

  analyticsProvider: "custom",

   };

  </script>

Any help would be much appreciated.

Cheers

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 jantzen_b

The code inside the Data Element is called the first time the data element is called. Typically, you could change your rule to fire at page bottom or DOM ready to see if either of those delays the rule long enough. However, If you're using the data element inside the ID service tool, there isn't a UI option for delaying that code.

In case you write code to delay the ID service, you need to ensure it loads before all other Adobe solutions since the solutions rely on the ID being returned from the ID service to perform many of their functions. In all cases, be sure to thoroughly test your code on a staging environment to ensure the ID is properly maintained and or migrated.

13 replies

Amit_Kumar
Level 10
June 13, 2017

In the custom JS use the following which will fix your problem.

var ips4_member_id = -1;

var checkExist = setInterval(function() {

   if (ipsSettings && ipsSettings.length) {

      clearInterval(checkExist);

      ips4_member_id = ipsSettings.memberID;

   }

}, 100);

return ips4_member_id;

Note: This is a patch work but it will fix your problem

Regards,

Amit

June 13, 2017

Hi Amit Kumar​ thanks for your help, I tried the above code and it stops DTM from crashing however it populates the data element as -1.

jantzen_b
Adobe Employee
jantzen_bAdobe EmployeeAccepted solution
Adobe Employee
June 13, 2017

The code inside the Data Element is called the first time the data element is called. Typically, you could change your rule to fire at page bottom or DOM ready to see if either of those delays the rule long enough. However, If you're using the data element inside the ID service tool, there isn't a UI option for delaying that code.

In case you write code to delay the ID service, you need to ensure it loads before all other Adobe solutions since the solutions rely on the ID being returned from the ID service to perform many of their functions. In all cases, be sure to thoroughly test your code on a staging environment to ensure the ID is properly maintained and or migrated.