Cardinal Path’s response to COVID-19 Cardinal Path is sharing all we know to help marketers during COVID-19.  Learn more.
This article assumes a working knowledge of Google Tag Manager tags, triggers, variables, and data layer. To learn more about these subjects, see the GTM course at Google Analytics Academy.

If you work in more of a marketing/analytics role, you can read through the post for the key takeaways and then review the implementation procedures with your developers.

Social interactions that occur on your website clearly indicate a high level of user engagement, so there is no question that we need to track social interactions. More specifically, the questions are:

  • What functionality do Google Analytics and the social networks provide to facilitate social tracking?
  • How can I track different kinds of social actions?

To help us structure our social tracking approach, we can break out three even more specific considerations, which we list below and then discuss in greater detail.

  • connect or content: am I tracking social connect/follow interactions or likes/shares of my content?
  • event or social hit: will I track the social interactions as Google Analytics events or Google Analytics social hits?
  • click or callback: is there a callback available for the social action, or do I need record the social action at the time of the click?

1 – Connect or Content

First and foremost, we need clearly recognize the difference between the two different types of social interactions:

  • social connect actions: connects, likes or follows on your organization’s social profiles
  • social content actions: votes, likes, shares, or tweets for your website content

Below we’ll see how we can distinguish between these two different types of social actions. (Note the two likes above – they don’t mean the same thing.)

2 – Event or Social Hit

Event and virtual pageview tracking is a critical concept in Google Analytics, since it allows us to track a wide range of user interactions that do not cause a page to load and do not therefore generate a pageview hit by default. (Events also play a central role in app tracking.)

You can opt to track your social actions as events. For instance, you can track a clickthrough from your website to your Facebook page using the Google Tag Manager tag and trigger shown below.

Google Analytics tag in Google Tag Manager configured to record an event for a clickthrough to your organization’s Facebook page.

Facebook Event

This trigger fires specifically when your website visitor clicks through to your organization’s Facebook page.

Facebook trigger

For each of your social connect links, you could create a tag and trigger similar to those above. As Track Type is specified as Event, the resulting hits will appear within the Events reports.

Social Hit

While we may be used to working with Google Analytics pageviews and events, there is a lesser known social hit type that specifically populates the Social > Plugins report. With the Track Type of a GA tag in GTM set to Social as shown below, Google Analytics records a social hit.

The tag below is the equivalent of the event tag above, but it specifies the Track Type as Social.

Facebook Social Tracking

You could apply the same trigger to this social tag as to the event since, since the same conditions should prompt either to fire.

With the track type set to Social, the resulting hit will appear in the Social > Plugins report that appears below rather than in the Events reports.

What about the social content actions? Should we track those as events or as social hits?

You could also track your social content actions either as events or as social hits, but you may want to opt for social hits instead of events in this case, if only for the reason that Google +1 content actions are automatically tracked as social hits (with callback) in Google Analytics, so it’s probably best to keep all of your social content actions tracked as social hits in the Social > Plugins report (unless you need to track these action as goals).

If you do opt to track all of your social connect and social content actions as social hits, you can populate easily distinguishable social actions as in the table below.

If you track all social actions as social hits, you can populate the social action parameter to clearly distinguish between social connect actions and social content actions.

Social NetworkConnect ActionContent Action
Google Plusplus-one-or-circle+1 (automatic)

3 – Click or Callback for Social Content Actions

The event and social hit tracking that we have discussed so far is based on an assumption: that the user will complete the actual connect or content action after the clickthrough. We must tolerate this uncertainty for social connect actions, because there is not a feasible way to verify that the user has completed the action before you generate an event or a social hit.

Like and Tweet

For some of our social content actions – specifically on Facebook and Twitter – we can use callback listeners to confirm the completion of the action before we send data to Google Analytics (or otherwise respond to the completed action).

Stated more simply, the callback waits till the user logs into the social network and completes the social action – only then does the callback function execute. (As a note, the callback could correspond to any function; we’re just using it for Google Analytics tracking in our case.)

This Facebook callback listener (which we set on every page once the DOM loads) will wait till the user has completed the content like action before it executes the callback function.

Facebook Callback

Keep in mind that Facebook like callback is available for like content but not like Facebook page.

Facebook Send

Callback is also available for the less common Facebook Send button. You can implement Send callback the same way as like; you’d just need to replace egde.create with message.send in the tag shown above. (You could maintain both callback listners on the same page.) For the full range of Facebook callback listeners, see Facebook developer documentation.

Callback is not available for Facebook Share, but we can still track Share actions immediately on click as described below.

Using the code below, you can set up a similar callback tag for tweets in Google Tag Manager.

