Contextual Targeting

How it works

A new mediarithmics JS Tag has been created for enabling Contextual Targeting on your website(s). The tag is imported in a JavaScript snippet that needs to be executed on all the pages you wish contextual targeting to be performed.
The code of the contextual targeting snippet is non-blocking - it does not impact on the page rendering time. The snippet can be inserted in the <head> part of the web page.
Contextual Targeting does not require any consent. We do not store nor use any data from users targeted using contextual and not giving their consent.
Contextual targeting JS Tag does not work as of now on Single Page Application. Please reach out to your Account manager if you need to integrate contextual targeting on a SPA.


  • The Panel-based Contextual Targeting feature should be activated on your organisation(s) by your Account manager. This will allow you to configure contextual targeting on your segments and update the JS Tag with them.
  • Real-time web apps tracking should be set up on your site, and events should be triggered to live ingest data for consenting users.


Schema update

You need to update your runtime schema to add the following line in UserEvent type:
contextual_key:String @TreeIndex(index:"USER_INDEX")
Contextual Targeting only works as of now with standard schema. Please reach out to your Account manager if you do not have UserEvent type in your schema.

Activity analyzer

You need to create an instance of contextual-targeting-event-analyzer-plugin in order to capitalize on data ingested with the regular mediarithmics JS Tag. Don't hesitate to contact us if you want more information about how this data is used.
You can configure a blacklist url & blacklist regexp files to filter out web pages where you do not want contextual targeting to be performed.
Blacklist url - Add a URL to blacklist per line:
Blacklist regexp - Add a regexp to blacklist per line:
You can use any javascript regexp in this file.

Snippet installation

You need to add a new mediarithmics snippet dedicated to contextual targeting on every page where you want contexutal targeting to be performed. The mediarithmics contextual targeting snippet is made of two parts:
  1. 1.
    The configuration that you should fill according to your context (site token & snippet name)
  2. 2.
    A technical tag which contains the JavaScript code which asynchronously load the TAG in the page. This part should not be edited.
Here is an example of the tracking snippet you should implement:
<script type="text/javascript">
const siteToken = "<SITE_TOKEN>" // token to change
const snippetName = "ctMics" // snippet name that can be changed
!function(e,t,s,i){"use strict";var a=e.ctscimhtiraidem||{};var r="call".split(" ");a._queue=a._queue||{},a._names=a._names||[],a._names.push(s),a._queue[s]=a._queue[s]||[],a._startTime=(new Date).getTime(),a._snippetVersion="ct-1.0";for(var n=0;n<r.length;n++)!function(e){var t=a[s]||{};(a[s]=t)[e]||(t[e]=function(){a._queue[s].push({method:e,args:Array.prototype.slice.apply(arguments)})})}(r[n]);e.ctscimhtiraidem=a,e[s]=a[s];e=t.createElement("script");e.setAttribute("type","text/javascript"),e.setAttribute("src",`${i}/contextual_targeting.js`),e.setAttribute("async","true"),t.getElementsByTagName("script")[0].parentNode.appendChild(e)}(window,document,snippetName,siteToken);
You can find the site token, for each channel created, in Settings > Datamart > Channel.
The two common ways to integrate a tag are:
  • Through a universal tag container like Google Tag Manager or another similar solution. The code snippet must be copied once in a new tag and the tag container service automatically inserts the code wherever it is needed.
  • By inserting the code snippet in a general purpose template (ex: header template for an e-shop) which is used in all the web site pages.