How I Use GTM to Track Social Media Outbound Link Clicks

How I Use GTM to Track Social Media Outbound Link Clicks


While setting up GTM to track social media outbound clicks on my website using Google Analytics 4 (GA4), I encountered a few unexpected challenges. Tracking icon-based links — like those leading to Facebook or Instagram — wasn’t as straightforward as I thought. In this post, I’ll walk through what worked, what didn’t, and how I eventually set up a reliable solution using Google Tag Manager.

The Goal

I wanted to track when users clicked on outbound social media links like Facebook, Instagram, or YouTube from my website — even if the links were just icons without any visible text.

The purpose:

  • Send click events to GA4
  • Analyze which social platforms users interact with
  • Use that data for remarketing or engagement optimization

What Didn’t Work Initially

I started with a Just Links Click Trigger in GTM and thought I could filter by Click Text, expecting it to return values like “Facebook” or “Instagram”.

But in the preview/debug mode, the Click Text value was showing as:

auto-event variable → undefined

That’s because most social media icons are set up like this:

<a href="https://facebook.com/myprofile">
  <img src="facebook-icon.png" alt="Facebook">
</a>

Since there’s no plain text inside the <a> tag, Click Text returns nothing — meaning my trigger condition failed.

The Solution That Worked

After testing different variables, I realized that the most reliable method is to track by Click URL. Here’s the setup that worked:

Step 1: Enable Built-in Click Variables

In GTM:

  • Go to Variables
  • Click Configure
  • Enable all click-related variables:
    • Click URL
    • Click Text
    • Click Classes
    • Click ID
    • Click Element

Step 2: Create a Trigger

Create a new Click – Just Links trigger:

Choose: Some Link Clicks

Add conditions using Click URL:

Click URL contains facebook.com
OR
Click URL contains instagram.com
OR
Click URL contains youtube.com

Step 3: Create a GA4 Event Tag

  1. Add a new GA4 Event tag
  2. Choose your GA4 Configuration Tag
  3. Event name: social_click
  4. Add parameters for more detail:
platform = {{Click URL}}
link_text = {{Click Text}}
link_class = {{Click Classes}}

Step 4: Test in Preview Mode

Use GTM’s Preview mode:

  • Click on your social icons
  • Make sure the trigger fires
  • Check if the event appears in GA4’s Realtime reports under social_click

Bonus: Use Click Classes or IDs


If your links include consistent class or id attributes, you can build more specific trigger conditions:

<a href="https://facebook.com" class="social-link facebook-icon">
  <img src="fb.png">
</a>

In that case, trigger condition can be:

Click Classes contains facebook-icon

Summary

MethodProsCons
Click TextHuman-readable❌ Fails if there’s no text
Click URL✅ Reliable, universalMay include extra query strings
Click Classes / IDGood for structured markupRequires consistent HTML
Click Element (custom JS)PowerfulMore advanced setup needed

Final Thoughts

If you’re trying to track outbound social media link clicks using GTM and run into problems with Click Text showing undefined, don’t worry — you’re not alone. The most stable way is to filter clicks using Click URL, optionally combined with Click Classes or Click ID.

This approach is now live on my site and working perfectly. I hope this post saves you the trial-and-error I went through!

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *