Was this article helpful?

Automatic Sharing

Last modified 05:33, 13 May 2014

Gigya offers an option to activate an automatic share per user and per predefined type of activity in your site.
Automatic share means that each time the user does the same type of activity in your site, his action will automatically be shared on pre-selected social networks, without prompting the Share plugin. Obviously, automatic share activation must receive the user's permission. In addition, you can give the user an option to choose to "Never share this", meaning never prompt the Share plugin on a certain type of activity in the site.

 

How it Works

The feature is enabled through the addition of two optional UI elements to the Share plugin (you may add each one independently):

  • "Always share" checkbox
  • The "Never share" link

ShareUI_Auto.gif

These two UI elements are enabled and customized through the use of showShareUI's auto share related parameters. This is broadly explained and demonstrated below.

If the user checks the "Always share" checkbox and presses "Publish", Gigya will turn on the automatic share for this user. Each time this user repeats the same type of activity (i.e. publish, comment, rate, reply, like, etc.), Gigya will automatically share the action without prompting the user with the Share plugin. The type of activity  is predefined (read more about the autoShareActionID parameter below). The action will be shared on the social networks that the user selected when he checked the checkbox and pressed "Publish". If a network is no longer connected, the share will fail without notifying the user. If all the social networks originally selected are now disconnected, the "Always share" property for this user and activity is reset and the Share plugin is prompted.

If the user clicks the "Never share" link, the Share plugin will close and Gigya will never prompt the Share plugin when this user repeats the same type of activity.

 

Adding the "Always share" Checkbox

To add the "Always share" checkbox, two additional parameters are required:

  • showAlwaysShare - set this parameter with one of the following values:
    • 'checked' - the "Always share" checkbox is displayed and checked by default.
    • 'unchecked' - the "Always share" checkbox is displayed and unchecked by default.
  • autoShareActionID - set this parameter with a unique identifier, specifying the type of activity that the user has performed on your site. For example: "Commented", "Rated", "Replied", "Liked", "Published" etc. The user selection (Always/Never Share) will apply only to this ID.

For example:

var params = {
    userAction: act  // The UserAction object enfolding the newsfeed data.
    ,showAlwaysShare: 'unchecked'
    ,autoShareActionID: 'Like'
};
gigya.socialize.showShareUI(params); // Activate the Share plugin

See complete Running Example below.

 

Adding the "Never share" Link

To add the "Never share" link, two additional parameters are required:

  • showNeverShare - set this parameter to true.
  • autoShareActionID - set this parameter with a unique identifier, specifying the type of activity that the user has performed on your site. For example: "Commented", "Rated", "Replied", "Liked", "Published" etc. The user selection (Always/Never Share) will apply only to this ID.

For example:

var params = {
    userAction: act  // The UserAction object enfolding the newsfeed data.
    ,showNeverShare:true
    ,autoShareActionID: 'Like'
};
gigya.socialize.showShareUI(params); // Activate the Share plugin

See a complete Running Example below.

 

Running Example

Here is a running example of the Share plugin with both "Always Share" and "Never Share" enabled:

 

The Example Code

