Gravito SDK V2

Using SDK V2

To use SDK you should have gravito config added to your site. Make sure you also have settings section added inside your config.

Using SDK for FirstParty

To Add standalone firstParty to your site you should modify setting section of your config as follows.

window.gravitoCMPConfig = {
  settings: {
    sdkVersion: 2,
  },
};

Then add following javaScript to your site. Make sure config loading logic is added above this script.

var gravitoSDKTag = document.createElement("script");
gravitoSDKTag.src =
  "https://gravitocdn.blob.core.windows.net/sdkv2/v201/sdk.js";
gravitoSDKTag.onload = function () {
  window.gravito.init("firstParty");
};
document.body.appendChild(gravitoSDKTag);

To check if the first party has been added to your site or not, please use following script and test it with browser console window. It should return your gravito registered firstParty URL

gravito.firstParty.getDefaultURL();

Once Firstparty is added to your website you can use the firstParty function to interact with gravito backend.

Get Your profile,

To get your profile you can call following function

function customCb(data) {
  console.log("data", data);
}
gravito.firstParty.getProfile(customCb);

Have your own First PartyId?

Using gravito firstParty you can use your own ID and give it more persistance using Gravito First Party API

function customCb(data) {
  console.log("data", data);
}
var gmId = "your own id";
gravito.firstParty.postEvents(
  {
    "gmId-overide": "gmid changed to " + gmId,
  },
  customCb,
  gmId
);

Send a Key value pair of events

You can attach key-value pairs to the profile for eg: pageViews : n

function customCb(data) {
  console.log("data", data);
}
let key = "pageViews";
let value = 2;
let model = {};
model[key] = value;
gravito.firstParty.postEvents(model, customCb);

Send a Keys to the Profile

Attach keys to the profile to get a complete picture of the profile. eg: GA ID.

function customCb(data) {
  console.log("data", data);
}
let keysInput = [
  {
    i: "56396541p-0jud-7qawe-lk45ue973723",
    K: "GAID",
    v: "56396541p-0jud-7qawe-lk45ue973723",
  },
  {
    i: "500808182",
    K: "FBID",
    v: "500808182",
  },
];

gravito.firstParty.postKeys(keysInput, customCb);

Attach consents to the profile to access it any time.

function customCb(data) {
  console.log("data", data);
}
let consentInputs = [
  { i: "t", c: "consent1", s: false },
  { i: "m", c: "consent2", s: false },
];

gravito.firstParty.postConsents(consentInputs, customCb);

Bridge in Match On id

Connect with matchOnId ( eg: a deterministic Id) to connect X-domain and X-device

function customCb(data) {
  console.log("data", data);
}
let matchOnId = "your_match_onId";

gravito.firstParty.attachMatchOnId(matchOnId, customCb);

Reset Profile

To reset your firstParty use following snippet

function customCb(data) {
  console.log("data", data);
}
let matchOnId = "reset";

gravito.firstParty.attachMatchOnId(matchOnId, customCb);

Delete Profile

To delete your firstParty use following snippet

function customCb(data) {
  console.log("data", data);
}
let matchOnId = "delete";

gravito.firstParty.attachMatchOnId(matchOnId, customCb);

Using SDK to deploy Standalone Light CMP

To Add standalone LightCMP to your site you should modify setting section of your config as follows.

window.gravitoCMPConfig = {
  settings: {
    type: "Light",
    useGCM: false,
    backendUrl: "",
    version: "bundle_Latest_2",
    componentURL: "https://cdn.gravito.net/ligthcmp",
    sdkVersion: 2,
  },
  //other sections
};

Then add following javaScript to your side. Make sure config loading logic is added above this script.

var gravitoSDKTag = document.createElement("script");
gravitoSDKTag.src =
  "https://gravitocdn.blob.core.windows.net/customhtmlscripts/sdk.js";
gravitoSDKTag.onload = function () {
  window.gravito.init("lightCMP");
};
document.body.appendChild(gravitoSDKTag);

Enabling GCM on exisitng Gravito’s LightCMP

To enable Google Consent Mode on Gravito’s LightCMP change “useGCM” flag to true in settings section of your conifg.

window.gravitoCMPConfig = {
  settings: {
    type: "Light",
    useGCM: true,
    version: "bundle_Latest_2",
    componentURL: "https://cdn.gravito.net/cmpbuilds",
    sdkVersion: 2,
  },
  //other sections
};

Enabling First Party backend capabilites on gravito’s Light CMP

To enable First Party backend capabilites on light CMP pass second argument “firstParty” to “gravito.init” function also update gravitoCMP config with follwing values

window.gravitoCMPConfig = {
  settings: {
    type: "Light",
    useGCM: true, // set it true if you want to use GCM as well
    backendUrl: "https://gto.yourDomainName", // if left empty url will be generated from hostname
    profileType: "",
    version: "bundle_Latest_2",
    componentURL: "https://cdn.gravito.net/lightcmp",
    sdkVersion: 2,
  },
  //other sections
};
var gravitoSDKTag = document.createElement("script");
gravitoSDKTag.src =
  "https://gravitocdn.blob.core.windows.net/customhtmlscripts/sdk.js";
gravitoSDKTag.onload = function () {
  window.gravito.init("lightCMP", "firstParty");
};
document.body.appendChild(gravitoSDKTag);

