I'm using a Non-Sequential HTML Javascript/Third Party tag, where I'm using the following script to pass data to a 3rd party tag.
<script>
x = _satellite.getVar('Sub-Total');
</script>
The problem that I have is that no data is passed to "x".
I have also tried the following:
<script>
var x = $('td[data-hook="order_item_total"]').text().substring(1);
</script>
In this case I'm getting $ is undefined. Note, both methods work when I test it in the Javascript console and if I use a Non-Sequential Javascript tag. What do I need to add to make either of these work? Your help is greatly appreciated.
Thanks,
Ridder
The issue is when you configure your tag to be Non-Sequential HTML, the code is output dynamically in an iframe
. Since the iframe
doesn't include the _satellite
object, attempting to reference it results in an undefined
error.
If your tag contains a blend of html and javascript that needs to be output and you need _satellite
exposed, you need to instead use a Sequential HTML tag.
Alternatively, if the code in your tag is really purely javascript and just happens to be wrapped in <script>
tags, then simply remove the <script>
tag wrapper and put the code in a Javacript style tag (It doesn't matter if it's sequential or non-sequential; both will have _satellite
exposed to it) .
Note: I could find no mention of this in the DTM documentation (though I could be blind!), but If you open your browser's developer console and look at the live/rendered DOM, you can verify this yourself. I feel like at a minimum this caveat should at least be mentioned in the documentation.