Reputation: 1215
I'm trying to add a Google AdWords remarketing list tag after the page has loaded with javascript - essentially after a user has taken a specific action.
The tag I get from google is something like this:
<!-- Google Code for English Job Seekers -->
<!-- Remarketing tags may not be associated with personally identifiable information or placed on pages related to sensitive categories. For instructions on adding this tag and more information on the above requirements, read the setup guide: google.com/ads/remarketingsetup -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1234567890;
var google_conversion_label = "abcdefghijk01234567890";
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1234567890/?value=1.00&currency_code=USD&label=abcdefghijk01234567890&guid=ON&script=0"/>
</div>
</noscript>
I may want to add more tags later in the page, depending on the user's behaviour, so the four global variables seems like a bad idea. Is there a way to trigger this without the global variables (maybe just inserting the tracking image with jQuery)?
Upvotes: 0
Views: 1343
Reputation: 1185
Yep - just use the asynchornous version of the tag that does not use globals: https://developers.google.com/adwords-remarketing-tag/asynchronous/
So you need to include the asynchronous script in your like so:
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>
Then when you need to trigger it, just call the new function that is available in the global scope as many times as your need
<script type="text/javascript">
/* <![CDATA[ */
window.google_trackConversion({
google_conversion_id: 1234567890,
google_conversion_label: 'abcdefghijk01234567890',
google_custom_params: window.google_tag_params,
google_remarketing_only: true
});
//]]>
</script>
Make sure you update window.google_tag_params each time you call with fresh information (or just use a separate object or object literal).
Hope that helps.
Upvotes: 3