Using SDK to deploy Standalone TCF CMP

To Add standalone TCFCMP to your site you should modify setting section of your config as follows.

window.gravitoCMPConfig = {
  settings: {
    type: "TCF",
    version: "bundle_Latest_2",
    componentURL: "https://cdn.gravito.net/cmp",
    sdkVersion: 2,
  },
  //other sections
};

In additon to above config add follwing script to your site.

var gravitoSDKTag = document.createElement("script");
gravitoSDKTag.src =
  "https://gravitocdn.blob.core.windows.net/customhtmlscripts/sdk.js";
gravitoSDKTag.onload = function () {
  window.gravito.init("tcfCMP");
};
document.body.appendChild(gravitoSDKTag);

Enabling First Party backend capabilites on gravito’s TCF CMP

To enable First Party backend capabilites on TCF CMP pass second argument “firstParty” to “gravito.init” function also update gravitoCMP config with follwing values

window.gravitoCMPConfig = {
  settings: {
    type: "TCF",
    backendUrl: "https://gto.yourDomainName", // if left empty url will be generated from hostname
    version: "bundle_Latest_2",
    componentURL: "https://cdn.gravito.net/cmp",
    sdkVersion: 2,
  },
  //other sections
};
var gravitoSDKTag = document.createElement("script");
gravitoSDKTag.src =
  "https://gravitocdn.blob.core.windows.net/customhtmlscripts/sdk.js";
gravitoSDKTag.onload = function () {
  window.gravito.init("TCF", "firstParty");
};
document.body.appendChild(gravitoSDKTag);

Integrating Gravito’s prebid js usermodule.

Gravito has a user module in prebid js, customers now can use Gravito’s first party service and prebid js usermodule to use a persistent first party id in prebid’s bit stream.

Gravito SDK make’s it easy for the customers to switch on the prebid support by adding userIdModule config parameter and setting its value to true.

window.gravitoCMPConfig = {
  settings: {
    // other parameters
    userIdModule: true,
  },
  //other sections
};

Prebid user module support is available in following scenarios

  1. Gravito First party only.
  2. Gravito Light CMP along with first party
  3. Gravito TCF CMP along with first party

Gravito first party and user module.

window.gravitoCMPConfig = {
  settings: {
    profileType: "micro",
    sdkVersion: 2,
    userIdModule: true,
  },
};

var gravitoSDKTag = document.createElement("script");

gravitoSDKTag.src = "https://cdn.gravito.net/sdkv2/latest/sdk.js";

gravitoSDKTag.onload = function () {
  // init gravito with two comma separated parameters, firstParty and prebid
  // this will make sure that the first party service drops a persistent id which can be utlized in prebids bit stream.
  window.gravito.init("firstParty", "prebid");
};

document.body.appendChild(gravitoSDKTag);

Gravito’s SDK makes sure that the gravito’s first party persistant id is written into a first party client side cookie “gravitompId”, which is then parsed by the userModule and made available to prebid’s bit stream.

To check if the first party id has been added to user module or not, please use following script and test it with browser console window.

pbjs.getUserIds().gravitompId.id;

Gravito Light CMP with first party and user module.

window.gravitoCMPConfig = {
  settings: {
    useGCM: false,
    backendUrl: "",
    profileType: "micro",
    version: "bundle_latest_2",
    componentURL: "https://cdn.gravito.net/lightcmp",
    sdkVersion: 2,
    userIdModule: true,
  },
  // other settings
};

var gravitoSDKTag = document.createElement("script");

gravitoSDKTag.src = "https://cdn.gravito.net/sdkv2/latest/sdk.js";

gravitoSDKTag.onload = function () {
  // init gravito with two comma separated parameters, lightCMP, firstParty and prebid
  // this will make sure that the first party service drops a persistent id which can be utlized in prebids bit stream.
  window.gravito.init("lightCMP", "firstParty", "prebid");
};

document.body.appendChild(gravitoSDKTag);

Gravito’s SDK makes sure that the gravito’s first party persistant id is written into a first party client side cookie “gravitompId”, which is then parsed by the userModule and made available to prebid’s bit stream.

To check if the first party id has been added to user module or not, please use following script and test it with browser console window.

pbjs.getUserIds().gravitompId.id;

Gravito TCF CMP with first party and user module.

window.gravitoCMPConfig = {
  settings: {
    useGCM: false,
    backendUrl: "",
    profileType: "micro",
    version: "bundle_latest_2",
    componentURL: "https://cdn.gravito.net/cmp",
    sdkVersion: 2,
    userIdModule: true,
  },
  // other settings
};

var gravitoSDKTag = document.createElement("script");

gravitoSDKTag.src = "https://cdn.gravito.net/sdkv2/latest/sdk.js";

gravitoSDKTag.onload = function () {
  // init gravito with two comma separated parameters, lightCMP, firstParty and prebid
  // this will make sure that the first party service drops a persistent id which can be utlized in prebids bit stream.
  window.gravito.init("tcfCMP", "firstParty", "prebid");
};

document.body.appendChild(gravitoSDKTag);

Gravito’s SDK makes sure that the gravito’s first party persistant id is written into a first party client side cookie “gravitompId”, which is then parsed by the userModule and made available to prebid’s bit stream.

To check if the first party id has been added to user module or not, please use following script and test it with browser console window.

pbjs.getUserIds().gravitompId.id;