How to track social media interactions with Google Tag Manager

Author:

Tracking social media interactions with Google Tag Manager (GTM) is essential for understanding how users are engaging with social media links and content on your website. By monitoring interactions such as clicks on social sharing buttons, social media follow buttons, and embedded social media content (like Facebook posts or Twitter feeds), you can gain insights into user behavior, content performance, and the effectiveness of social media marketing efforts. Here’s how to set up social media interaction tracking using Google Tag Manager.

Step 1: Determine What Social Media Interactions You Want to Track

Before setting up tracking, identify the specific social media interactions that are important to your business. Some common interactions include:

  1. Clicking on social media sharing buttons (e.g., Facebook, Twitter, LinkedIn, Pinterest)
  2. Clicking on social media follow buttons (e.g., Instagram, Twitter follow buttons)
  3. Interacting with embedded social media content (e.g., liking or commenting on embedded Instagram or Facebook posts)
  4. Social media referral traffic (e.g., tracking when users come to your site from a specific social media platform)

Step 2: Create a Social Media Trigger for Button Clicks

For tracking social media interactions like clicks on social media buttons (e.g., sharing or following), the first step is to set up a trigger in GTM that listens for these events.

  1. Log into Google Tag Manager and open the container for your website.
  2. Go to the “Triggers” Section:
    • In the left menu, click on Triggers.
    • Click on New to create a new trigger.
  3. Choose “Click – Just Links” as Trigger Type:
    • Select Click as the trigger type and choose Just Links.
    • This will allow GTM to track click events on anchor tags (links) like social media buttons.
  4. Configure the Trigger:
    • Under Trigger Configuration, select Some Link Clicks.
    • Define the condition based on the social media links. For example:
      • If you are tracking clicks on Facebook, set the condition to Page URL contains facebook.com.
      • For Twitter, use Page URL contains twitter.com.
      • You can use other link attributes such as Click URL if social media links are in specific elements or have distinct classes/IDs.
      • For example, the condition could be: Click URL contains facebook.com (or the relevant social media domain).
  5. Save the Trigger:
    • Once you’ve configured the trigger for social media clicks, click Save.

Step 3: Set Up a Tag to Track Social Media Interactions

Next, create a tag in GTM to send the data about the social media interaction to your analytics tool (such as Google Analytics).

  1. Go to the “Tags” Section:
    • In GTM, click on Tags in the left menu and click New to create a new tag.
  2. Select the Tag Type:
    • If you’re using Google Analytics (Universal Analytics), choose Google Analytics: Universal Analytics.
    • If you’re using Google Analytics 4 (GA4), choose Google Analytics: GA4 Event.
  3. Configure the Tag:
    • For Universal Analytics:
      • Set the Track Type to Event.
      • For Category, use something like Social Media.
      • For Action, use a variable like {{Click URL}} (this captures the URL of the social media link that was clicked).
      • For Label, use a variable like {{Page URL}} to capture the page on which the social media interaction occurred.
      • For Value, you can leave it empty or assign a value based on the type of interaction (e.g., if a user clicked a “Follow” button).
    • For GA4:
      • Set the Event Name to something descriptive, such as social_media_click.
      • Add event parameters:
        • platform: {{Click URL}} (this captures the specific social media link).
        • page_url: {{Page URL}} (this captures the page where the interaction happened).
        • event_action: You can use click or another custom value based on your needs.
  4. Set the Trigger for the Tag:
    • Select the trigger you created earlier (e.g., Click – Facebook Link, Click – Twitter Link).
  5. Save the Tag:
    • Once the tag is configured, click Save.

Step 4: Track Social Media Interactions with Embedded Content

For tracking interactions with embedded social media content, such as liking or commenting on Facebook posts or Instagram embeds, you can use a similar approach, but there may be additional steps depending on the platform. Many embedded social media posts (such as Facebook or Instagram embeds) use custom HTML elements, and you may need to listen for interactions with these elements.

Example: Tracking Facebook Embedded Post Interactions

  1. Create a Trigger for Interactions with Embedded Content:
    • Go to the Triggers section in GTM and create a new trigger for Click or Custom Event.
    • For example, use a Click trigger that listens for clicks on elements with a specific class (e.g., .fb-post for Facebook posts).
  2. Set up a Tag to Track the Interaction:
    • Create a tag for Google Analytics or Google Tag Manager.
    • Track the interaction using event parameters like Category (e.g., Embedded Social Content), Action (e.g., Like), and Label (e.g., Post ID or URL).

Step 5: Track Social Media Referral Traffic

If you want to track when users arrive on your site from social media platforms (e.g., Facebook, Twitter), you can use Google Analytics to track source/medium or create a custom dimension in GTM.

  1. Create a Trigger for Social Media Traffic:
    • Create a trigger based on Page View with a condition for Referrer URL or Source.
    • For example, use a condition like Referrer URL contains facebook.com or Referrer URL contains twitter.com.
  2. Create a Tag to Track Referrals:
    • Create a tag in GTM that sends referral data to Google Analytics.
    • You can set the Source and Medium in the event or pageview tag, for example, Source = Facebook, Medium = social.

Step 6: Test Your Setup in GTM Preview Mode

Before making your changes live, always test your triggers and tags in GTM’s preview mode.

  1. Enter GTM Preview Mode:
    • In GTM, click on Preview and enter your website’s URL to start testing.
  2. Test Social Media Clicks:
    • Click on social media buttons on your website (Facebook, Twitter, LinkedIn, etc.).
    • Check if the tags are firing correctly by opening the GTM Preview panel.
  3. Check in Google Analytics:
    • For Google Analytics, check Real-Time > Events or Acquisition > All Traffic for social media events and referrals.

Step 7: Publish Your Changes

Once you’ve tested and confirmed that the tags are firing correctly, publish your GTM container to make the changes live.

Best Practices for Social Media Interaction Tracking

  • Set up specific goals: Align your social media tracking with specific business goals, such as increasing social media shares or driving traffic from social media platforms.
  • Track engagement: For platforms like Instagram, Facebook, and Twitter, tracking comments, likes, and shares can provide valuable insights into user engagement.
  • Use UTM parameters: For social media referral traffic, use UTM parameters to identify where users are coming from and the effectiveness of each campaign.

Conclusion

By setting up social media interaction tracking with Google Tag Manager, you can gain deeper insights into how users engage with your social media content and how social media drives traffic to your website. Whether it’s clicks on social media sharing buttons, embedded content interactions, or social media referrals, GTM makes it easy to track and analyze these interactions. With this data, you can optimize your social media strategy and make data-driven decisions to improve your marketing efforts.