Collecting Meta (formerly known as Facebook) advertiser id in Google Analytics 4

In this guide you will learn how you can record your website visitors Meta ad id in your GA4 account. Recording Meta ad ids in GA4, will help you in creating more targeting remarketing audiences in Meta.

Pre-requisites to this guide

  • GA4
  • Google Tag Manager
  • Meta Pixel

Step 1 - Creating a "User-Defined Variable" in Google Tag Manager

Go to your Google Tag Manager account, navigate to your active workspace --> Variables

Under Variables, create a new "User-Defined Variable", where the type is "Custom JavaScript" and paste the code you see below

function getCookie() {
  var value = '; '+ document.cookie;
  var parts = value.split('; _fbp=');
  if (parts.length === 2) return parts.pop().split(';').shift();

Hit "save" and give the variable a name, e.g: Toplyne FBP

Step 2 - Add the variable to a Tag

Navigate to Tags section of your dashboard and look for the GA4 configuration tag (recommended) or a tag where the firing trigger is All Pages. In that tag, add a configuration parameter, where the key can be set as FPB in plain text, and in the value, select the variable you created in the step above.

Once done, hit save

Step 3 - Submitting your changes

Once you've saved your tag, you need to submit the changes. Post submission, data can take up to 24 hours to show up in your GA4 account