Enabling Analytics


This section describes how to add SearchStax® Analytics from Measured Search® to your existing website.

To set up tracking, you need to have access to the source code for your website. It is expected that you have access to the website's HTML and JavaScript, and that you understand how your search results are displayed.

Create App

You must create an Analytics "App" for your SearchStax deployment.

Screenshot

To create an Analytics App, please: Click on Analytics from the main menu. Click on the Create App Button. * Enter a descriptive name for your new app and click the Create button.

After the application is created, you will see a new application with a key.

Connect Your Website to the App

Your search website communicates to the Analytics App through a javascript function on the web page.

Include Tracking Script

Add the following script before the ending body tag in your search-results page. You will have to replace the variables shown in UPPERCASE LETTERS with dynamic values available on the search results page. Note that only 'key' and 'query' attributes are required; everything else is optional. Just remove the lines that you don’t have dynamic values for. However, the more you can add, the better insights you’ll get from the Dashboard.

<script type="text/javascript"> 
var _msq = _msq || []; //declare object

(function() { var ms = document.createElement('script'); ms.type = 'text/javascript'; ms.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'searchstax.measuredsearch.com/static/js/ms2.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ms, s); })(); 
</script>

Tracking Searches

When your web page submits a query, have it send this message to the Analytics App:

_msq.push(['track', {
    key: 'REPLACE_WITH_APP_KEY',
    user: 'REPLACE_WITH_UID',
    session: 'REPLACE_WITH_SESSION_ID',
    query: 'REPLACE_WITH_QUERY',
    shownHits: 'REPLACE_WITH_SHOWN_HITS',
    totalHits: 'REPLACE_WITH_TOTAL_HITS',
    latency: 'REPLACE_WITH_LATENCY',
    pageNo: 'REPLACE_WITH_PAGE_NUMBER'
}]);

Below is an example of how the script looks like once you’ve substituted the UPPERCASE LETTERS with real values.

_msq.push(['track', { 
   key: "4Qp1Sv9MnALbAGbixW9ZaWrHxpbfwm6i", 
   user: "foobar123", 
   session: "XDJFNS355FGDFVVDFG", 
   query: "Steve Jobs – San Francisco, CA", 
   shownHits: 10, 
   totalHits: 1890, 
   latency: 150, 
   pageNo: 1 
}]);

Tracking Clicks

In order to start generating data around click-through, search quality & relevance, we need to track clicks on your site. In your search results page, replace the link to every search result with the following.

<a onClick="_msq.push(['trackClick', { 
    session: 'REPLACE_WITH_SESSION_ID',
    key: 'REPLACE_WITH_APP_KEY',
    query: 'REPLACE_WITH_QUERY',
    cDocId: 'REPLACE_WITH_DOCUMENT_ID',
    cDocTitle: 'REPLACE_WITH_DOCUMENT_TITLE'
    position: 'REPLACE_WITH_RESULT_POSITION',
    pageNo: 'REPLACE_WITH_PAGE_NUMBER',
    pageUrl: 'REPLACE_WITH_PAGE_URL',
    showHits: 'REPLACE_WITH_SHOWN_HITS',
    totalHits: 'REPLACE_WITH_TOTAL_HITS',
    lat: 'REPLACE_WITH_SEARCH_LATITUDE',
    lon: 'REPLACE_WITH_SEARCH_LONGITUDE',
    user_lat: 'REPLACE_WITH_USER_LATITUDE',
    user_lon: 'REPLACE_WITH_USER_LONGITUDE'        
}]);" href="REPLACE WITH LINK URL">REPLACE WITH LINK TITLE</a>

Below is an example of how the script looks like once you’ve substituted the UPPERCASE LETTERS with real values.

<a onClick="_msq.push(['trackClick', { 
   session: "XDJFNS355FGDFVVDFG", 
   key: '4Qp1Sv9MnALbAGbixW9ZaWrHxpbfwm6i', 
   query: 'Steve Jobs', 
   position: 4, 
   cDocId: 'http://mycompany.com/steve-jobs/', 
   cDocTitle: Steve Jobs', 
   pageNo: 1, 
   shownHits: 10, 
   totalHits: 1890
   lat: '33.916',
   lon: '-118.404',
   user_lat: '33.916',
   user_lon: '-118.404'        
 }]);" href="'http://mycompany.com/steve-jobs/">Steve Jobs</a>

Tracking Shopping Cart Additions

This is the format for logging shopping cart additions with the Analytics App:

<a onClick="_msq.push(['addToCart', { 
    category: 'REPLACE_WITH_PRODUCT_CATEGORY',
    id: 'REPLACE_WITH_ITEM_ID_OR_SKU',
    sku: 'REPLACE_WITH_ITEM_SKU',
    name: 'REPLACE_WITH_ITEM_NAME',
    key: 'REPLACE_WITH_APP_KEY',
    pageUrl: 'REPLACE_WITH_ITEM_URL',
    price: 'REPLACE_WITH_ITEM_PRICE',
    quantity: 'REPLACE_WITH_ITEM_QUANTITY',
    session: 'REPLACE_WITH_SESSION_ID',
    user: 'REPLACE_WITH_UID'   
}]);" href="'http://mycompany.com/cart/">Add to cart</a>

Tracking Transactions

When the user commits to a purchase, send this massage to the Analytics App:

_msq.push(['addTransaction', { 
    category: 'REPLACE_WITH_PRODUCT_CATEGORY',
    id: 'REPLACE_WITH_ITEM_ID_OR_SKU',
    sku: 'REPLACE_WITH_ITEM_SKU',
    name: 'REPLACE_WITH_ITEM_NAME',
    key: 'REPLACE_WITH_APP_KEY',
    pageUrl: 'REPLACE_WITH_ITEM_URL',
    price: 'REPLACE_WITH_ITEM_PRICE',
    quantity: 'REPLACE_WITH_ITEM_QUANTITY',
    session: 'REPLACE_WITH_SESSION_ID',
    user: 'REPLACE_WITH_UID'   
}]);

Tracking Feedback

SearchStax Analytics provides a mechanism for keeping track of user feedback about individual result items. On your search-results page you can approve/disapprove icons under each result. SearchStax will collect and keep track of clicks on these icons.

<a onClick="_msq.push(['trackFeedback', {
    key: 'REPLACE_WITH_APP_KEY',
    query: 'REPLACE_WITH_QUERY',
    cDocId: 'REPLACE_WITH_DOCUMENT_ID',
    cDocTitle: 'REPLACE_WITH_DOCUMENT_TITLE'
    position: 'REPLACE_WITH_RESULT_POSITION',
    pageNo: 'REPLACE_WITH_PAGE_NUMBER',
    pageUrl: 'REPLACE_WITH_PAGE_URL',
    showHits: 'REPLACE_WITH_SHOWN_HITS',
    totalHits: 'REPLACE_WITH_TOTAL_HITS',
    user: 'REPLACE_WITH_UID',
    session: 'REPLACE_WITH_SESSION_ID',
    'relevant': 'REPLACE_WITH_RELEVANCY',
}]);" href="REPLACE WITH LINK URL">REPLACE WITH LINK TITLE</a>

where relevant can be 1 or 0 (1 == relevant, 0 == not relevant).