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, Adi
The easiest way would be to create data elements in DTM that reference the values that exist on the page. You can use the getVar method to return the value of a data element by passing in the name of the data element. Then your code would look like this:
<script>
demo.identify({
customer_id:_satellite.getVar('customer id'), // Or whatever the data element name you create is
email: _satellite.getVar('customer email'), // TODO: Replace with your customer's email address
joined_at: _satellite.getVar('customer join date'), // TODO: Replace with your customer's join date
firstname: _satellite.getVar('customer firstname'), // TODO: Replace with your customer's firstname if available
lastname: _satellite.getVar('customer lastname') // TODO: Replace with your customer's lastname if available
});
</script>