How to use Mailchimp Merge Tags and Google Tag Manager for Facebook Advanced Matching

Blake Epstein

What is Facebook advanced matching?

"This new feature of the Facebook pixel enables advertisers to leverage their own customer data such as email address, phone number, and so on. By implementing this feature, advertisers can report on more conversions, optimize their ads against more conversion data, and reach more people on Facebook with their website custom audiences or dynamic ads.”

The more data you send along each Facebook event, the more you’ll be able to optimize and increase your conversion rates. This has huge on building better audience models for custom audiences and lookalikes.

Since most web traffic is anonymous, it’s difficult know these user’s emails, phone numbers or Facebook ID’s. One great way to help identify traffic is through leveraging your own first-party data through email campaigns.

By using Mailchimp’s merge tags you can send customer data through each URL inside an email. When the user visits the site that data is carried with them and can then be read by the Facebook pixel.

1) Get the Merge Tag and set up URL’s inside of Mailchimp
Inside of “Lists” click “Settings”, then navigate to “List fields and *|MERGE|* tags”


Once you view the fields, you can see all the field labels (your list columns) and the merge tags for those fields. In my example I will use email or *|EMAIL|* . You can now use this as a query string on a URLs inside of your email.


So if I had a button that asked the user to read an article on my blog or visit a product in my store I can simply add it onto a URL. For example,*|email|* Now once you send this to your list and a user clicks on a link, this is what will be in the browser URL:


As you can see, [email protected] is populated.

2) Use Google Tag Manager to Create a Macro
Google Tag Manager is not needed — you can use Javascript or JQuery to do this, but I suggest using it because it’s an amazingly powerful tool and makes things very easy.

Inside of GTM navigate to “Variables” on the left side, then click “new”. Once there create a variable called “userEmail”.

After that choose the variable type “URL” then select “Query” under “Component Type”. The “Query Key” is going to be “user”.


This basically means that GTM will look at query string inside the browser after the question mark. ( ) and save it as a variable we can use called userEmail.

If you pull up GTM’s preview tool, you can see it live below. Once we know it’s working we can pass this variable into Facebook’s pixel.


2) Pass the GTM Macro into the Facebook pixel
Inside of “Tags” find your Facebook pixel. From there, add the advanced matching code:

fbq('init', '', { em: 'email' });

Now, you can use the Macro of the variable we created and insert it into the pixel code.

fbq('init', '', { em: '{{userEmail}}' });

Publish then test via the Facebook Pixel Helper tool. You should see it firing. Because Facebook automatically hashes the email, you’ll see a long alpha-numeric string instead of the actual email address.


And that’s it. You know have advanced Facebook matching in place.


Other Posts