Posted on

Facebook Ads Tracking Multiple Domains

Facebook ADS

To implement Facebook tracking across multiple domains, including a scenario where the ad redirects users to a landing page on one domain and the purchase is completed on another domain, you can use one of the following methods:

    • Use the Facebook Conversion API to send server-side events to Facebook. The Conversion API allows you to send web and app events from your server to Facebook, which can help you measure customer actions across multiple domains and devices. You can use the Conversion API in combination with the Facebook Pixel to improve the accuracy and reliability of your conversion tracking. To use the Conversion API, you need to:
      • Create a Facebook Pixel and a Facebook Access Token for your app or website.
      • Install the Facebook Pixel on your landing page and your purchase page, and use the fbq('init', 'pixel_id') function to initialize the Pixel with your Pixel ID.
      • Generate a unique event ID for each event you want to track, and pass it to the Pixel using the fbq('track', 'event_name', {eventID: 'event_id'}) function. You can also pass other parameters, such as value, currency, content_type, and content_ids, to provide more information about the event.
      • Send the same event ID and parameters to the Conversion API using a HTTP POST request to the following endpoint: https://graph.facebook.com/v11.0/<pixel_id>/events?access_token=<access_token>. You need to include a JSON payload in the request body that contains the event_name, event_time, event_id, and other parameters. You can also include a user_data object that contains hashed information about the user, such as email, phone, or client_ip_address, to help Facebook match the event to a person.
      • You can use the Facebook Event Manager to verify that your events are received correctly by both the Pixel and the Conversion API.

      For more information and examples on how to use the Conversion API, you can refer to the following web pages:

Using iframe

  • Use an iframe approach to inject the Facebook Pixel code into the subdomain or the different domain. This method can help you track events across domains that share the same top-level domain, such as example.com and sub.example.com, or domains that have a cross-domain agreement, such as example.com and partner.com. To use the iframe approach, you need to:
    • Create a Facebook Pixel and install it on your landing page and your purchase page, and use the fbq('init', 'pixel_id') function to initialize the Pixel with your Pixel ID.
    • Create a new page on your main domain that contains the Facebook Pixel code and the event you want to track, such as ViewContent, AddToCart, or Purchase. You can also include parameters, such as value, currency, content_type, and content_ids, to provide more information about the event. For example, you can create a page named facebook-pixel-purchase.html that contains the following code:

<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex">
<!-- Facebook Pixel Code -->
<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', 'Purchase', {value: '0.00', currency: 'USD'});
</script>
<noscript>
<img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=pixel_id&ev=PageView&noscript=1"/>
</noscript>
<!-- End Facebook Pixel Code -->
</head>
<body></body>
</html>

Note that you should also add the robots meta tag to prevent search engines from indexing this page.

  • Add an iframe tag to your subdomain or different domain page that points to the page you created on your main domain. For example, you can add the following code to your purchase page on sub.example.com or partner.com:

<iframe src="https://example.com/facebook-pixel-purchase.html" style="width:0;height:0;border:none;"></iframe>

This will inject the Facebook Pixel code and the event into the subdomain or different domain page, and allow you to track the event across domains.

For more information and examples on how to use the iframe approach, you can refer to the following web pages: