For the complete documentation index, see llms.txt. This page is also available as Markdown.

Contextual targeting

Set up the contextual targeting module: the schema update and event rule every customer needs, and the snippet that activates targeting lists.

Your goal

Prepare your environment so that contextual targeting can analyse your content and, if you need it, activate targeting lists on your pages.

Expected outcome

Your schema carries the contextual fields, the Contextual Targeting Extractor event rule runs on your channels, and - if you activate targeting lists - the contextual snippet is deployed on your pages.

Prerequisites

The contextual module enabled for your organisation. It is not enabled by default: get in touch with your Account Manager. What contextual targeting is, and its solutions, are described in Contextual reference.

General setup (mandatory)

Every customer using contextual targeting needs this setup, whether or not they activate targeting lists.

1

Update the schema

For both solutions, add this line to the UserEvent type in your runtime schema:

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

and make sure the ts field in UserEvent is indexed:

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

For semantic targeting, and in particular to create audience segments from semantic information, add:

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")

along with the types they refer to:

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")
}

Add @EdgeAvailability on semantic_tagging and targeting_list_ids if you want to use those characteristics in Edge segments.

Schema work in general is documented in Design your data model & schema.

2

Add the Contextual Targeting Extractor event rule

Add the Contextual Targeting Extractor event rule to the channels where you want to use contextual targeting. The event rule mechanism itself is documented in Event rules; what this particular rule does is:

  • Specify which JavaScript tag collects URLs and hits. Either the user event tag, which uses the URL explicitly passed in the event and requires the tracking snippet, or the contextual targeting tag, which captures the page URL from the browser automatically and requires the contextual snippet.

  • Calculate and add the contextual key to the event. Automatic once the rule is added.

  • Add the extracted semantic information to the event. Required if you want audience segments based on semantic information - tick Tag event with semantic extract.

  • Blacklist URLs, individually or by pattern. No semantic extraction and no targeting is performed on them.

3

Blacklist URLs

One entry per line, in each list.

One URL per line. None of them may include the protocol (http://, https://):

www.mediarithmics.io/homepage
actu.mediarithmics.io/
mediarithmics.io/actu

One expression per line. Only * is authorised, and * is automatically applied before and after the input expression.

mediarithmics*.io/homepage

blacklists:

  • www.mediarithmics.io/homepage

  • mediarithmicsTEST.io/homepage

  • mediarithmics*io/homepage/page

On a news site, blacklist the pages that list articles - usually themed index pages such as "politics" - which are refreshed frequently and whose semantic content is therefore unstable.

Activation setup (optional)

Needed only to activate targeting lists.

1

Deploy the contextual snippet

For website activation, deploy the contextual targeting snippet on every page where contextual targeting activation should happen. The snippet is made of a configuration you fill in with your site token and a snippet name, and a technical part that asynchronously loads the contextual targeting tag and must not be edited.

The site token for each channel is found in Settings > Datamart > Channel.

Common integration routes: through a universal tag container such as Google Tag Manager, where the snippet is copied once into a new tag; or by inserting it into a general-purpose template used across all pages, such as a header template.

The snippet should go in the <head> of the page. Its code is non-blocking and does not affect page rendering time.

The tag loaded by the snippet can also capture new URLs and their hits, which is why it can serve as the collection route as well as the activation route.

2

Handle single-page applications

Optional, depending on your site.

In a single-page application, call the following function whenever the URL changes, on every page where contextual targeting should be performed:

The call extracts the current URL, looks up the associated targeting lists, and synchronises their IDs with the configured activation platforms.

1

Integrate the API

Integrate the API that fetches the targeting lists associated with a given URL. The response carries an array of targeting list IDs. Signature authentication is documented in Manage API access.

2

Send the IDs to the activation platform

Send those IDs to the activation platform you work with, following that platform's own documentation.

How the tag behaves

1

It identifies the URL

The contextual targeting tag identifies the URL browsed by an anonymous user.

2

It resolves the lists

It determines which targeting lists are associated with that URL.

3

It performs key-value targeting

It proceeds to key/value targeting with the configured activation platforms.

Last updated

Was this helpful?