Reputation:
I have multiple Facebook Pixels ID that will be passed as URL parameters (i.e. first pixel 'fbpid=123456789' - second pixel 'fbpid=987654321' etc.)
Whenever a user clicks a certain button, if the URL parameter is 'fbpid=12345679', then only the pixel ID 123456789 should be fired.
Instead, if the pixel ID in the URL parameter is 'fbpid=987654321' then only the pixel with the ID 987654321 should be fired, and so on.
How could I retrieve the URL parameter in GTM and fire just the Facebook pixel ID passed as URL parameter?
Upvotes: 0
Views: 2682
Reputation:
Thanks a lot for your answer.
Here's how the entire pixel script looks like:
`<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'PIXEL_ID');
fbq('track', 'PageView');
fbq('track', 'Lead');
</script>`
Would it be possible to replace just the "PIXEL_ID" inside the script above with the 'fbpid' passed as a query?
Upvotes: 0
Reputation: 32770
Go to variables, custom variables, new, select "URL" as variable type, "query" as component type and "fbpid" as query key. This will return the value for fbpid if the query parameter is present in the url.
You can then use the value in a trigger (i.e. create a pageload trigger, fire on some events, condition fbpid equals 123456789).
Upvotes: 2