How to track custom social share buttons with google analytics?

Member

by dortha , in category: SEO Tools , 2 months ago

How to track custom social share buttons with google analytics?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by annabell_mcdermott , 2 months ago

@dortha 

To track custom social share buttons with Google Analytics, you will need to set up event tracking for each button. Here's how you can do it:

  1. Add tracking code to the social share buttons: Add onclick event handlers to your social share buttons that call a function to send data to Google Analytics. For example, you can add the following code to each button:
1
<button onclick="trackSocialShare('Facebook')">Share on Facebook</button>


  1. Create a function to send event data to Google Analytics: Create a function in your JavaScript code that sends event data to Google Analytics. This function should use the ga() function provided by Google Analytics to send the event data. Here's an example of the function:
1
2
3
function trackSocialShare(network) {
  ga('send', 'event', 'Social Share', 'click', network);
}


  1. Set up event tracking in Google Analytics: In your Google Analytics account, go to the "Admin" section and navigate to the property where you want to track the social share button events. Go to the "Goals" section and click on "New Goal" to create a new goal for tracking social share button clicks. Set the goal type to "Event" and define the event conditions to match the category, action, and label you set in the trackSocialShare() function.
  2. Test the tracking: Add the tracking code to the social share buttons on your website and test the buttons to make sure that the events are being tracked correctly in Google Analytics. You can use the Real-Time reporting section in Google Analytics to see if the events are being recorded in real-time.


By following these steps, you can track custom social share buttons with Google Analytics and gain valuable insights into how users are sharing your content on social media.