//assumes you have initialized window.twttr as part of the standard code for displaying the tweet button
if (typeof twttr !== 'undefined') { 
  twttr.ready(function (twttr) {'click', trackTwitter);  
function trackTwitter() {
          'event': 'socialTrigger', 
          'socialNetwork': 'Twitter', 
          'socialAction': 'tweet', 
          'socialTarget': window.location.href

Note that in the two social content actions above, we’re populating the data layer with 1) the values that we’ll read into the GTM social tag using data layer variables as shown below and 2) the event value that we’ll use for the tag’s Custom Event trigger. Note also that the social target parameter is optional for a Google Analytics social hit, but we’re populating it with the current URL, which is the default in any case.

This Google Tag Manager tag reads the social values from the data layer using Data Layer variables. The trigger for this tag is the population of the socialTrigger event value into the data layer. (We could have used any value for this variable; we’d just need to configure the Custom Event trigger to match.)

Social tag using data layer variables

You can apply this trigger to the tag above. When the socialTrigger event value is pushed into the data layer, the trigger will fire the tag.

Custom Event trigger

What do we do when no callback is available?


Callback is not available for LinkedIn or Pinterest, but we can still populate the data layer with the social hit values (and the event value for the Custom Event trigger) as shown below as soon as the associated link is clicked (and assume that the user logs into the social network and completes the action, as we do for the social connect clicks).

    'event': 'socialTrigger', 
    'socialNetwork': 'LinkedIn', 
    'socialAction': 'share', 
    'socialTarget': window.location.href

For our LinkedIn click trigger, we can inspect the HTML for the LinkedIn button:

<a id="li_ui_li_gen_1439046400859_0-link" href="void(0);">

We can then apply a click trigger based on the id attribute value of the <a> tag as shown below.

You can apply this trigger, based on the id attribute of the LinkedIn share link, to the tag above to populate the data layer when the link is clicked.

Click trigger


We can similarly populate the data layer with social values when a visitors clicks a Pinterest PinIt button. If we inspect the HTML of the PinIt, we see that we’ll just need to define our trigger as Click Classes contains pin_it_button and not by link ID.

<a data-pin-href="" data-pin-log="button_pinit_bookmarklet" class="PIN_1439052112077_pin_it_button_28 PIN_1439052112077_pin_it_button_en_28_red PIN_1439052112077_pin_it_button_inline_28 PIN_1439052112077_pin_it_none_28" data-pin-config="none"><span class="PIN_1439052112077_hidden" id="PIN_1439052112077_pin_count_0"><i></i></span></a>

Facebook Share

As mentioned above, Facebook Share does not offer a callback. We can instead push event data to the data layer immediately on click as with LinkedIn and Pinterest. However, we won’t be able to depend on the HTML id and class attributes, since these attributes are identical for the Facebook Like and Share button span tags as shown below:

<span class="pluginButtonLabel">Like</span>
<span class="pluginButtonLabel">Share</span> 

Instead, we can create a DOM Element variable as shown below that returns the text of these spans, which will thereby allow us to create a trigger for Share only.

The popup help confirms that the CSS selector in this DOM Element variable will return the text of the matched element, which will allow us to distinguish Facebook Like from Share buttons.

CSS Selector variable

This trigger uses the variable shown above to identify the Facebook Share button specifically.

Trigger based on CSS Selector variable

Social Plugins Report

All social connect and social content actions that we record as social hits (as opposed to events) will appear in the Social > Plugins report as shown below. In the report, note that Social Source corresponds to the social network value that we populated, and Social Entity corresponds to the social target value that we populated (or the current page of the action if not specified).

Actions recorded as a social hit (i.e., with Track Type set to Social in the Google Analytics tag) appear in the Social Plugins report.

Social Plugins report

Can I create goals from social actions?

If you have tracked social actions as events, you can create goals for them just as you can for any other event, but no goal setup available for social dimensions or metrics. If it’s critical that you track your social actions as goals, you can opt to track them as events (except for G+ content +1 action, which are automatically tracked as social hits, but for which you could also generate an event on click).

Social Widgets

Some social content widgets such as ShareThis or WordPress plugins such as Sharrre add social sharing buttons to your Web pages and integrate with Google Analytics. (ShareThis populates social sharing data into the Events reports, while Sharrre populates Social Plugins). If you opt for a social widget instead of adding social buttons manually, review documentation and speak with support to verify that the widget integrates smoothly with Google Analytics.

Plan Your Social Tracking

Social tracking is somewhat more complex than some of our other Google Analytics implementation tasks, but if you review the considerations above and implement accordingly, you’ll soon enjoy greater insight into social interactions on your website.


State of Digital Marketing Analytics

The 2020 State of Digital Marketing Analytics examines the marketing technology that supports the world's most successful enterprises and highlights the challenges and strategies for navigating the new normal..