Was this article helpful?

socialize.addEventHandlers

Last modified 11:38, 15 Sep 2014

Description

The Gigya service generates several global application events for various situations that are driven by user interactions.
Global application events are fired whenever the event to which they refer occurs, regardless of what was the action that triggered the event.
This is in contrast to plugin events, which are only fired by the specific plugin on which they were configured.
This method allows setting event handlers for each of the supported global events.
To learn more about how to handle events generated by Gigya, please refer to the Events page in the Developer's Guide.

 

The following is a list of available global application events:

  • onLogin - Fired whenever a user successfully logs in to Gigya. This may happen, for example, as a result of using the socialize.showLoginUI method.
  • onLogout - Fired whenever a user logs out of Gigya, using the socialize.logout call.
  • onConnectionAdded - Fired whenever a user is connected to a provider?. This may happen, for example, as a result of calling one of the following methods: socialize.addConnection, socialize.showAddConnectionsUI, socialize.showEditConnectionsUI.
  • onConnectionRemoved - Fired whenever a user is disconnected from a provider. As above, this event will be fired regardless of the action that triggered it.

 

An Event Handler is a JavaScript function with the following signature:

functionName(eventObj)

The single argument eventObj, contains information about the event and has different data fields for different events. In "Event Handlers - eventObj event data" below, you will find the specification of the available fields in the eventObj for each event.

 

Note: several social & sharing plugins may generate these global events. You may identify the source of the event using the 'source' field in the returned event data. Read more in the events' data reference below.
Please note that the plugins may trigger onConnectionAdded or onLogin depending on the connectWithoutLoginBehavior parameter of the global configuration object. Read more in the Using Plugins to Initiate Site Login guide.

 

Syntax

gigya.socialize.addEventHandlers(params)

 

Method Parameters

The following table lists the params object members:

Required Name Type Description
Optional onLogin function A reference to a function that is called when the user is successfully authenticated by Gigya.
  onLogout function A reference to a function that is called when the user has logged out.
  onConnectionAdded function A reference to a function that is called when the user is successfully connected to a provider.
  onConnectionRemoved function A reference to a function that is called when the user disconnects from a provider.
  callback function A reference to a callback function. Gigya calls the specified function along with the results of the API method when the API method completes.
The callback function should be defined with the following signature: functionName(response).
The "Response object Data Members" table below provides specification of the data that is passed to the callback function.
  cid string A string of maximum 100 characters length. The CID sets categories for transactions that can be used later for filtering reports generated by Gigya in the "Context ID" combo box. The CID allows you to associate the report information with your own internal data. For example, to identify a specific widget or page on your site/application. You should not define more than 100 different context IDs.
Note: the value of this parameter overrides the value of the identical parameter in the global configuration object.
  context object A developer-created object that is passed back unchanged to the application as one of the fields in the response object.

 

Response Object Data Members

Field Type Description
errorCode integer The result code of the operation. Code '0' indicates success, any other number indicates failure. For a complete list of error codes, see the Error Codes table.
errorMessage string A short textual description of an error associated with the errorCode for logging purposes.
operation string The name of the API method that generated this response.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.

 

Event Handlers - eventObj Event Data

The following tables specify the list of available data fields in the eventObj for each event.

onLogin Event Data

Field Type Description
eventName string The name of the event: 'login'.
source string The source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showLoginUI'.
Note: this field will not be available if the source of this event is not a plugin (e.g. if the source is a socialize.login API call).
context object The context object passed as a parameter to the plugin/method that triggered this event, or null if no object was passed.
loginMode string The type of login:
  • standard - the user is logging into an existing account.
  • reAuth -  the user is proving ownership of an account by logging into it.
provider string The name of the provider that the user used in order to login (e.g. "Facebook"). Note: If this event is fired as a result of a socialize.notifyLogin call, i.e. the user was authenticated by your site, the provider field will be set to "site".
signatureTimestamp  string The GMT time of the response in UNIX time format (i.e. the number of seconds since Jan. 1st 1970). The time stamp should be used for login verification, as described under the Validate the UID Signature in the Social Sign-On Process section.
UID string The User ID that should be used for login verification*.
Note: The UID string must be encoded using the encodeURIComponent() function before sending it from your client to your server.
UIDSignature  string The signature that should be used for login verification, as described under the Validate the UID Signature in the Social Sign-On Process section.
user User object User object with updated information for the current user.
signature  string Deprecated. Please use the UIDSignature parameter instead.
timestamp  string Deprecated. Please use the signatureTimestampparameter instead.
This parameter holds the GMT time of the response in "yyyy-mm-dd HH:mm:ss" format where HH is in 24 hour time format.
* To learn more about login verification, please refer to the Validate the UID Signature in the Social Sign-On Process section in the Security page of the Developer's Guide.

onLogout Event Data

Field Type Description
eventName string The name of the event: 'logout'.
context object The context object passed as a parameter to the plugin/method that triggered this event, or null if no object was passed.

  

onConnectionAdded Event Data

Field Type Description
eventName string The name of the event: 'connectionAdded'.
source string The source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showCommentsUI', 'showChatUI', etc.
Note: this field will not be available if the source of this event is not a plugin (e.g. if the source is a socialize.addConnection API call)
context object The context object passed as a parameter to the plugin/method that triggered this event, or null if no object was passed.
user User object A User object with updated information for the current user.
provider string The name of the social network to which the user connected.

 

onConnectionRemoved Event Data

Field Type Description
eventName string The name of the event: 'connectionRemoved'.
source string The source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showEditConnectionsUI'.
Note: this field will not be available if the source of this event is not a plugin (e.g. if the source is a socialize.removeConnection API call)
context object The context object passed as a parameter to the plugin/method that triggered this event, or null if no object was passed.
user User object User object with updated information for the current user.
provider string The name of the social network from which the user disconnected.

  

Code Sample

function DisplayEventMessage(eventObj) {
    alert(eventObj.eventName + " event happened");
}
 
gigya.socialize.addEventHandlers({ 
    onLogin:DisplayEventMessage,
    onConnectionAdded:DisplayEventMessage,
    onConnectionRemoved:DisplayEventMessage
   }
);

Notes:
  • This sample is not meant to be fully functional code. For brevity's sake, only the code required for demonstrating the API call itself is presented.
  • To run the code on your own domain, add your Gigya API key to the socialize.js URL. A Gigya API key can be obtained on the Site Dashboard page on Gigya's website. Please make sure that the domain from which you are loading the page is the same domain name that you used for generating the API key.
  • In some cases it is necessary to connect/login the user to a provider? prior to calling the API method. You can learn more in the Social Login guide.

Was this article helpful?
Pages that link here
Page statistics
14 view(s) and 1 edit(s)
Social share
Share this page?

Tags

This page has no custom tags set.

Comments

You must to post a comment.

Attachments