Setup
To configure this feature, please follow the next steps IN ORDER:
Schema update
Event rule configuration
Contextual snippet installation
Schema update
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.
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 lines in UserEvent type:
semantic_tagging:[SemanticTagging] @Property(path:"$properties.$semantic_tagging")
targeting_list_ids:[String] @TreeIndex(index:"USER_INDEX") @ReferenceTable(type:"CORE_OBJECT", model_type:"CONTEXTUAL_TARGETING_LISTS") @Property(path:"$properties.$targeting_list_ids")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")
}Don't forget to add @EdgeAvailability on semantic_tagging & targeting_list_ids properties if you want to use those characteristics for building Edge segments. More information about Edge segments.
Event rule configuration
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 various objectives:
Specify which JavaScript tag will be responsible for URL & hit collection:
User event tag: uses the URL explicitly passed in the event
Contextual targeting tag: automatically captures the page URL from the browser
Calculate and add the contextual key in the event. This is done automatically when adding the event rule
Add the semantic information extracted from a URL in the event . This is required if you want to create Audience segments based on semantic information. Check Tag event with semantic extract in that case
Specify URLs (Blacklist URLs) or group of URLs (Blacklist RegEx) to blacklist. No semantic extraction nor targeting will be perfomed on those URLs. If we take the example of a news website, we recommend blacklisting pages that list articles, usually related to the same theme (e.g. "politics") and that are frequently refreshed.
Blacklist URL
Add a URL to blacklist per line. ALL URLs provided should NOT have protocol in it (http://, https://). For example:
www.mediarithmics.io/homepage
actu.mediarithmics.io/
mediarithmics.io/actuBlacklist Regexp
Add a regexp to blacklist per line. Note that only * is authorized and * will automatically be applied before and after the input regexp. For example:
mediarithmics*.io/homepageWill blacklist the following URLs:
www.mediarithmics.io/homepage
mediarithmicsTEST.io/homepage
mediarithmics*io/homepage/page.
Contextual snippet installation
General
You need to deploy a new mediarithmics snippet dedicated to Contextual targeting feature on every page where you want contexutal targeting activation to be performed. The mediarithmics contextual targeting tag is made of two parts:
The configuration that you should fill according to your context (site token & snippet name)
A technical part which contains the JavaScript code which asynchronously load the Contextual targeting tag on the page. This part should not be edited.
Here is an example of the contextual targeting tag you should implement:
<script type="text/javascript">
/* YOU CAN EDIT THIS PART */
const siteToken = "<SITE_TOKEN>" // token to change
const snippetName = "ctMics" // snippet name that can be changed
/* YOU SHOULD NOT EDIT THIS PART */
!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",`https://events.mics-notrack.com/v1/sites/${i}/contextual_targeting.js`),e.setAttribute("async","true"),t.getElementsByTagName("script")[0].parentNode.appendChild(e)}(window,document,snippetName,siteToken);
</script>
You can find the site token, for each channel created, in Settings > Datamart > Channel.
As mentioned earlier, the Contextual targeting tag loaded through the snippet can also capture new URLs and associated hits.
Additional step for SPA
In case of a Single-page application, you will need to execute the following function whenever the URL change and, more exactly, on every page where you want contexutal targeting to be performed:
ctMics.forceSetTargeting() // replace "ctMics" by the snippetName you used when implementing the contextual snippetThis call wil result in extracting the current URL to lookup associated Targeting lists and synchronize their IDs with configured activation platforms. Please make sure to call this function as soon as possible to ensure that the Targeting lists IDs are calculated before the auction is executed.
Last updated
Was this helpful?