Time needed: 5 minutes
Tracking user clicks on the socialized share buttons is easy with Google Tag Manager (GTM), all you need is a variable, trigger, and a tag.
- Create the custom variable
Create a new variable called “Social Sharing Platform” with the variable type
Data Layer Variable
Set the “Data Layer Variable Name” togtm.element.dataset.platform
Optionally, you can check the box to “Set Default Value” and leave it blank.
Save the variable. - Create the Trigger
Create a new trigger named “Share on Social Media” with the trigger type
Click - Just Links
Check the radio button for “Some Link Clicks” and chooseClick Classes
contains
socialized-link
Save the trigger. - Create the Google Analytics 4 Tag
Create a new tag named “Share on Social Media” with the tag type “Google Analytics: GA4 Event”
Set the “Event Name” toshare
Create a new row under “Event Parameters” with the “Parameter Name” set tosocial_media_platform
and the “Value” set to{{Social Sharing Platform}}
Add your website’s configuration tag.
Set the firing triggers to the “Share on Social Media” trigger you made in step 2.
Save the tag. - Test & Publish
Preview your updates in GTM. With the GTM debugger, click on any of the sharing icons and check that your new tag fired when clicked.