Skip to main content

API Functions (US for Web)

GPP API

__gpp(command, [callback], [parameter], [version])

Argument Name

Type

Value

command

String

Name of the command to execute

version

number

Optional parameter, version of the API, currently v1.0

callback

function

Function to be executed with the result of the command

parameter

number

Parameter to be passed to the command function

Commands

ping

Gets CMP metadata.

__gpp('ping', (pingReturn) => {console.log(pingReturn)})

Argument Name

Type

Value

command

string

'ping'

version

number

(ignored)

callback

function

Function to be executed with the result of the command

parameter

(ignored)

What the function returns

CMP Metadata

Argument Name

Value

gppVersion

current GPP version as string

cmpStatus

stub | loaded | error

cmpDisplayStatus

visible | hidden | disabled

supportedAPIs

List of supported APIs (prefix strings), e.g. used while loading. Example: [‘usnat’]

cmpId

IAB assigned CMP ID, may be 0 during stub/loading.

Function call:

__gpp('ping', (data, success) => {console.log(data)})

Returned value

gppVersion: "1.0"
cmpStatus: "loaded"
cmpDisplayStatus: "visible"
suportedAPIs: [‘usnat’]

Accept (give consent)

Gives consent to specific purposes or to all purposes if parameters are not provided or null.

Argument Name

Type

Value

command

string

'accept'

version

number

(ignored)

callback

function

Function to be executed with the result of the command

parameter

Array

Array | purposeId | null

Accept all:

__gpp('accept',(result, success) => console.log(result, success), [], null);    
__gpp('accept',(result, success) => console.log(result, success), null, null);

Accepts specific purposes, list their IDs as parameter:

 __gpp('accept',(result, success) => console.log(result, success), ['saleOptOut-1', 'sharingOptOut-1'], null);

Reject (revoke consent)

Revokes consent from specific purposes or from all purposes if parameters are not provided or null..

Argument Name

Type

Value

command

string

'reject'

version

number

(ignored)

callback

function

Function to be executed with the result of the command

parameter

Array | null

purposeId | null

Reject all example:

__gpp(reject,(result, success) => console.log(result, success), [], null);    
__gpp(reject,(result, success) => console.log(result, success), null, null);

Reject specific purposes example, list their IDs as parameter:

__gpp(reject,(result, success) => console.log(result, success), ['saleOptOut-1', 'sharingOptOut-1'], null);true | false

CMP Applies

Gets the information on whether the CMP applies or not. If a user is located in the US, CMP will apply.

Argument Name

Type

Value

command

string

'cmpApplies'

version

number

(ignored)

callback

function

Function to be executed with the result of the command

parameter

(ignored)

Function call:

__gpp('cmpApplies', (res)=> console.log(res))

What the function returns:

true | false. True if cmp applies, false otherwise

showConsentManager

The showConsentManager command will surface the manager screen at any given time regardless of consent state.

Argument Name

Type

Value

command

string

'showConsentManager'

version

number

(ignored)

callback

function

function(result: Void)

Consent manager will be shown

parameter

Optional(boolean)

If passed it will be used to force consent tool state to show or hide regardless of the current state.

 

The command below opens the consent manager:

__gpp('showConsentManager')

The command below opens the privacy information page:

__gpp('showConsentManager', null, { openPrivacyInformation: true })

The command below hides the consent:

__gpp('showConsentManager', null, { toggle: false })

addEventListener

The addEventListener command registers a callback function with the CMP. The listener's callback is triggered when for example the consent string status has changed. The listener is registered with an ID for later removal.

__gpp('addEventListener', (result) => {console.log(result)});

Argument Name

Type

Value

command

string

'addEventListener'

version

number

(ignored)

callback(result)

function

Function to be executed with the result of the command

parameter

 

(ignored)

Returned value

The addEventListener command returns an EventListener object immediately. The GPP script will then call the callback function and return a new EventListener object every time the CMP detects a change.

{       
        eventName : String, // for possible values see events below        
        listenerId : Number, // Registered ID of the listener        
        data: mixed, // data supplied by the underlying API (see possible values below)        
        pingData : object // see ping command and PingReturn object    
}

Event Name

Data

Description

listenerRegistered

boolean

The data property signals whether the event listener was registered successfully.

listenerRemoved

boolean

The data property signals whether the event listener was successfully removed.

cmpStatus

string

The data property will contain the new status (e.g. “loaded”).

cmpDisplayStatus

string

The data property will contain the new display status (e.g. “visible”).

error

string

The data property will contain a human readable error message.

sectionChange

string

The data property will indicate the name (API prefix) of the changed section.

removeEventListener

The removeEventListener command removes specific previously registered event listener or all registered event listeners.

Argument Name

Type

Value

command

string

'removeEventListener'

version

number

(ignored)

callback(result)

function

Function to be executed with the result of the command.

parameter

 

(ignored)

To remove specific event listener:

__gpp('removeEventListener', (result: EventListener) => {console.log(result)}, listenerId);

To remove all registered event listeners:

__gpp('removeEventListener', (result: EventListener) => {console.log(result)});

Returned value

{
    eventName : "listenerRemoved"
    listenerId : Number, // Registered ID of the listener, or 0 if no listener was removed
    data: boolean, // true if action was successful, false otherwise
    pingData : object // see ping command and PingReturn object
}

hasSection

Detects if the CMP has generated a section of a certain specification.

Argument Name

Type

Value

command

string

'hasSection'

version

number

(ignored)

callback(result)

function

Function to be executed with the result of the command

parameter

string

API Prefix string

__gpp('hasSection', (result) => {console.log(result)}, "usnat");

Returned value

The command returns boolean. true if the specified section is present, false otherwise.

getSection

Used to receive the (parsed) object representation of a section of a certain specification or null.

Argument Name

Type

Value

command

string

getConsent

version

number

(ignored)

callback(result)

function

Function to be executed with the result of the command.

parameter

string

API Prefix string

__gpp('getSection', (result) => {console.log(result)}, "usnat");

getField

Used to receive a specific field out of a certain section.

Argument Name

Type

Value

command

string

'getField'

version

number

(ignored)

callback(result)

function

Function to be executed with the result of the command

parameter

string

API Prefix string + “.” (dot) + fieldName

__gpp('getField', (result) => {console.log(result)}, "usnat.Version");

getGPPData (To Be Deprecated in GPP v1.1)

This command is used to receive the current version of the (encoded) GPP string.

Argument Name

Type

Value

Command

string

'getGPPData'

version

number

(ignored)

callback(result)

Function to be executed with the result of the command

parameter

function

(ignored)

__gpp('getGPPData', (result) => {console.log(result)});

Returned value

Parsed header plus the encoded GPP String with all sections representing the current GPPData object:

    {
        sectionId : Number,  // Always 3 to indicate the header section
        gppVersion : Number, // The version number parsed from the header
        sectionList : Array of Number, // the sections contained within the encoded GPP string as parsed from the header
        applicableSections: Array of Number, // In most cases, this field should have a single section ID. In rare occasions where such a single section ID can not be determined, the field may contain up to 2 values. The value can be 0 or a Section ID specified by the Publisher / Advertiser, during stub / load. When no section is applicable, the value will be -1.
        gppString: String // the complete encoded GPP string
        pingData: object // see PingReturn
    }