Social sharing JavaScript API events

šŸ“˜

The content on this page deals with a legacy feature of the ā€‹Akamaiā€‹ Identity Cloud (in this case, social sharing). If you are currently an Identity Cloud customer and are using social sharing, that feature is still supported. However, if youā€™re new to the Identity Cloud, social sharing is no longer available.


The Social Sharing solution supports client-side handling of a number of events. These are useful for customizing the user experience or tracking user behavior with a third-party analytics tool.

To handle events generated by Social Sharing, register your event handlers using the janrain.social method within the janrainSocialOnLoad function. Each of the following events has on and off methods that may be used to register callback functions.

<script type="text/javascript">
     functionjanrainSocialOnLoad(){
   janrain.social.on({
       provider\_select:function(data){
     console.log("Clicked on provider "+ data.provider);
   },
  auth\_done:function(data){
  console.log("Authorized for provider "+ data.provider);
  },
 share\_done:function(data){
 console.log("Sharing completed for provider "+ data.provider);
 }
 });
}
</script>

Event methods

Each event method will accept anĀ eventNameĀ toĀ callbackĀ mapping. See theĀ Event ResponsesĀ section for the data that will be available for the callback function to handle.


.on(eventName, callback)

This method will register aĀ callbackĀ for the specifiedĀ eventName. It will accept one event per call. Example:

<script type="text/javascript">
 functionjanrainSocialOnLoad(){
 janrain.social.on("share\_done",function(data){
 console.log("Sharing completed for provider "+ data.provider);
 });
 }
</script>

If you have multiple instances of Social Sharing on a single page, you can specify an individual instance by passing in the instanceā€™s HTML ID in the form ofĀ eventName:instanceId. Example:

<script type="text/javascript">
 functionjanrainSocialOnLoad(){
 janrain.social.on("share\_done:shareInstance1",function(data){
 console.log("Sharing completed for provider "+ data.provider);
 });
 }
</script>

.on(eventNameToCallbackMapping)

If you have multiple events you want to call, you can pass them into the same method inside of an object withĀ eventName:callbackĀ pairs. The following examples are equivalent:

<script type="text/javascript">
 functionjanrainSocialOnLoad(){
 janrain.social.on({
 provider\_select:function(data){
 console.log("Clicked on provider "+ data.provider);
 },
 share\_done:function(data){
 console.log("Sharing completed for provider "+ data.provider);
 }
 });
 }
</script>
<script type="text/javascript">
 functionjanrainSocialOnLoad(){
 janrain.social.on("provider\_select",function(data){
 console.log("Clicked on provider "+ data.provider);
 });
 janrain.social.on("share\_done",function(data){
 console.log("Sharing completed for provider "+ data.provider);
 });
 }
</script>

.off(eventName, callback)

This method will remove aĀ callbackĀ from the specifiedĀ eventName. It will accept one event per call.

<script type="text/javascript">
 janrain.social.off("share\_done",shareCompleteCallback);
</script>

auth_done

Type:Ā Share Authorization

Fired when a user authorizes a provider for sharing.


auth_fail

Type:Ā Share Activity

Fired when a user fails to authorize a provider for sharing.



provider_select

Type:Ā Share Activity

Fired when a user clicks on a provider icon.


share_done

Type:Ā Share Authorization

Fired when a user successfully completes sharing. For broadcast sharing, the share will occur immediately after the user authorizes a provider for sharing and theĀ auth_doneĀ event fires.


share_fail

Type:Ā Share Activity

Fired when the user cancels sharing or there was an error.


share_start

Type:Ā Share Activity

Fired when a user clicks on theĀ Share button.


Event responses

Depending on the event type, different information is passed to the event handler function.


Share activity

These types of events contain the HTML ID of the share tool that was used, the name of the social identity provider used for authentication, and the sharing mode (email,Ā contact, orĀ broadcast). Example event:

{
    "id": "shareInstance1",
    "provider": "facebook",
    "mode": "broadcast"
}

Share authorization

These types of events contain the HTML ID of the share tool that was used, the name of the social identity provider used for authentication, the sharing mode (email,Ā contact, orĀ broadcast), and an authentication token from the social provider. Example event:

{
    "id": "shareInstance2",
    "provider": "facebook",
    "mode": "broadcast",
    "auth\_token": "ab12cd34ef56gh78ij90kl12mn34op56qr78st78"
}