Tracking Chef
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • About
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • About
Tracking Chef
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • About
  • Guides
    • Google Ads
    • Google Analytics
    • Google Tag Manager
    • Google Data Studio
    • Facebook
    • LinkedIn Ads
    • Hubspot
    • Segment
    • Quora Ads
    • Reddit Ads
  • Blog
  • GTM Playground
  • Swag
  • About
Fixing Facebook referrer tracking in Google Analytics
Home » Facebook
August 3, 2020 Elad Levy

When trying to report on traffic from coming Facebook to your site, you can come across multiple instances of Facebook across several Source/Medium rows.

Most commonly, you can expect to see facebook.com, m.facebook.com, l.facebook.com and lm.facebook.com.

Multiple Facebook referrers in the Source/Medium report

This can be quite a pain in the neck when configuring your reports for Facebook traffic.

Why does this happen?

Facebook sends traffic through two main domains based on the device the user is on – Desktop or Mobile. This is indicated by the letter M in the subdomain, i.e. m.facebook.com and lm.facebook.com.

On top of that, Facebook uses a mechanism called Link Shim that sends the user via a redirect before landing on your site. This adds the letter L to the subdomain, i.e. l.facebook.com and lm.facebook.com.

This mechanism serves two purposes:

  1. Protecting the user’s privacy – if the user clicked a link on their Facebook profile, the referral URL (Full Referrer) would show their profile link, which is personally identifiable information (PII)
  2. Protecting the user from malicious links – Before sending the user to the external link, Facebook checks that the link is legit against a list of malicious sites built by Facebook, Google McAfee and others.

How to solve this

Solving this is pretty easy, by adding a simple ‘Search and Replace’ filter on your Google Analytics view.

  1. Open Google Analytics and navigate to the admin section
  2. Under the relevant view, click Filters and then ‘Add Filter’
  3. Select ‘Create new Filter’
  4. Name the filter something descriptive, e.g. ‘Facebook referrer rewrite’
  5. Set the Filter Type to Custom
  6. Select Search and Replace
  7. Set the Filter Field to ‘Campaign Source’
  8. Under ‘Search string’ paste ^.*.facebook.com
  9. Under ‘Replace string’ paste facebook.com
  10. Save the filter
Facebook referrer rewrite filter

Pro tip:
Always create a backup view for your property that doesn’t have any filters applied to it

You can also verify your filter before saving to examine how the filter would have impacted your past seven days data. The table below shows the values impacted and the expected output of the filter.

Validating the filter

The bigger issue with Facebook tracking in Google Analytics

The key issue with Facebook tracking in Google Analytics is the inability to distinguish between Paid and Organic traffic coming from Facebook. Google can’t tell apart these traffic types, so if you’re reporting on Paid Facebook campaigns using Google Analytics you could run into attribution issue.

The standard mechanism for solving this is by using UTMs in your Facebook ads, so that a user sent to your site from a campaign will be clearly marked for Google Analytics.

For example, a user will be sent to the link:

https://www.example.com/product?utm_source=facebook&utm_medium=ppc&utm_campaign=summer-2020

Paid vs Organic Facebook traffic in Google Analytics

These UTMs can be added in Facebook in one of two ways:

  1. Directly on the Website URL you’re sending the users to. You can use Facebook’s built in tool for that

  2. You can also use the URL Parameters box to add these. Using this box makes the UTM management easier across the entire account.

Using Facebook’s native UTM tool can also inject dynamic parameters from Facebook, e.g. the Campaign’s ID or the Ad Set’s name for more granular control at scale (although some might argue that these are notoriously error prone).

About the Author

Elad Levy View all posts by Elad Levy

Experienced Web Analyst, working for almost a decade now with various web analytics tools.
Also a husband, father of three rascals, and the co-founder of Fixel.

« Previous
Next »
5 Responses
  1. רונן
    Reply
    October 8, 2020 at 3:59 pm

    היי,
    במאמר המצויין שלך על סינון תוצאות פייסבוק באנליטיקס, לא ברור באיזה מחרוזת חיפוש להשתמש. בטקסט ההסבר היא מופיעה בצורה אחת, ובתמונה בצורה אחרת
    https://prnt.sc/uvgz54
    https://trackingchef.com/google-analytics/fixing-facebook-referrer-tracking-in-google-analytics/
    אשמח אם תוכל להבהיר,

    תודה, רונן

    • Elad Levy
      Reply
      October 8, 2020 at 4:26 pm

      האמת ששתי האפשרויות פועלות באותה המידה, אבל איחדתי כדי שיהיה עקבי יותר
      תודה שהסבת את תשומת ליבי 🙂

  2. רונן
    Reply
    October 8, 2020 at 5:49 pm

    בכייף! רק שים לב שעדיין יש סלאשים (\) בסטרינג השני ובראשון לא [אני יודע ששניהם עובדים אבל זה עדיין עשוי לבלבל
    תודה שוב, אלוף!

    https://prnt.sc/uvjq54

  3. Adam
    Reply
    February 24, 2021 at 2:08 am

    I was having difficulty verifying the filter you’ve provided and then I noticed that the RegEx in step 8 of your post (^.*.facebook.com) is actually different than the RegEx in your screenshot (^.*\.facebook\.com) so I tried that. Unfortunately, that didn’t work either so I came up with my own and wanted to share with you. This is the RegEx that allowed to me verify the filter was working correctly: ^*\.facebook\.com$

    • Elad Levy
      Reply
      February 28, 2021 at 10:50 am

      Hey Adam, thanks for sharing your variation 🙂
      All three work, though there is slight some nuance between them.
      Note the Regex string you’ve written has a multiplier (*) without any preceding character.
      Mine arguably use a dot w/o a slash (i.e. escaped) which potentially could return any character too.

Leave a Reply

Click here to cancel reply.

Contents hide
Why does this happen?
How to solve this
The bigger issue with Facebook tracking in Google Analytics
Made with ❤️ by Elad Levy
Disclaimer: Some of the links shared on this site are affiliate links, so if you choose to make a purchase, I’ll earn a small commission. Please note, I only recommend tools I’ve used and have found useful, the commission is not a driving factor