facebook

Changing the Facebook “tr” endpoint to send Facebook Events to another URL (GTM Server-Side – Conversion API)

As a caveat this is an **unofficial** way of achieving this as of this article’s writing…

The question is why would you even want to change where events are sent to in the first place?

For certain Server-Side implementations (e.g. GTM Server-Side implementations with the Facebook Conversion API) there is a need to send your events to a different url other than https://facebook.com/tr .

There is an unofficial and undocumented method that will allow you to do this out-of-box. I had to read the pixel code to find this out, but it seem to be an effective way to modify the endpoint that the Facebook Pixel sends to. In a sense, it is like the “transport_url” for GA.

To the JS endpoint in the FB pixel you can call the “set” function with “endpoint” then override the default server that “tr” calls are made to. So just add the following line before your fbq calls and it will override FB’s default endpoint URL:

endpoint   
  1. fbq('set', 'endpoint', ' https://yoururl.com/tr');

So how your pixel code could resemble would be. When you run the script you’ll see that the calls are now being made to the endpoint you added.

fbpixel   
  1. !function(f,b,e,v,n,t,s)
  2. {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
  3. n.callMethod.apply(n,arguments):n.queue.push(arguments)};
  4. if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
  5. n.queue=[];t=b.createElement(e);t.async=!0;
  6. t.src=v;s=b.getElementsByTagName(e)[0];
  7. s.parentNode.insertBefore(t,s)}(window, document,'script',
  8. 'https://connect.facebook.net/en_US/fbevents.js');
  9. fbq('set', 'endpoint', ' https://yoururl.com/tr');
  10. fbq('init', '<YOUR_PIXEL_ID>');
  11. fbq('track', 'PageView');
Farmer

Share
Published by
Farmer

Recent Posts

Facebook Business Manager Verification – “Start Verification” Button Disabled!?

There are many benefits to verify your Business Manager on Facebook; however, it is not…

5 years ago

Adding the Facebook Pixel to a GTM AMP Container

One issue when adding the Facebook pixel to a Google Tag Manager AMP container is…

6 years ago

Installing dependencies to get Puppeteer 1.0 running on Ubuntu 16.04

When trying to run Puppeteer 1.0 within your Node.JS scripts on an Ubuntu 16.04 box and…

6 years ago

API Rate-Limiting with Lumen 5.6 and Illuminate Routing/ThrottleRequests Class

Off the back of this article, there could be some potential improvements to make the…

6 years ago

How to use the Facebook img tag to fire pixel events

Before implementing the img tag, the previous article should be reviewed: it discusses some of…

6 years ago