i want to create a dynamic remarketing campaign in Google Ads, but i have to let GTM know where to extract the information for ecomm_prodid, ecomm_pagetype, ecomm_totalvalue and ecomm_category from my website. I understand that i have to create a Data Layer Variable but i just don't know how to make those tags extract the necessary info from my website. I also know that you should be able to see in Google Tag Assistant the Metadata for your products (price, brand, category etc) in the Dynamic Remarketing Tag. Unfortunately i cannot add code to my website as it was created on a platform that doesn't allow custom code, so i have to use GTM.

For example the class for the price is: fPrice -g-product-final-price-258. Shouldn't ecomm_totalvalue take info from this class? I tried reading Help pages from google but they are soooo confusing, i cannot understand them.

If anyone would help me with this i would be very grateful.

Thanks

Tag:google-ads-api, google-tag-manager, google-datalayer, data-layers

Only one comment.

  1. sebieire

    I know this is 10 months late but this might help you or lead someone arriving here to hopefully the right direction and/or solution. I came across your question unanswered when looking for something else. It seems you have two questions so I'll try to answer both.

    For starters you might want to have a quick look at the GTM Dynamic Remarketing Documentation.

    Question 1: Where to extract the information for [variables] ?

    You are on the right track with the dataLayer here. Usually you need to implement that with custom Javascript on your website (which in your case you can't do / see below for that). You would usually populate a events & variables with dataLayer.push() function.

    Here is a sample of how that could look:

    dataLayer.push({ 'event': 'your_event_name', 'a_container_name' : { 'key1' : key_var_1, 'key2' : key_var_2, } })

    You can also do inner structures within those structures (nested dictionary).

    Once those are populated you can create variables in Google Tag Manager (GTM) and simply pick up the values with the naming convention you've used separated by a "." (dot). For the above you could for example do: "a_container_name.key1" which would then populate the variable in GTM with the value of "key_var_1".

    You can use the event name (here: 'your_event_name') as the trigger for the Tag in GTM to fire your Tag.

    So in your case you would usually want the variable "ecomm_prodid" taken from the webpage with a bit of javascript and pushed into the dataLayer for you to pick up in GTM as described.

    Question 2: I cannot add code to my website, what can I do ?

    While this is entirely possible it is unfortunately a bit more tedious and potentially much more error prone. In this case you have to read the values you want directly from your website through GTM.

    You can use custom javascript inside variables in GTM. To do so click on "variables", then click on "New" and select "Custom Javascript". You can then use pretty much any javascript here to basically scrape the value off your website based on id, class or any other HTML identifiers. There are tons of options on how to do that. You have to use what works best for you.

    However this is potentially very error prone. Here is why: You've stated that your class for the price is "fPrice -g-product-final-price-258". This looks to me very much like an auto generated identifier. Next time you look at that product or pick another one it is most likely different. So your option is to take either another unique identifier or use a sub-string of that one (e.g.: fPrice -g-product-final-price only). But keep in mind if your website ever updates or changes those class names the javascript you wrote instantly will not work any longer.

    So it is important to pick some robust form of identifier or write the javascript code so that it will last. As mentioned, the jvascript to scrape or read directly off your website can be as custom as you like. Here is a crude example of how this would look like.

    var text = ''; // empty value placeholder if (document.getElementsByClassName("YOUR_SPECIFIC_CLASS_NAME")) { ....loop through returned elements if applicable.... ....do stuff here or check stuff here... text = SOME_ELEMENT.innerHTML; console.log(text) // helps to debug your code } return text

    Again this is only a crude example but if you get this to work then you can simply use the populated variable in your Tag in any field that supports variable with the double curly brackets: {{YOU_TAG_MANAGER_VARIABLE_NAME}}

    I hope this helps and gives you a bit on an insight. Good luck!

    PS: By the way. If you can't edit your code because of your website provider or website engine then I would strongly recommend moving away from it. As you can see it would save you a ton of headache. For smaller to mid sites and smaller e-commerce stores use Wordpress. For larger stuff there are other solutions. In any case there are some website builders out there that are simply really bad but at the same time very misleading. Basically leading you to the problems as you've described. Don't use them :)

Add a new comment.