Gigya Job Openings

accounts.getCounters JS

Skip to end of metadata
Go to start of metadata

 

Description

This method retrieves the real-time value of one or more counters for the current user (see Signals for information). Note that counter data is not retrievable until 1-24 hours after it is recorded.

Note: This method is also supported in our REST API. If you wish to execute this method from your server, please refer to

REST API > accounts.getCounters.

 
 

Syntax

 

 

Parameters

The following table lists the available parameters:

RequiredNameTypeDescription
countersarray of objectsAn array of counter objects, each object has the following fields:
  • class -  the type of action that is counted. May be specified as a regular experssion in the format: regex('').
  • path -  an optional path to return. If not specified then all paths of the class are returned. May be an exact path or regex :
    • A specific path (e.g. “/sport”).
    • A regular expression, same format as given in the schema, e.g. “regex('/.*/cbs')”.
  • period  - optional aggregation period to return. The default is total.
    The possible values are:
    • total
    • YYMM
    • YYMMDD
    • last7Days
    • A regular expression, e.g., to get all monthly counters in 2013, regex(‘^13..$’).
callbackfunction
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.
cidstring
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: This parameter overrides the value of the identical parameter in Global Conf (the global configuration object). If the parameter is not set for the method, the value from Global Conf is used.

contextobject
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

FieldTypeDescription
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 Response Codes and Errors table.
errorMessage string A short textual description of an error associated with the errorCode for logging purposes.
callId string Unique identifier of the transaction, for debugging purposes.
context object The context object passed by the application as a parameter to the API method, or null if no context object has been passed.
countersarray of objectsAn array of counter objects, each object has the following fields:
  • class -  the type of action that is counted, e.g. "shares".
  • path - a path that provides an extra classification for the action, e.g. "/news/sport".
  • period - specifies the period of time for which the counters are returned. The possible values are: “total”, “YYMM”, “YYMMDD”, or “last7Days”.
  • value - a value for the count.
  • count - the count for this class and path.

 

Example of a call to accounts.getCounters

The following code registers an event handler for a connection to a social network, the data passed back by the event handler will include the User Object for the user.

The user ID for the user is retrieved from the user object and then used to call accounts.getCounters to retrieve the current counters for this user.

The code displays the counters' contents on the screen.

 

<html>
<head>
<!-- Including the gigya.js script: -->
<script type="text/javascript" src="http://cdn.gigya.com/JS/gigya.js?apikey=<your API key here>" ></script>
<script type="text/javascript">
      //<!--This function is called by the event handler-->
       function cbUserInfo(userinfo) {
           //<!--The UID is a required parameter for the call to accounts.getCounters-->
           gigya.accounts.getCounters(userinfo.UID, { callback: ckresponse });    
            }
       </script>
 <script>
      function ckresponse(info2) {
          //<!--loop reading each counter class-->
           for (var i = 0; i < info2.counters.length; i++) {
               var counter2 = info2.counters[i];
               alert("counter: " + counter2.class + " path: " + counter2.path + " period: " + counter2.period + " value: " + counter2.value + " count: " + counter2.count);
                       }         };
      </script>
</head>
<body>
 <!-- Basic Gigya's Social Login integration -->   
    Please Login using one of the following Social Networks:   
    <div id="loginDiv"></div>   
    <script type="text/javascript">
        //<!-- register the onLogin event which when fired will call "cbUserInfo" function with the user's data.-->
        gigya.socialize.addEventHandlers({ onLogin: cbUserInfo });
        //<!-- display the login plugin -->
        gigya.socialize.showLoginUI({ containerID: 'loginDiv', enabledProviders: "facebook,yahoo,linkedin", showTermsLink: false, height: 50 });
        </script>
</body>
</html>