@ra5mus/eb-comscore

1.0.1 • Public • Published

eb-comscore

How to interact with Comscore

These are the main steps to perform:

1. (mandatory) Initialize and configure comscore on page load.

Normally this is done via the <ebComscore:init /> taglib, which add a number of common parameters to the ebComscore object, including comscoreId, comscoreSite, comscoreVsite, comscoreSubVsite and comscoreString. Alternatively, call ebComscore.initializeComscore() and supply the needed parameters.

2. (optional) Track page view Often done via the <ebComscore:trackPageView /> taglib function, which generates both javascript and a <noscript><img> for browsers with javascript disabled. Alternatively, call ebComscore.sendComscorePageview() directly, and remember to handle browsers with javascript disabled.

3. (optional) Track event Can be done via the <ebComscore:jsForTrackingEvent /> taglib function, which generates javascript to put in ex. an onclick/onsubmit event handler. Alternatively, call one of the comscoreEvent() or ebComscore.sendComscoreNonPageview() javascript functions directly. Both options offer the opportunity to send along custom parameters to comscore.

4. (mandatory) Include comscore js before </body>

Normally this is done via the <ebComscore:bottom /> taglig, right before the end </body> tag. Alternatively, manually include http://b.scorecardresearch.com/c2/16785783/cs.js at the end of the body.

Javascript cheat-sheet

Refer to the source for more information. This is just a short sample

<!-- include javascript -->
<script src="http://ekstrabladet.dk/template/v5-6/shared/js/modules/comscore/comscore.js" type="text/javascript" />
<script src="http://ekstrabladet.dk/template/v5-6/shared/js/modules/comscore/ecommerce.js" type="text/javascript" />

<script>
  // initialize comscore on each page within the <head> section
  ebComscore.initializeComscore('16785783', 'jppol', 'ebmedier', 'ekstrabladet', { key1: 'val1', key2: 'val2' });
</script>

<script>
  // track page view. Normally, you should supply values for le_type, le_name and le_label as parameters
  ebComscore.sendComscorePageview({ name: 'myname', category: 'mycat', key3: 'val3', key4: 'val4' });
</script>

<!-- track deferred event (inpage=false). Useful for events involving page navigation on mobile browsers. -->
<!-- Normally you should supply values for le_type, le_name and le_label. -->
<a onclick="comscoreEvent(event, this, { name: 'myname', category: 'mycat', key5: 'val5' }, false);">my trigger</a>

<!-- track event immidiately (inpage=true). Does usually not work on mobile browsers when navigating -->
<!-- Normally you should supply values for le_type, le_name and le_label. -->
<a onclick="comscoreEvent(event, this, { name: 'myname', category: 'mycat', key5: 'val5' }, true);">my trigger</a>
<form onsubmit="comscoreEvent(event, this, { name: 'myname', category: 'mycat', key6: 'val6' }, true);"></form>

<script>

  // track event immediately. Alternative to the above.
  // Normally you should supply values for le_type, le_name and le_label.
  ebComscore.sendComscoreNonPageview({ name: 'myname', category: 'mycat', key7: 'val7', key8: 'val8' });

  // Create the order object, and initialize it with the base url (created by initializeComscore), customer ID and unique order ID
  var eComOrder = new ns_order(ebComscore.comscoreBaseUrl() + ebComscore.comscoreString, userId, orderId);
  // Add a line to the order, with the required fields
  eComOrder.addLine(productId, brandName, productGroup, shopName, 1, 0.00);
  // Send the order info to comscore
  eComOrder.sendOrder();

</script>

Package Sidebar

Install

npm i @ra5mus/eb-comscore

Weekly Downloads

0

Version

1.0.1

License

ISC

Last publish

Collaborators

  • ra5mus