HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Track clicks

Describes how to track clicks to generate useful recommendations.

If the user clicks on a Product Recommendations item, the click must be tracked to generate useful recommendations. Two JavaScript functions are available to achieve this.

  • Peerius.smartRecsClick(id) must be called when a product recommendation is clicked and the click takes the customer to a new page.
  • Peerius.smartRecsSendClick(id) should be called if the user stays on the same page following the click. (smartRecsSendClick(id) sends the click to our servers via a background request).

Usage of smartRecsClick(id) is demonstrated in the example below:

window.PeeriusCallbacks=
      {
        // utility function to create the html code of a product
        // using jquery.
        product:function(json) 
          {
            var title=json.title
            var h="<p>"+title+"</p>"
            h+="<a href='"+json.url+"'>"
            h+="<img src='"+json.img+"'/>"
            h+="</a>"
            var p=$('<div>').html(h)
            p.click(function()
              {
                // extra care to be taken so that the correct recommendation
                // id is used (for reporting purposes)!
                Peerius.smartRecsClick(json.id)
              })return p
          },
          // implementation of the Peerius callback
          smartRecs:function(jsonArray) 
            {
              $('<div id="jsonRecs">').html("JSON recommendations").appendTo('.body-content-div')
              for(i in jsonArray)
                {
                  var widget=jsonArray[i]
                  for(j in widget)
                    {
                      var json=widget.recs[j]
                      var p=this.product(json)
                      p.appendTo('#jsonRecs')
                    }
                }
            }
      }