Integrate Provided Functions To HTML Document - AFS

AFS Integration Guide

Reference Guide

Here is a quick integration code of AFS click web service. These following two functions must be loaded into pages in which they have to be called. For that there are several solutions:

  • Creating a JavaScript file that is dedicated to this code. It is not advised for performances purposes (loading a file through HTTP is quite expensive)
  • Inserting this code inside your Javascript code or directly in a <script> element
  • Integrating this code into your files that are compressed and obfuscated

* @param clickPath must be the path at which the click web service can be reached.
* "/click" will be appended to this parameter Example:
* @param serviceId AFS Service id
* @param status AFS Service status
* @param target Clicked URL
* @param label Label
* @param sessionId Optional, AFS Search session id
* @param userId Optional, AFS Search user id
function notifyClick(clickPath, serviceId, status, target, label, sessionId, userId)
var url = clickPath + 'click?afs%3Aservice=' + serviceId + '&afs%3Astatus=' +
status + '&afs%3Atarget=' + encodeURI(target) + '&afs%3Alabel=' +
encodeURI(label) + '&afs%3Aaction=log';
if (sessionId)
url += '&afs%3AsessionId=' + encodeURI(sessionId);
if (userId)
url += '&afs%3AuserId=' + encodeURI(userId);

* Executes an HTTP GET method to the given URL. It supports requesting any host name
* (uses a work around for the Same Origin Policy). This method is not able to return
* the response body.
* @param url The target URL
function executeGetRequest(url)
var iframe = document.createElement('iframe'); = 'none';
iframe.setAttribute('src', url);

There are two functions. The first one is the one to call, the second one is just for implementation purposes.

This function supports cross domain requesting, it requires to know the following values:

  • AFS service ID and AFS service status
  • Click web service host. For instance
  • Click web service path. If click is at the web server's root, value is /
  • Click target: URL of the search result that is going to be clicked
  • Click label: Title of the search result

Two additional parameters are optional: AFS sessionId and userId. They enable AFS click to track search sessions (see Identification of search sessions and unique visitors). Their values are generated by AFS web services.

This code has been tested and works on most popular browsers such as Firefox, Chrome, Safari, Opera, Internet explorer 7, 8, 9.