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.
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:
- 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)
- 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.
- Open Google Analytics and navigate to the admin section
- Under the relevant view, click Filters and then ‘Add Filter’
- Select ‘Create new Filter’
- Name the filter something descriptive, e.g. ‘Facebook referrer rewrite’
- Set the Filter Type to Custom
- Select Search and Replace
- Set the Filter Field to ‘Campaign Source’
- Under ‘Search string’ paste ^.*.facebook.com
- Under ‘Replace string’ paste facebook.com
- Save the filter
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.
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:
These UTMs can be added in Facebook in one of two ways:
- Directly on the Website URL you’re sending the users to. You can use Facebook’s built in tool for that
- 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).