# Tag integration V2

{% tabs %}
{% tab title="Tag" %}
{% hint style="info" %}
**Should you want to use our API for user data and/or contextual with Prebid, please consider using our official** [**Prebid Real Time Data Submodule**](https://docs.prebid.org/dev-docs/modules/sirdataRtdProvider.html)
{% endhint %}

Add this **tag** to you *header* or directly to the *ad placement* where you would like to access user segments **cookies & consent based** user-centric segments, **cookieless** and/or **contextual** categories.

{% hint style="success" %}
THIS TAG WILL **NOT** DROP OR ACCESS TO ANY COOKIE. PRIVACY CHECKS WILL BE PERFORMED BY SIRDATA, AND THE CALL MAY BE REDIRECTED TO OUR COOKIE-BASED API WHEN RELEVANT.
{% endhint %}

{% hint style="warning" %}
In UE, the UK, Iceland, Liechtenstein and Norway, unless specifically and by written authorized not to, do call this tag **ONLY** on websites working with a [TCF compliant CMP](https://iabeurope.eu/cmp-list/).&#x20;

The tag will automatically perform relevant checks, but you can perform these tests on your own and earn precious milliseconds : call the tag when a valid ~~consent~~ **CHOICE** for Purposes 1 & 3 and Vendor IDs 53 (cookie-based) and/or 916 (cookieless) has been made by the user, with the mandatory [***gdpr=\[gdpr\_applies\]\&gdpr\_consent=\[tc\_string\]***](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md) parameters in the URL.
{% endhint %}

Use this script to get user-centric segments and contextual categories and use them in the callback function :

```javascript
function sddanCallback(result){
   //Do stuff here e.g. load adserver/ssp with key/value data in result
   console.log(result);
   console.log(JSON.stringify(result.segments));
   console.log(JSON.stringify(result.contextual_categories));
   console.log(JSON.stringify(result.shared_taxonomy));
}

var sddanPid = 1; //USE 1 FOR TESTS, GET YOUR OWN ID
var sddanKeyId = 1; //USE 1 FOR TESTS, GET YOUR OWN ID

var sddanTag = document.createElement('script');
var sddanUrl;
try { sddanUrl = '&url='+encodeURIComponent(window.top.location.href); } catch (e) {}
sddanTag.src = 'https://kvt.cookieless-data.com/api/v1/public/p/'+sddanPid+'/d/'+sddanKeyId+'/s?callback=sddanCallback'+sddanUrl;
sddanTag.async = true;
sddanTag.setAttribute('referrerpolicy','unsafe-url');
document.getElementsByTagName('body')[0].appendChild(sddanTag);
```

*gdpr* and *gdpr\_consent* are collected automatically, but you can earn precious milliseconds by sending them directly on the relevant endpoint like that :

```javascript
<script>
var sddanPid = 1; //USE 1 FOR TESTS, GET YOUR OWN ID
var sddanKeyId = 1; //USE 1 FOR TESTS, GET YOUR OWN ID
var sddanWaitUserChoice = true; //True if you want to wait user choice or false if not
var sddanSegments = new Object;

function sddanCallback(result){
   //Do stuff here e.g. load adserver/ssp with key/value data in result
   console.log(result);
   console.log(JSON.stringify(result.segments));
   console.log(JSON.stringify(result.contextual_categories));
   console.log(JSON.stringify(result.shared_taxonomy));
}

function getSddanTargeting(tcData,isCookiebased) {
	var sddanTag = document.createElement('script');
	var sddanHost = (isCookiebased===true?'sddan.com':'cookieless-data.com');
	var sddanTcString = (tcData?'&gdpr='+tcData.gdprApplies+'&gdpr_consent='+(tcData.tcString?tcData.tcString:''):'');
	var sddanUrl;
	try { sddanUrl = '&url='+encodeURIComponent(window.top.location.href); } catch (e) {}
	sddanTag.src = 'https://kvt.'+sddanHost+'/api/v1/public/p/'+sddanPid+'/d/'+sddanKeyId+'/s?callback=sddanCallback'+sddanUrl+sddanTcString;
	sddanTag.async = true;
	sddanTag.setAttribute('referrerpolicy','unsafe-url');
	document.getElementsByTagName('body')[0].appendChild(sddanTag);
}

(function () {
  if (typeof window.__tcfapi === 'function') {
    window.__tcfapi('addEventListener', 2, function (tcData, success) {
        if (!success || (!tcData.eventStatus && tcData.gdprApplies)) {
            return
        }
        if (!tcData.gdprApplies || (tcData.tcString && tcData.vendor.consents[53] && tcData.purpose.consents[1] && tcData.purpose.consents[4])) {
            getSddanTargeting(tcData,true);
            __tcfapi('removeEventListener', 2, function () {}, tcData.listenerId);
        }
        else if (tcData.eventStatus === "tcloaded" || tcData.eventStatus === "useractioncomplete" || sddanWaitUserChoice !== true) {
        	 getSddanTargeting(tcData,false);
            __tcfapi('removeEventListener', 2, function () {}, tcData.listenerId);
        }
    });
  }
  else {
  	getSddanTargeting(null,null);
  }
})();
</script>
```

| Parameter            | Value                                                                                                                                                                                                                                                                             |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ***\[PARTNER\_ID]*** | *numerical value* - is given by **your contact** at Sirdata during the [API Access](https://docs.sirdata.net/api-overview/api-access) process (e.g. *sddanPid* in the example above) (mandatory)                                                                                  |
| ***\[KEY\_ID]***     | *numerical value* - is given by **your contact** at Sirdata during the [API Access](https://docs.sirdata.net/api-overview/api-access) process (e.g. *sddanKeyId* in the example above) (mandatory)                                                                                |
| ***gdpr***           | [TCF V2 *gdpr\_applies* parameter](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#full-tc-string-passing) (mandatory for EEA/UK users) |
| ***gdpr\_consent***  | [TCF V2 TC String](https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20Consent%20string%20and%20vendor%20list%20formats%20v2.md#full-tc-string-passing) (mandatory for EEA/UK users)                 |
| ***callback***       | callback function name can be change (mandatory)                                                                                                                                                                                                                                  |
| {% endtab %}         |                                                                                                                                                                                                                                                                                   |

{% tab title="Tag Response" %}
{% hint style="info" %}
Tag response will call your **function name set** in the resquest (e.g. ...?*callback=*&#x73;ddanCallback&...)
{% endhint %}

```javascript
sddanCallback({
    "segments": [
        111111,
        222222
    ],
    "segtaxid": null,
    "cattaxid": null,
    "contextual_categories": {
        "333333": 100
    },
    "shared_taxonomy": {
        "27440": {
            "segments": [
                444444,
                555555
            ],
            "segtaxid": 552,
            "cattaxid": 553,
            "contextual_categories": {
                "666666": 100
            }
        }
    },
    "global_taxonomy": {
        "9998": {
            "segments": [
                123,
                234
            ],
            "segtaxid": 4,
            "cattaxid": 7,
            "contextual_categories": {
                "345": 100,
                "456": 100
            }
        },
        "9999": {
            "segments": [
                12345,
                23456
            ],
            "segtaxid": 550,
            "cattaxid": 551,
            "contextual_categories": {
                "34567": 100,
                "45678": 100
            }
        }
    }
})
```

| Name                   | Value                                                                                                                                                                                                                                                                                                              |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| segments               | <p>User-based segments IDs.<br><br>Please refer to your dedicated taxonomy with private segment IDs and segtaxid if operated within SDA specification</p>                                                                                                                                                          |
| contextual\_categories | <p>Context-based category IDs with relevancy score (0-100 scale from lower to higher quality).</p><p></p><p>Please refer to your dedicated taxonomy with private segment IDs and cattaxid if operated within SDA specification</p>                                                                                 |
| global\_taxonomy       | <p>SDA & IAB taxonomies based & user-centric segments & Context-centric categories. </p><p></p><p>These IDs may be shared with all buyers thanks to the SDA specification.</p>                                                                                                                                     |
| shared\_taxonomy       | <p>User-centric segments & Context-centric categories dedicated to a given partner when you request us to share data with him on your website.</p><p></p><p>Useless for you, the partner has his own private taxonomy.</p><p></p><p>These IDs may be shared with given buyers thanks to the SDA specification.</p> |
| {% endtab %}           |                                                                                                                                                                                                                                                                                                                    |
| {% endtabs %}          |                                                                                                                                                                                                                                                                                                                    |

{% hint style="danger" %}
**PLEASE REMBER TO HAVE YOUR DOMAIN(S) WHITELISTED WHEN REQUESTED PRODUCTION PARTNER ID AND KEY ID, OTHERWIZE THE TAG WILL GET NOW ANSWER**
{% endhint %}

Whenever you want to work accordingly to the SDA specification, please refer to the [official segtax ID taxonomies](https://github.com/InteractiveAdvertisingBureau/openrtb/blob/master/extensions/community_extensions/segtax.md).
