How to track social media interactions with Google Tag Manager

Author:

Tracking social media interactions with Google Tag Manager (GTM) enables you to measure how users interact with your social media links and embedded social media content (like share buttons or embedded posts) on your website. While GTM doesn’t automatically capture social interactions, you can configure custom events to track clicks and interactions with social media elements. Here’s a guide to set up tracking for social media interactions with GTM:

1. Define the Social Media Interactions to Track

Identify which social interactions are most valuable to your business. Common interactions include:

  • Clicking on Social Media Icons or Links: Users clicking on icons to visit your social media profiles.
  • Using Social Share Buttons: Users clicking on buttons to share content on their social media accounts.
  • Interacting with Embedded Social Media Posts: Engaging with embedded posts, such as likes, shares, or comments.

Each type of interaction can be set up as a custom GTM trigger.

2. Set Up Link Click Tracking for Social Media Icons

For sites with links to social media profiles (e.g., Facebook, Instagram, Twitter), you can set up click tracking to capture when users visit your profiles from your website.

Step 1: Enable Click Variables in GTM

  1. Open Google Tag Manager:
    • Log in to GTM and go to your container.
  2. Enable Click Variables:
    • Navigate to Variables on the left menu.
    • Click Configure under Built-in Variables.
    • Enable the following click variables:
      • Click URL
      • Click Text
      • Click Classes
      • Click ID

These variables help identify the link clicked by capturing its URL, class, text, and other attributes.

Step 2: Create a Trigger for Social Media Link Clicks

  1. Create a New Trigger:
    • Go to Triggers and click New.
  2. Select Trigger Type:
    • Choose Just Links as the trigger type.
  3. Set Trigger Conditions:
    • In the Trigger Configuration pane, select Some Link Clicks.
    • Use conditions to specify the social media URLs (e.g., Click URL contains “facebook.com”, Click URL contains “instagram.com”).
  4. Save the Trigger:
    • Name it something like “Social Media Link Click Trigger” and save it.

Step 3: Create a Tag to Send Data to Google Analytics

  1. Create a New Tag:
    • Go to Tags and click New.
  2. Select Tag Type:
    • For Google Analytics 4, select GA4 Event.
    • For Universal Analytics, select Universal Analytics and set the Track Type to Event.
  3. Configure Event Parameters:
    • For GA4:
      • Event Name: “social_interaction”
      • Add Event Parameters:
        • social_network: Set to Click Text or a custom value like “Facebook”.
        • social_action: Use “click”.
        • social_target: Use Click URL.
    • For Universal Analytics:
      • Category: Social Media
      • Action: Click
      • Label: {{Click URL}} to capture the specific social media profile clicked.
  4. Add the Trigger:
    • Attach the “Social Media Link Click Trigger” you created.
  5. Save the Tag.

3. Tracking Social Share Button Clicks

If you have share buttons on your site, setting up event tracking for each button allows you to capture data on what content users are sharing and where. You can often differentiate share buttons by their Click ID or Click Classes.

Step 1: Create a Trigger for Share Buttons

  1. Create a New Trigger:
    • Go to Triggers and click New.
  2. Select Trigger Type:
    • Choose Click – All Elements if the share buttons don’t use links, or Just Links if they do.
  3. Set Trigger Conditions:
    • Use Click Classes or Click ID to target specific buttons. For example, if your Facebook share button has the class share-facebook, set the trigger condition as Click Classes contains “share-facebook”.
  4. Save the Trigger:
    • Name it something like “Social Share Button Click Trigger”.

Step 2: Create a Tag to Track Share Events

  1. Create a New Tag:
    • Go to Tags and click New.
  2. Configure Event Tag:
    • For GA4:
      • Event Name: “social_share”
      • Event Parameters:
        • social_network: Custom value like “Facebook” or “Twitter” (depending on the button clicked).
        • social_action: Use “share”.
        • social_target: The page URL shared (use {{Page URL}}).
    • For Universal Analytics:
      • Category: “Social Share”
      • Action: “share”
      • Label: {{Click Text}} or {{Page URL}} to capture the content being shared.
  3. Add the Trigger:
    • Attach the “Social Share Button Click Trigger”.
  4. Save the Tag.

4. Tracking Interactions with Embedded Social Media Posts

Tracking embedded social media interactions like “likes” or “comments” is more complex and may require custom JavaScript. Many embedded posts (like Facebook or Instagram) don’t natively support GTM tracking due to cross-domain restrictions.

Alternative Methods:

  • Use Facebook Pixel or Twitter Universal Tag: These allow you to track interactions with their content directly.
  • For YouTube video embeds, use GTM’s built-in YouTube Video Trigger for tracking video engagement (play, pause, complete, etc.).
  • Consult the developer documentation of each social media platform to see if they offer custom event listeners for embedded content.

5. Testing Social Media Interaction Tracking

Before publishing, test your setup to ensure each tag and trigger is working correctly.

  1. Enter Preview Mode:
    • In GTM, click Preview to open the debug console.
  2. Test Social Media Interactions:
    • Visit your site in the preview window and interact with social media links, share buttons, and embedded posts.
  3. Check the Debug Console:
    • Confirm that each interaction triggers the correct tags and events in the GTM debug console.
  4. Verify in Google Analytics:
    • After testing in GTM, check Google Analytics (under Events in GA4 or Real-Time > Events in UA) to ensure the data is recorded correctly.

6. Publishing and Monitoring Social Media Tracking

  1. Publish Changes:
    • When all tests are successful, publish the container by clicking Submit and Publish.
  2. Monitor Analytics Reports:
    • In Google Analytics, go to the Events section in GA4 or Behavior > Events in Universal Analytics to see data from social interactions. Analyze which platforms, content, and share buttons drive the most engagement.

Conclusion

With GTM, tracking social media interactions like profile visits, share button clicks, and embedded post engagements can provide valuable insights into user engagement with your brand’s social media presence. Although some interactions (like embedded post actions) require alternative approaches, GTM’s flexibility allows for effective tracking of most social media events. This data helps measure the impact of your social media presence on-site, refine your content strategy, and make data-driven decisions.