# Activation setup

{% hint style="warning" %}
To configure Targeting lists activation, please follow the next steps:

1. Contextual snippet installation (for website activation)
2. Targeting list / URL API implementation (for mobile app activation)
3. Activation plaftorm specific setup (for website & mobile app activation)
   {% endhint %}

## Contextual snippet installation

### Setup

For website activation, 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 snippet is made of two parts:

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

```javascript
<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.

{% hint style="success" %}
As mentioned earlier, the **Contextual targeting tag** loaded through the snippet can also capture new URLs and associated hits.
{% endhint %}

{% hint style="info" %}

* The two common ways to integrate the snippet 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.
* The snippet should be inserted in the `<head>` part of the web page. The code of the Contextual targeting snippet is non-blocking - it does not impact on the page rendering time.&#x20;
  {% endhint %}

### 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:

```javascript
ctMics.forceSetTargeting() // replace "ctMics" by the snippetName you used when implementing the contextual snippet
```

This 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.

### How it works

**Contextual targeting tag** will automatically:

1. Identifies the URL browsed by an anonymous user
2. Determines which targeting lists are associated to the URL
3. Proceeds to key/value targeting with the configured activation platforms

## Targeting list / URL API implementation

{% hint style="warning" %}
For mobile app content to be eligible for activation, it must be linked to a URL that can be analyzed.

This means that Contextual Targeting can be used on applications that mirror a website. Semantic analysis and the creation of targeting lists are performed on the website, and the results of the analysis can then be made available to an application that calls our API with a known URL.
{% endhint %}

To enable mobile app activation, follow the steps below:

1. **Integrate our dedicated API** to [fetch the targeting lists associated with a given URL](https://developer.mediarithmics.io/advanced-usages/api-documentation#retrieve-targeting-lists-for-a-given-url) within your mobile app.
   1. Review the [Signature Authentication documentation](https://developer.mediarithmics.io/resources/api-overview/authentication#signature-authentication) to learn more about how to autenticate when making API calls
   2. In the API response, you will receive an array of **targeting\_list IDs** (`id` property in `targeting_lists` object). These IDs must be passed to the activation platform in the next step.
2. **Send the retrieved targeting\_list IDs** to the activation platform you are working with. Refer to the activation platform’s documentation for instructions on how to transmit these IDs.

## Activation plaftorm specific setup

To enable activation on external platforms, follow the setup guide corresponding to each platform:

* [Google Ad Manager](https://developer.mediarithmics.io/advanced-usages/audiences/panel-based-contextual-targeting/google-ad-manager)
* [Xandr (through prebid.js)](https://developer.mediarithmics.io/advanced-usages/audiences/panel-based-contextual-targeting/xandr-through-prebid.js)
* [Equativ](https://developer.mediarithmics.io/advanced-usages/contextual-targeting/activation-setup/equativ)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.mediarithmics.io/advanced-usages/contextual-targeting/activation-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
