0

I recently added the Google Classroom share button to my website. I'm looking to fire off a Google Analytics event every time this share button is clicked. I've tried using a javascript onClick to do it, but that didn't work. I think it might be because this creates an iframe when rendered by the browser.

$('#___sharetoclassroom_0').on('click', function(e) {
    ga('send', 'event', 'gClassroom', 'gClassroom Click', 'Google Classroom Clicked');
}

I then saw the "data-onsharestart" attribute I can add to the Google Classroom tag and tried using that. That didn't work either...

<g:sharetoclassroom url="URL" data-onsharestart="gClassroomCount" size="20"></g:sharetoclassroom>

function gClassroomCount() {
    ga('send', 'event', 'gClassroom', 'gClassroom Click', 'Google Classroom Clicked');
}

Any ideas on how I could add this event to the Google Classroom Share button?

Mark
  • 1

1 Answers1

0

You should try to use the debug version of the analytics.js library, that logs detailed messages to the Javascript console as it's running. These messages include successfully executed commands as well as warnings and error messages that can tell you when your tracking code is set up incorrectly. It also provides a breakdown of each hit sent to Google Analytics, so you can see exactly what data is being tracked.

Based from the blog, if you want a full control of the appearance and behavior of the share button (and don't need the callbacks), you can customize the Classroom icon as long as it still meets our branding guidelines and initiate the share via a URL of the form: https://classroom.google.com/share?url=https://foo.com/

You can also check this related SO question, hope it helps!

Community
  • 1
  • 1
adjuremods
  • 2,938
  • 2
  • 12
  • 17