Enabling click tracking on URLs other than the indexed live url

Managed by | Updated .

Funnelback's click tracking feature includes in-built security that prevents redirection to an arbitrary URL.  Click tracking, while not required, enables Funnelback to learn from user behaviour and modify result ranking.  Click tracking is also used for the top click reports within the analytics.

There are some valid situations where you wish to redirect to a URL that doesn't match the indexed URL for the document, but still capture the click.  This redirect could be to an external URL or a URL that is contained within a metadata field (eg. if the indexer has assigned internal URLs as occurs when indexing database content and some XML data).

This page describes how this redirection can be achieved with click tracking support.

Create a hook_post_datafetch.groovy hook script that modifies the live URL.  This modification must occur in post datafetch (not post process) because the click tracking link includes an encoded version of the live URL which is calculated after the post datafetch phase completes.

hook_post_datafetch.groovy
import java.net.URLEncoder;
if ( transaction.response != null
  && transaction.response.resultPacket != null) {
  transaction.response.resultPacket.results.each() {
     
    def parameter = ''
   
    if ( it.liveUrl.contains("?") ) {
      parameter = "&";
    } else {
      parameter = "?";
    }
     
    // In Groovy, "it" represents the item being iterated
    it.liveUrl = it.liveUrl + parameter + 'fb_keyword=' + URLEncoder.encode(transaction.question.query);       
  }
}
Was this artcle helpful?

Tags
Type: Keywords:
Features:
XML
Frontend > Modern UI Frontend > Hook scripts

Comments