0
votes

So, I am implementing a pixel that needs to be added via Google Tag Manager and a variable needs to passed into it.

The GTM code has been added to the site. (This is the general code that Google give).

The pixel that needs to be fired, is on the thakn you page and looking in debug mode, I can see that the tag works.

I need to pass data to this tag so I have created a dataLayer tag

Again in debug mode, I can see this works.

However, what I am not sure is, how do i pass this data into the tag.

The Google Tag:

<img src="https://prf.hn/conversion/campaign:1101l598/conversionref:{{ The dataLayer variable to be included here}}/currency:GBP" height="1" width="1" />';

The dataLayer is:

dataLayer.push({
  'oppId': <%= current_customer.opportunities.last.id %>
});

Can someone help me so that when pixel is rendered, it shows soething like:

<img src="https://prf.hn/conversion/campaign:1101l598/conversionref:12345678/currency:GBP" height="1" width="1" />';
1

1 Answers

0
votes

You can do this with the combination of Custom Image Tag and datalayer variable.

  1. capture the "oppId" into a datalayer variable. You have pushed the value into the datalayer, to get it into GTM, you need to create a variable. Go to Variables page, click on the "New" button, pick "Data Layer Variable" at the variable type, fill in "oppId" for the name like so:

enter image description here

Then go back to the "Tag" page and create a new "Custom Image" tag. Fill in the image source with the variabe we just created sandwitched between the URL with {{my oppid}}, just value of the "src" attribute like so:

enter image description here

The last step is to just set your trigger for this pixel.

Documentation on Custom Image Tag: https://support.google.com/tagmanager/answer/6107167?hl=en