<html>
<head>
    <style>
	 body {font-family:Arial;font-size: 12px; background-color:#fff; line-height:20px}
	</style>
	<SCRIPT type="text/javascript" lang="javascript" 
	   src="http://cdn.gigya.com/JS/socialize.js?apikey=2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N">
	   {
		cid: "Share Example page"
	   }
	</SCRIPT>
	<script>
	 
       
    </script>
    <script type="text/javascript">

        // Create and Publish User's Action
        // This method is associated with the "btnShare" click
        function showShareUI() {

		    // Constructing a UserAction Object
		    var act = new gigya.socialize.UserAction();

			// Adding a Link Back
			act.setLinkBack("http://www.gigya.com/site/content/socialize.aspx");

			// Setting the Title
			act.setTitle("This is my title");

			// Setting the Description
			act.setDescription("This is my Description");

			// Adding a Media (image)
			act.addMediaItem({
			    src: 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1',
			    previewImageURL: 'http://graphics8.nytimes.com/images/2006/01/02/science/03cute.large2.jpg',
			    type: 'flash'
			 });
			 
			// Parameters for the showShareUI method, including the UserAction object
			var params = 
			{
			    userAction: act  // The UserAction object enfolding the newsfeed data.
				,showAlwaysShare: 'unchecked' // display the "Always share" checkbox. The checkbox will be unchecked on load
				,showNeverShare:true   // display the "Never share" link. 
				,autoShareActionID: 'SharedVideo'  // The activity type ID is "SharedVideo". user selection will apply to this activity ID only
				//,autoShareActionDisplay:'videos'    // optional - change the default text
			    ,onError: onError  // onError method will be summoned if an error occurs.
			};
			 
			// Activate the Share Plugin
			gigya.socialize.showShareUI(params);
		}
		
		// onError event handler
		function onError(event) {
		    alert('An error has occured' + ': ' + event.status + '; ' + event.statusMessage);
		}

    </script>

</head>
<body>
    <h4>Please click the button below to open the "Share" dialog:</h4>
    <input type=button id="btnShare" onclick="javascript:showShareUI()" value="Share" />
    <div id="status"></div>
</body>
</html>

 

Additional Customizations

There are two more parameters in the auto share related parameters group for customizing this feature:

  • autoShareExpiration - gives you the ability to define expiration time to the user selection. The default is never expire.
  • autoShareActionDisplay - gives you the option to change the default text next to the "Always share" checkbox and the "Never share" link. The autoShareActionDisplay string will be appended to the "Always share" and "Never share" strings, i.e. "Always share XXX" and "Never share XXX" where XXX is the autoShareActionDisplay string. The default value of autoShareActionDisplay is the string "this".  Note: this field can be no longer than 12 characters.

 

Accessing User Settings in Gigya's Database

The user's selections of always/never share per activity type are stored in Gigya's database. Gigya offers direct access to the user settings, allowing retrieving, storing and deleting settings. Following are the API methods for accessing user settings:

JavaScript API:

REST API:

 

Each of these methods receive two parameters:

  • group - user settings have group classification. The group ID identifies a set of settings as related to each other. By default the group identifier is empty. For the "always/never share" settings we have defined the following group identifier: 'gigyaShareSettings'.
  • settings - A JSON object containing [name: value] pairs of the settings to set for the current user.

For auto share the settings object will look similar to this:

{"activityID1":{"actionID":"activityID1","alwaysShare":true,"neverShare":false,"providers":"linkedin"},
"activityID2":{"actionID":"activityID2","alwaysShare":false,"neverShare":true}}

Where the keys are the activity IDs (i.e. "Commented", "Rated", "Replied", "Liked", "Published" etc.), and the values are JSON objects containing the user's selections corresponding to the activity ID.

 

Running Example

Here is a running example that uses the getUserSettings and delUserSettings:

 

The Example Code

???<html>
<head>
    <style>
	 body {font-family:Arial;font-size: 12px; background-color:#fff; line-height:20px}
	</style>
	<SCRIPT type="text/javascript" lang="javascript" 
	   src="http://cdn.gigya.com/JS/socialize.js?apikey=2_Y82PzwJ_chSFImHXaIDJClnLyJzmk-VFOavSsaNTzl6m901s_NNxRAS0xJ3bd3_N">
	</SCRIPT>
    <script type="text/javascript">
       var response = { errorCode: errorCode, errorMessage: errorMessage, operation: operation, context: context, settings: settings };
        // This method is associated with the "btnGet" click
        function getUserSettings() {
            // Parameters for the getUserSettings method

            var params =
			{
			    callback: printGetResponse,
			    group: 'gigyaShareSettings'
			};

            // Activate the Share Plugin
            gigya.socialize.getUserSettings(params);
        }

        function printGetResponse(response) {
            
            if (response.errorCode == 0) {
                var settings = JSON.stringify(response.settings);
                alert("The current user's settings are: " + settings);
            }
            else {
                alert('Error :' + response.errorMessage);
            }
        }

        // This method is associated with the "btnDel" click
        function delUserSettings() {

            // Parameters for the delUserSettings method
            var params =
			{
			    callback: printDelResponse,
			    group: 'gigyaShareSettings'

			};

            // Activate the Share Plugin
            gigya.socialize.delUserSettings(params);
        }

        function printDelResponse(response) {
            if (response.errorCode == 0) {
                alert("The current user's settings are deleted");
            }
            else {
                alert('Error :' + response.errorMessage);
            }
        }


    </script>

</head>
<body>
    <h4>Please, click the button below to Get/Delete User Settings from Gigya DB</h4>
    <input type=button id="btnGet" onclick="javascript: getUserSettings()" value="Get User Settings" />
    <input type=button id="btnDel" onclick="javascript: delUserSettings()" value="Delete User Settings" />
</body>
</html>

A Complete Demo

To have a good demonstration of the whole feature, follow these steps:

  1. Go to the second Running Example (get/del settings)
    Press the "Get User Settings button. You should see a dialog showing an empty JSON object (no settings).
  2. Go to the first Running Example above (with the Share plugin).
    1. Click the "Share" button. The Share plugin should open.
    2. Select one or more social networks.
    3. Check the "Always share this" check box.
    4. Click the "Publish" button.
    5. Check to see the published newsfeed in the relevant social networks.
    6. Click the "Share" button again. This time the Share plugin shouldn't open.
    7. Check to see a new automatically published newsfeed in the same social networks.
  3. Go to the second Running Example (get/del settings)
    1. Press the "Get User Settings" button. You should see a dialog showing a JSON object containing the settings that were created due to your previous picks in the Share plugin. The object should look similar to this:
      {"SharedVideo":{"actionID":"SharedVideo","alwaysShare":true,"neverShare":false,"providers":"linkedin,facebook"}}
      Where:
      "SharedVideo" is the activity ID we gave in the first running example (line 53:   autoShareActionID: 'SharedVideo').
      "alwaysShare" is true since you have checked the "Always share this" check box.
      "providers":"linkedin,facebook" list of social networks that you have selected.
    2. Press the "Del User Settings" button. The settings should now be deleted.
    3. Press the "Get User Settings button. You should see a dialog showing an empty JSON object (no settings).
  4. Go to the first Running Example above (with the Share plugin). Click the "Share" button. Since you have deleted the settings, the Share plugin should open again.
Was this article helpful?
Pages that link here
Page statistics
4992 view(s) and 7 edit(s)
Social share
Share this page?

Tags

This page has no custom tags set.

Comments

You must to post a comment.

Attachments