Schema update

For Panel-based as wel as Semantic contextual targeting, you'll need to update your runtime schema to add the following line in UserEvent type:

contextual_key:String @TreeIndex(index:"USER_INDEX")

$url attribute needs to be populated with a proper URL in order to extract the contextual_key (URL without protocol nor query stings).

As well, ensure that the field ts in UserEvent is indexed:

ts:Timestamp! @TreeIndex(index:"USER_INDEX")

For Semantic contextual targeting, and particularly if you want to create Audience segments based on semantic information, you'll need to add the following line in UserEvent type:

semantic_tagging:[SemanticTagging] @Property(path:"$properties.$semantic_tagging")

As well as the following types:

type SemanticTagging  {
   provider_id:String @Property(path:"$provider_id") @TreeIndex(index:"USER_INDEX")
   provider_version:String @Property(path:"$provider_version") @TreeIndex(index:"USER_INDEX")

   entities:[SemanticEntity] @Property(path:"$entities")
   iab_categories:[SemanticIABCategory] @Property(path:"$iab_categories")

type SemanticEntity  {
   entity_id:String @Property(path:"$entity_id") @TreeIndex(index:"USER_INDEX")
   name:String @Property(path:"$name") @TreeIndex(index:"USER_INDEX")
   type:String @Property(path:"$type")
   wikidata_id:String @Property(path:"$wikidata_id")

type SemanticIABCategory  {
   category_id:String @TreeIndex(index:"USER_INDEX") @Property(path:"$category_id")
   name:String @TreeIndex(index:"USER_INDEX") @Property(path:"$name")

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.

Event rule

You need to add CONTEXTUAL_TARGETING_EXTRACTOR event rule to channels on which you want to use the contextual targeting feature. This event rule will have two roles:

  • Calculate and add the contextual key in the event

  • Tag the event with semantic information

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:


Note that only * is authorized and * will automatically be applied before and after the provided regexp.

Please note that this event rule can only be created through an API call at the moment. Reach out to us if you need some help with this.

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. The configuration that you should fill according to your context (site token & snippet name)

  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.

Last updated