How to fetch dynamic value in 3rd Party Tags in DTM ? | Community
Skip to main content
adwait_krishna
Level 2
October 16, 2015
Solved

How to fetch dynamic value in 3rd Party Tags in DTM ?

  • October 16, 2015
  • 2 replies
  • 1804 views

Hi All,

We have some code snippet which we want to place on the page and I can use 'Javascript/Third Party Tags' to do that. 

But the challenge is, we have some fields in the snippet which requires data to be picked up from the page dynamically. Please see below one sample code snippet:

<script>
demo.identify({
customer_id:'11111', // TODO: Replace with your customer identifier
email: 'johndoe@somedomain.com', // TODO: Replace with your customer's email address
joined_at: '2014-08-24’, // TODO: Replace with your customer's join date
firstname: 'John', // TODO: Replace with your customer's firstname if available
lastname: 'Doe' // TODO: Replace with your customer's lastname if available
});
</script> 

 

These all fields needs to be populated from the page dynamically. The page has these details available. 

Please suggest, how can the data be picked from and then how these picked data be fetched here in the snippet ?

 

Thanks,

Adwait

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 devinderbanga

Hi

why not use jQuery to obtain data from the page? 

Suppose your page has an email field with id = 'mail'. You could do something similar to:

<script>

var mailValue = $('#mail').val(); // or .text() or .html() or whatever you need from that field
demo.identify({
customer_id:'11111', // TODO: Replace with your customer identifier
email: mailValue
joined_at: '2014-08-24’, // TODO: Replace with your customer's join date
firstname: 'John', // TODO: Replace with your customer's firstname if available
lastname: 'Doe' // TODO: Replace with your customer's lastname if available
});
</script> 

You can also create a data element for your email, which value you can then read in your script. So you would create a data element in which you would put a script similar to:

 return $('#mail').val();

You can obviously add some validation to check whether this #mail field exists etc prior returning it. Then in your script you can use _satellite methods to read the value of the data element, like so:

<script>

var mailValue =  _satellite.getDataElement('your data element name');
demo.identify({
customer_id:'11111', // TODO: Replace with your customer identifier
email: mailValue,
joined_at: '2014-08-24’, // TODO: Replace with your customer's join date
firstname: 'John', // TODO: Replace with your customer's firstname if available
lastname: 'Doe' // TODO: Replace with your customer's lastname if available
});
</script> 

Courtesy: Michal Papciak

    Regards

    Devinder

    2 replies

    devinderbanga
    devinderbangaAccepted solution
    Level 6
    October 16, 2015

    Hi

    why not use jQuery to obtain data from the page? 

    Suppose your page has an email field with id = 'mail'. You could do something similar to:

    <script>

    var mailValue = $('#mail').val(); // or .text() or .html() or whatever you need from that field
    demo.identify({
    customer_id:'11111', // TODO: Replace with your customer identifier
    email: mailValue
    joined_at: '2014-08-24’, // TODO: Replace with your customer's join date
    firstname: 'John', // TODO: Replace with your customer's firstname if available
    lastname: 'Doe' // TODO: Replace with your customer's lastname if available
    });
    </script> 

    You can also create a data element for your email, which value you can then read in your script. So you would create a data element in which you would put a script similar to:

     return $('#mail').val();

    You can obviously add some validation to check whether this #mail field exists etc prior returning it. Then in your script you can use _satellite methods to read the value of the data element, like so:

    <script>

    var mailValue =  _satellite.getDataElement('your data element name');
    demo.identify({
    customer_id:'11111', // TODO: Replace with your customer identifier
    email: mailValue,
    joined_at: '2014-08-24’, // TODO: Replace with your customer's join date
    firstname: 'John', // TODO: Replace with your customer's firstname if available
    lastname: 'Doe' // TODO: Replace with your customer's lastname if available
    });
    </script> 

    Courtesy: Michal Papciak

      Regards

      Devinder

      adwait_krishna
      Level 2
      October 16, 2015

      Thanks Devinder for your detailed answer. I will try this way and let you know if I face any further challenges.

      Regards,

      Adwait