Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Data Element JS not working in DTM but works in console

Avatar

07-06-2017

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

337 likes

Total Posts

2,286 posts

Correct Reply

815 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

337 likes

Total Posts

2,286 posts

Correct Reply

815 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile
jantzen_belliston-Adobe
Community Manager

13-06-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.

Answers (12)

Answers (12)

Avatar

Avatar
Boost 50
Employee
Kaushalendra
Employee

Likes

65 likes

Total Posts

142 posts

Correct Reply

69 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Boost 50
Employee
Kaushalendra
Employee

Likes

65 likes

Total Posts

142 posts

Correct Reply

69 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Kaushalendra
Employee

09-06-2017

Hi DinoF40​,

I analyzed the issue on the page and I see that the Data Element is being used under Marketing Cloud ID Service tool to populate the Customer ID "ips4_member_id" with the value from Data Element 'ips4_member_id'.

The Marketing Cloud ID Servicetool is the first thing DTM loads and hence it seems that the object 'ipsSettings' is not available at that time, hence the error. The next step for resolution of the issue would be to load the Data Layer objects earlier on the page.

Avatar

Avatar
Validate 1
Level 1
alexf40
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
alexf40
Level 1

Likes

0 likes

Total Posts

3 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
alexf40
Level 1

12-06-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.

Avatar

Avatar
Validate 10
MVP
Amit_Kumar
MVP

Likes

329 likes

Total Posts

649 posts

Correct Reply

231 solutions
Top badges earned
Validate 10
Validate 1
Establish
Give Back 50
Give Back 5
View profile

Avatar
Validate 10
MVP
Amit_Kumar
MVP

Likes

329 likes

Total Posts

649 posts

Correct Reply

231 solutions
Top badges earned
Validate 10
Validate 1
Establish
Give Back 50
Give Back 5
View profile
Amit_Kumar
MVP

12-06-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

Avatar

12-06-2017

Hi Jantzen.Belliston​ thanks for your help, the ips object is dynamic server side but it's static as in served with the HTML.

Avatar

12-06-2017

Hi Kaushalendra​ thanks again for your help with this, I've got a lot to learn.

The 'ips4_member_id' is an authenticated login value from the CRM software, this was being used against the MC service to link the two together.

I've tried removing the authentication against the MC service but it still causes issues trying to fire too early. I'm unable to move the original JS in the HTML to the beginning of the code. Is there any way I can change the timing within DTM of when the dataElement fires?

Cheers

Avatar

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

337 likes

Total Posts

2,286 posts

Correct Reply

815 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile

Avatar
Validate 1000
Community Manager
jantzen_belliston-Adobe
Community Manager

Likes

337 likes

Total Posts

2,286 posts

Correct Reply

815 solutions
Top badges earned
Validate 1000
Springboard
Validate 500
Validate 250
Validate 100
View profile
jantzen_belliston-Adobe
Community Manager

09-06-2017

Hi,

It sounds like you might have a timing issue. Do you know if the ipsSettings object is dynamically added to the page or is it static with the page?

Thanks,
Jantzen

Avatar

08-06-2017

Well I thought it was working, in the console _satellite.getVar("ips4_member_id"); returns the correct value.

However when published I get the following error which prevents the whole DTM container from loading.

Uncaught ReferenceError: ipsSettings is not defined

    at Object.customJS (satelliteLib-dd4a7b2….js:12)

    at Object.D.realGetDataElement (satelliteLib-dd4a7b2….js:10)

    at Object.D.getDataElement (satelliteLib-dd4a7b2….js:10)

    at Object.D.getVar (satelliteLib-dd4a7b2….js:10)

    at satelliteLib-dd4a7b2….js:10

    at String.replace (<anonymous>)

    at Object.D.replace (satelliteLib-dd4a7b2….js:10)

    at g.parseIds (satelliteLib-dd4a7b2….js:11)

    at g.applyCustomerIDs (satelliteLib-dd4a7b2….js:11)

    at g.initialize (satelliteLib-dd4a7b2….js:11)

Avatar

08-06-2017

Thanks hyderziaee​, I tried this but it comes back as undefined. Interestingly the custom code works fine in live/production but not staging mode.

Why would it not work as a JS object?

Cheers

Avatar

08-06-2017

Interesting it works fine when deployed live. I assume the staging/preview mode must have affected the firing order.

Avatar

Avatar
Establish
Employee
hyderziaee
Employee

Likes

227 likes

Total Posts

465 posts

Correct Reply

222 solutions
Top badges earned
Establish
Coach
Contributor
Shape 1
Give Back 25
View profile

Avatar
Establish
Employee
hyderziaee
Employee

Likes

227 likes

Total Posts

465 posts

Correct Reply

222 solutions
Top badges earned
Establish
Coach
Contributor
Shape 1
Give Back 25
View profile
hyderziaee
Employee

08-06-2017

Why not use JS Object rather than Custom Code?

forum_DE.PNG

Avatar

Avatar
Boost 50
Employee
Kaushalendra
Employee

Likes

65 likes

Total Posts

142 posts

Correct Reply

69 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile

Avatar
Boost 50
Employee
Kaushalendra
Employee

Likes

65 likes

Total Posts

142 posts

Correct Reply

69 solutions
Top badges earned
Boost 50
Boost 5
Boost 3
Boost 25
Boost 10
View profile
Kaushalendra
Employee

08-06-2017

Hi dinof40​,

I believe you are trying to populate the Member ID to a custom variable through the Data Element and the variable is not set with a value in the call. If so, the issue could be with the order in which the code to populate the variable is executed and when the JS object is initiated on the page. If you can provide a Page URL and steps you are following to test I can have a look at the issue.