Was this article helpful?

socialize.showRatingUI

Modified 12:05, 11 Apr 2013 by Tanya

Description

Displays a Rating plugin. The plugin presents the average rating of an item and a link to show all the reviews.

Note: If you plan on integrating the Rating plugin, we highly recommend reading the Rating & Reviews page, which is a step-by-step guide for integrating Gigya's Rating & Reviews platform in your site, including the Rating plugin.

 

Plugin's Default Design

The following screen shot presents a Rating plugin:

RatingUI-withComments.gif

The design is fully customizable via HTML Elements Style (CSS).

 

Syntax

gigya.socialize.showRatingUI(params)

 

Method Parameters

The following table lists the params object members:

   

Required Name Type Description
Required containerID string An ID of a <DIV> element on the page in which you want to display the plugin.
  categoryID integer The identifier of the Comments Category with which this plugin is associated.
Before embedding a Rating plugin in your site, you are required to create at least one Comments Category in the Comments Setup page on Gigya's website, and assign to it 'Operation mode: Rating & Reviews'. When creating a new Comments Category, a unique categoryID is created. The generated 'Embed code' includes the categoryID. You can use this code to embed the plugin in your site.
  streamID string In each category you may define multiple streams. Set this parameter with a unique ID of your choice to identify a stream. Note: the string is limited to 150 characters and is case sensitive.
Optional linkedCommentsUI string The containerID (<DIV> ID) of a Comments plugin that resides on the same page. This will be used to jump to the appropriate section in the comments plugin when the user clicks the # reviews link or the "Write your review" button.
  replyUserAction userAction object When a user posts a review, the post may be published to one or more social networks. Using this parameter you may customize the feed published to the social networks. The default values of the replyUserAction fields (if not overridden) are:
  • User Message - "" (empty)
  • Title - "My Review on: " page title
  • Link Back - the URL of page where the commenting stream is located
  • Description - the comment text
  showReadReviewsLink Boolean Indicates whether the "Read reviews" link is displayed in the plugin. The default value is 'true'.
  showCommentButton Boolean Indicates whether the "Write your review" button is displayed in the plugin. The default value is 'true'.
  context object A reference to a developer created object that will be passed back unchanged to the event handlers as one of the fields of the eventObj (see extended explanation in the "Plugin Events" section below).
  actionAttributes JSON object In Gamification your users receive points for actions they perform on your site, in this case adding a rating grants the user points. Action Attributes may be used to annotate actions with additional information, such as the section of the web site that generated the action. If you set here the actionAttributes, each time a user adds a rating, the action also receives an attribute, for example "tv-show":"glee", which can mean that the action was performed on the "Glee" page of the site. 

These action attributes are later used to display the GM Plugins filtered according to a certain attribute. For example, you can show the Leaderboard plugin only for top users on the "Glee" page.

This parameter receives a JSON object, comprised of a set or sets of a key (category) and a value or values, i.e.:
    {
        "<attribute1 name>": ["<attribute1 value1>", "<attribute1 value2>", ...],
        "<attribute2 name>": "<attribute2 value>",
        ...
    }
For example:
    {

        "tv-show": ["glee", "30rock"],
        "music": "pop"
    }
In this example the action receives three attributes: {"tv-show":"glee"}, {"tv-show":"30rock"}, and {"music":"pop"}. This parameter may receive a list of up to three sets of key and value entries per call. If more values are entered, only the first three will count and the rest will be ignored. The three sets of key and value can be one key with three values, or three keys with one value each, or two keys, one with two values and the other with one value. 
You can also choose to input attributes using a generic "Tags" key, with no category name, for example: {"tags": ["glee", "house", "pop"]}. In this case the action receives these three attributes: {"tags":"glee"}, {"tags":"house"}, and {"tags":"pop"}.

  ratingTemplate string (HTML) Using this parameter you may override the default design of the Rating plugin. Defines an HTML template representing the design of the Rating plugin. The HTML template supports the following placeholders: $stars, $readReviewsLink, $addReviewButton.
 Events Registration Parameters  
  onLoad function ref A reference to an event handler function that will be called when the plugin has finished drawing itself.
  onError function ref A reference to an event handler function that will be called when an error occurs.
  onAddReviewClicked function ref A reference to an event handler function that will be called when the "Write your review" button clicks.
  onReadReviewsClicked function ref A reference to an event handler function that will be called when the # reviews link clicks.
 

Plugin Events

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 fields for different events.

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

 

onLoad Event Data

Field Type Description
eventName string The name of the event.
sourcestringThe source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showLoginUI', 'showCommentsUI', etc.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.

 

onError Event Data

Field Type Description
eventName string The name of the event.
sourcestringThe source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showLoginUI', 'showCommentsUI', etc.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.
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.
errorDetails string This field will contain the exception info, if available.

 

onAddReviewClicked Event DataEdit section

Field Type Description
eventName string The name of the event.
sourcestringThe source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showLoginUI', 'showCommentsUI', etc.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.

 

onReadReviewsClicked Event Data

Field Type Description
eventName string The name of the event.
sourcestringThe source plugin that generated this event. The value of this field is the name of the plugin's API method, e.g. 'showLoginUI', 'showCommentsUI', etc.
context object The context object passed by the application as parameter to the API method, or null if no context object has been passed.

 

Please refer to the Events page in the Developer Guide, to learn more about how to handle events generated by the Gigya service.

 

Code Sample

var params=
{
	categoryID: 'Rating1',  
	streamID: 'RatingStream1',
        containerID: 'ratingDiv'
};

gigya.socialize.showRatingUI(params)

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 the Rating & Reviews demo you will find a complete working example that uses the socialize.showRatingUI method. You may view the code, run it and view the outcome.

Tags

This page has no custom tags set.

Comments

You must to post a comment.

Attachments