^ top ^


NAME

comscore.js - JavaScript foundation library for Tracking (Comscore) integration

^ top ^


SYNOPSIS

Automatic (synchronous) tracking:

   <script type="text/javascript">
      document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b";) + ".scorecardresearch.com/beacon.js'%3E%3C/script%3E"));
   </script>
   <script type="text/javascript">
      document.write(unescape("%3Cscript src='comscore.js'%3E%3C/script%3E"));
   </script>

Manual (asynchronous) tracking:

   <script type="text/javascript">
      document.write(unescape("%3Cscript src='comscore.js'%3E%3C/script%3E"));
   </script>
   <script type="text/javascript">
      Libero.getTracking({ callDirectly: 1 });
   <script>

^ top ^


DESCRIPTION

comscore.js is the minimal JavaScript foundation library for tracking (Comscore) calls made from header/footer packages. Note that each package contains comscore_<sitename>.js.

^ top ^


JavaScript API

comscore.js creates a global Libero object (if not already defined) with several properties and function.

Libero.Stash

Libero.Stash is an empty object intended for use by page JavaScript code.

Libero.getTracking( object ) (aka Libero.getComscore( object ))

This function does the tracking (Comscore) call.

Note that the the Libero.getComscore function has been renamed to Libero.getTracking. However, for backward compatibility, you can continue to use Libero.getComscore with the same API even if we suggest to change the name to the new one.

The function takes a single argument object object. Within object you could set following properties:

^ top ^


CGI API

The tracking (Comscore) calls behaviour could be also customized by setting an appropriate query string. In that case, the call will be always sychronous. The CGI parameters are:

All CGI paramenters must be URL-escaped. Moreover, the tracking (Comscore) call will start only if at least one of the cs_ajax, cs_path, cs_url or cs_cookie parameters has been defined on the query string

EXAMPLES

   http://mysite.libero.it/footer_on_iframe.html?cs_url=http%3A//mysite.libero.it&cs_test=1

^ top ^


Tracking code integration

Synchronous call (the standard way)

The easiest way to add tracking code is to include a code in your footer like following:

   <!--  Libero COMSCORE start - Version x.y.z -->
   <script type="text/javascript">
      document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b";) + ".scorecardresearch.com/beacon.js'%3E%3C/script%3E"));
   </script>
   <script type="text/javascript">
      document.write(unescape("%3Cscript src='js/comscore.js'%3E%3C/script%3E"));
   </script>
   <noscript>
      <img src="http://b.scorecardresearch.com/p?c1=2&amp;c2=13259779&amp;cj=1&amp;name=libero.others&amp;ns_site=libero"; />
   </noscript>
   <!-- Libero COMSCORE end -->

Please, include always the code provided in footer*.html files of header/footer distribution since the <noscript> section can differ from a site to another.

Note that if your site run under HTTPS protocol, the <noscript> section must changed in order to

   <noscript>
      <img src="https://sb.scorecardresearch.com/p?c1=2&amp;c2=13259779&amp;cj=1&amp;name=libero.others&amp;ns_site=libero" />
   </noscript>

Asynchronous call (AJAX applications)

In order to do tracking (Comscore) asynchronous calls (for example, from AJAX applications or any other situations that don't require the reload of the page), you should use Libero.getTracking() API.

Examples

The following code does a non-blocking JavaScript call, by using setTimeout:

   <script type="text/javascript">
      document.write(unescape("%3Cscript src='comscore.js'%3E%3C/script%3E"));
   </script>
   <script type="text/javascript">
      setTimeout('Libero.getTracking({ ajax: \'' + ajax_target + '\', callDirectly: 1 })',10)
   </script>

The following example does a non-blocking JavaScript call (by using setTimeout) on the another frame:

   <script type="text/javascript">
      document.write(unescape("%3Cscript src='comscore.js'%3E%3C/script%3E"));
   </script>
   <iframe border="0" style="display: block" width="100%" id="comscore" src="footer.html"></iframe>
   <script type="text/javascript">
      setTimeout('document.getElementById(\'comscore\').contentWindow.Libero.getTracking({ ajax: \'' + ajax_target + '\', callDirectly: 1})',10);
   </script>

Note that footer.html must include comcore.js and both page than iframe have to live under the same domain.

^ top ^


Customizing tracking calls

The tracking (Comoscore) call should be customized as follow.

Error pages

For error pages, before to load js/comscore.js, you must set libero_comscore_error JavaScript variable with the correspondent HTTP status code. Currently, only 4xx and 5xx values are allowed.

For example:

   <script type="text/javascript">
      var libero_comscore_error = 404;
   </script>

Test mode

For stage, development and pre-production sites, before to load js/comscore.js, you must set libero_comscore_test JavaScript variable as follow:

   <script type="text/javascript">
      var libero_comscore_test = 1;
   </script>

In that way, the tracking (Comscore) calls will be done with a special test account.

Using JavaScript API (Libero.getTracking) alternatively you must set test key with a true value.

Using the CGI API alternatively you must set cs_test parameter with a true value:

   cs_test=1

Note that js/comscore.js auto-detects test mode if the referer live under .st.libero.it and .pp.libero.it domain, even if libero_comscore_test hasn't been defined.

Debug mode

The debug mode allows to print with browser console.log() method (if defined) some useful informations. In order to enable debug mode, you could alternatively:

Note: Do not enable debug mode in any production site.

Adding custom labels to Comscore call

In order to add custom labels to Comscore call (that is, CGI parameters), you can alternatively:

Note that:

How to prevent multiple calls

Sometime can occurs that a site inserts the ``Comscore'' code several times. That means that tracking calls will be duplicate,

In order to enable check to prevent multiples comscore calls (synchronous mode), you can set libero_comscore_check_multiple_calls Javascript variable before loading js/comscore.js file:

   <script type="text/javascript">
      libero_comscore_check_multiple_calls = 1;
   </script>

libero_comscore_check_multiple_calls will set to maximum calls allowed from the same page (that is, without reload and/or frame/iframe).

You can use alternatively check_multiple_calls argument in Libero.getTracking() asynchronous call.

^ top ^


SEE ALSO

^ top ^


AUTHOR

Enrico Sorcinelli <enrico.sorcinelli [at] staff.libero.it>

^ top ^


BUGS

Send bug reports and comments to: <enrico.sorcinelli [at] staff.libero.it>. In each report please include also the API version module, the browser name and version and your SO.

^ top ^


COPYRIGHT AND LICENSE

Copyright (C) 2012 by Libero S.r.l.

^ top ^