Enhancements to the Classroom Share Button

December 16, 2015


Link copied to clipboard

Originally posted on Google Apps Developer Blog

Posted by Andrew Garrett, Software Engineer, Classroom API and Michael Stillwell, Developer Advocate, Google Apps

By popular developer request, the Classroom Share Button now supports JavaScript callbacks and a question post type (in addition to announcements and assignments).

The following callbacks are supported:

  • onsharestart is called immediately after the user clicks the share button
  • onsharecomplete is called after the user successfully shares the URL to their class

The callbacks are supported by both the share tag and the JavaScript API, and they work on all supported browsers except Internet Explorer.

What can you use this for? There's a bunch of different things you can do, but to get you started, here are some suggestions:

  • Analytics and reporting How frequently is the share button used? What's the most frequently shared URL across the site?
  • Shared URL history Store the list of URLs a user has shared, to provide a customized and more engaging site.
  • Contextual help The first time a user shares a link back to your site, explain what happened and what they should expect to see next.
  • A/B testing Are many users starting a share action, but failing to finish?

Finally, if you want to fully control 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/

As ever, please continue asking questions (or answering them!) on StackOverflow (use the google-classroom tag) and report bugs and feature requests via the Classroom API bug tracker.