How to Track Social Shares in Google Analytics
Knowing that someone found your article on LinkedIn is valuable, but understanding which articles inspire them to click your on-site “Share to LinkedIn” button is a different level of insight. This isn’t data Google Analytics provides out-of-the-box, but setting it up is easier than you think. This tutorial will walk you through exactly how to track social sharing clicks on your website as events in Google Analytics 4 using Google Tag Manager.
Why Bother Tracking Social Shares?
While referral traffic shows you which social platforms send visitors to your site, tracking shares shows you what content is compelling enough for visitors to broadcast from your site. This data is a direct signal of engagement and content resonance.
- Identify Your Best Content: Uncover the specific pages, blog posts, or products that your audience finds most valuable and share-worthy. An article with low traffic but high shares might be a hidden gem.
- Understand Your Audience: Do shares on Twitter outperform those on Facebook? This tells you where your most engaged audience members prefer to communicate, helping you focus your own social media efforts.
- Find Your Ambassadors: While this setup won’t identify the exact user who shared, a spike in shares can alert you to content that is starting to gain organic traction, allowing you to amplify it further.
The Tool for the Job: Google Tag Manager (GTM)
Google Analytics 4 is fantastic at tracking what happens on a page (like scrolls and views), but it can't automatically see clicks on specific external links, like a share button for Twitter or Facebook. For this, we need its powerful sidekick, Google Tag Manager (GTM).
GTM acts as a middleman. It watches your website for specific visitor actions (like a click on a share button) and then tells other tools, like Google Analytics, that the action happened. If you haven't installed GTM on your site yet, you’ll need to do that first. It involves adding a small snippet of code to your website’s header and body, and there are many plugins that can help with this on platforms like WordPress.
Once GTM is set up, we will configure a "Tag" and a "Trigger" to get the job done.
- The Trigger: This is the rule that tells GTM when to fire. Our rule will be, “Fire when someone clicks a link that contains a social sharing URL.”
- The Tag: This is what GTM does when the trigger fires. Our tag will tell GTM, “Send an event to GA4 called ‘social_share’ and include which platform they shared to.”
Step 1: Create a Trigger for Social Share Clicks
First, log in to your Google Tag Manager account and navigate to the container for your website.
This trigger is designed to activate whenever a user clicks an outbound link that contains the classic signature of a social share link, like ‘facebook.com/sharer/’ or ‘twitter.com/intent/tweet’.
- Navigate to Triggers from the left-hand menu and click New.
- Give your trigger a clear name, like “GA4 - Trigger - Social Share Click”.
- Click on Trigger Configuration and choose the trigger type Click - Just Links under the Click section.
- Select Some Link Clicks. This ensures the trigger doesn’t fire on every single link click on your website.
- Now, set the condition for when this trigger fires. From the dropdowns, set the rule as follows: Click URL > matches RegEx (ignore case) > twitter.com/intent/tweet|facebook.com/sharer|linkedin.com/share
This piece of regular expression (| means "OR") tells GTM to look for a click on a URL containing any of those three social sharing paths. You can add more networks by including their sharing URL patterns, separating each with another | pipe character (e.g., pinterest.com/pin/create).
twitter.com/intent/tweet|facebook.com/sharer|linkedin.com/share|pinterest.com/pin/create
After setting the condition, click Save.
A Note on Built-in Variables
For this to work, GTM needs to know what a "Click URL" is. By default, it might not. On the left menu, go to Variables. Under Built-In Variables, click Configure and make sure that "Click URL," "Click Text," and "Page URL" are all checked. This makes them available for use in your tags and triggers.
Step 2: Create a Tag to Send Data to GA4
Now that GTM knows when to listen, we need to tell it what to do. In this case, it’s sending an event to GA4.
- Navigate to Tags from the left-hand menu and click New.
- Give your Tag a descriptive name, such as “GA4 - Event - Social Share”.
- Click on Tag Configuration and select Google Analytics: GA4 Event.
- In the Configuration Tag field, select your main GA4 configuration tag. (If you don't have one, you'll need to create it first by pasting your GA4 Measurement ID).
- Under Event Name, type in a clear name for your event. Use snake_case format, like
social_share. This is the name you will see in your GA4 reports. - Next, we'll add Event Parameters to send more context with each share click. This is how we'll know which platform was used and what page was shared. Add two rows:
- Below the Tag Configuration, click on Triggering.
- Select the trigger you just created: “GA4 - Trigger - Social Share Click.”
- Click Save.
Finally, click the blue Submit button in the top right corner of GTM to publish your changes. Give your version a name (e.g., "Added Social Share Tracking") and click Publish.
Step 3: Test and Find Your Data in GA4
With everything published, it’s time to confirm your setup works. Open your website in one tab and the Realtime report in your GA4 property in another tab.
Click on one of your social share buttons. Within a minute or two, you should see the social_share event appear in the "Event count by Event name" card in the Realtime report. If you see it, congratulations! Your tracking is working.
Registering Custom Dimensions
For GA4 to let you properly use the share_platform and page_shared parameters in your reports, you need to register them as custom dimensions. This is a crucial one-time step.
- In GA4, go to Admin (the gear icon in the bottom-left).
- Under the Data display column, click Custom definitions.
- Click the Create custom dimensions button.
- First dimension:
- Click Save.
- Second dimension:
- Click Save.
It can take up to 48 hours for data to fully populate using these new dimensions. Once available, you can build explorations (in GA4, go to Explore > Free Form) using your social_share Event name and dragging your new "Share Platform" and "Page Shared" dimensions into the rows to see which content is resonating most and where.
Final Thoughts
Setting up social share tracking through Google Tag Manager gives you a much deeper understanding of audience engagement than looking at referral traffic alone. It moves beyond passive consumption metrics and reveals which pieces of your content actively inspire your readers to become promoters of your work.
Once you start collecting custom event data like this in Google Analytics, you can often find the GA4 reporting interface cumbersome for getting quick answers. We built Graphed to solve exactly this problem. By connecting your GA account, you can skip building complex reports and simply ask questions in plain English, like "What were my top 10 most shared pages last month?" or "Chart shares to Twitter vs LinkedIn for the quarter." We help you turn that hard-earned data into a clear answer in seconds, not hours.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.