### Consumer Usage Example with __gpp
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/README.md
Shows how a consumer can use the global __gpp function to ping the GPP, add an event listener, check for a section, and get a field value.
```javascript
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/CONTRIBUTING.md
Installs all necessary dependencies for the project. Run this command after cloning the repository.
```sh
npm install
```
--------------------------------
### Install @iabgpp/stub
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/modules/stub/README.md
Install the stub module using npm.
```bash
npm install @iabgpp/stub
```
--------------------------------
### Build Stub for Direct Page Drop
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/modules/stub/README.md
Clone the repository, install dependencies, and build the stub for direct inclusion on a page.
```bash
git clone https://github.com/InteractiveAdvertisingBureau/iabgpp-es.git
cd iabgpp-es/modules/stub/
npm install
npm run build
```
--------------------------------
### CMP Usage Example with CmpApi
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/README.md
Demonstrates how a CMP can use the CmpApi to set a GPP string, update a field value, and retrieve the GPP string.
```javascript
```
--------------------------------
### Get Queue of Commands
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/modules/stub/README.md
Use the global __gpp() function to retrieve a queue of commands and log the success and data.
```javascript
__gpp("ping", function (data, success) {
console.log("ping success: " + success + " data: " + JSON.stringify(data));
});
```
--------------------------------
### CMP Methods for IAB GPP Framework
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/README.md
Provides a list of methods available to CMPs for managing GPP consent information. These include methods for setting and getting GPP strings, field values, and section data.
```javascript
constructor(cmpId: number, cmpVersion: number, customCommands?: CustomCommands)
fireEvent(eventName: string, value: any)
fireErrorEvent(value: string)
fireSectionChange(value: string)
getEventStatus()
setEventStatus(eventStatus: EventStatus)
getCmpStatus()
setCmpStatus(cmpStatus: CmpStatus)
getCmpDisplayStatus(): CmpDisplayStatus
setCmpDisplayStatus(cmpDisplayStatus: CmpDisplayStatus)
getApplicableSections(): number[]
setApplicableSections(applicableSections: number[]): void
getSignalStatus(): SignalStatus
setSignalStatus(signalStatus: SignalStatus): void
setGppString(encodedGppString: string): void
getGppString(): string
setSectionString(sectionName: string, encodedSectionString: string): void
setSectionStringById(sectionId: number, encodedSectionString: string): void
getSectionString(sectionName: string): string
getSectionStringById(sectionId: number): string
setFieldValue(sectionName: string, fieldName: string, value: any): void
setFieldValueBySectionId(sectionId: number, fieldName: string, value: any)
getFieldValue(sectionName: string, fieldName: string): any
getFieldValueBySectionId(sectionId: number, fieldName: string)
getSection(sectionName: string): any
getSectionById(sectionId: number): any
hasSection(sectionName: string): any
hasSectionId(sectionId: number): any
deleteSection(sectionName: string)
deleteSectionById(sectionId: number)
clear()
getObject()
getGvlFromVendorList(vendorList: VendorList): GVL
async getGvlFromUrl(gvlUrlConfig: GVLUrlConfig): Promise
```
--------------------------------
### Build Project
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/CONTRIBUTING.md
Compiles the project's source code into distributable formats. This command is typically used before deployment or for local testing of the built output.
```sh
npm run build
```
--------------------------------
### Consumer Commands for IAB GPP Framework
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/README.md
Lists commands available to consumers for interacting with the GPP framework. These include adding/removing event listeners and retrieving GPP information.
```javascript
__gpp("addEventListener", callback?, parameter?)
__gpp("getField", callback?, parameter?)
__gpp("getSection", callback?, parameter?)
__gpp("hasSection", callback?, parameter?)
__gpp("ping", callback?, parameter?)
__gpp("removeEventListener", callback?, parameter?)
```
--------------------------------
### Run Project Tests
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/CONTRIBUTING.md
Executes the test suite to ensure code quality and functionality. It's recommended to run tests before submitting changes.
```sh
npm run test
```
--------------------------------
### Include Stub via ES Module Import
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/modules/stub/README.md
Import the stub module to set up the global __gpp() function. No further calls are needed after import.
```javascript
import "@iabgpp/stub";
```
--------------------------------
### Consumer Commands
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/README.md
Commands available for consumers to interact with the IAB GPP Framework via the `__gpp` function.
```APIDOC
## Consumer Commands
### Description
Commands for consumers to query and interact with GPP information using the global `__gpp` function.
### Commands
- `__gpp("addEventListener", callback?, parameter?)`: Adds an event listener.
- `__gpp("getField", callback?, parameter?)`: Retrieves a specific field's value.
- `__gpp("getSection", callback?, parameter?)`: Retrieves a specific section's data.
- `__gpp("hasSection", callback?, parameter?)`: Checks if a section exists.
- `__gpp("ping", callback?, parameter?)`: Pings the GPP service to check its status.
- `__gpp("removeEventListener", callback?, parameter?)`: Removes an event listener.
```
--------------------------------
### Include Stub via CommonJS Require
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/modules/stub/README.md
Require the stub module to set up the global __gpp() function. No further calls are needed after requiring.
```javascript
require("@iabgpp/stub");
```
--------------------------------
### CMP Methods
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/README.md
Methods available for Consent Management Platforms (CMPs) to interact with the IAB GPP Framework.
```APIDOC
## CMP Methods
### Description
Methods for CMPs to manage and retrieve GPP consent information.
### Methods
- `constructor(cmpId: number, cmpVersion: number, customCommands?: CustomCommands)`: Initializes the CMP API.
- `fireEvent(eventName: string, value: any)`: Fires a custom event.
- `fireErrorEvent(value: string)`: Fires an error event.
- `fireSectionChange(value: string)`: Fires a section change event.
- `getEventStatus()`: Retrieves the current event status.
- `setEventStatus(eventStatus: EventStatus)`: Sets the event status.
- `getCmpStatus()`: Retrieves the CMP status.
- `setCmpStatus(cmpStatus: CmpStatus)`: Sets the CMP status.
- `getCmpDisplayStatus(): CmpDisplayStatus`: Retrieves the CMP display status.
- `setCmpDisplayStatus(cmpDisplayStatus: CmpDisplayStatus)`: Sets the CMP display status.
- `getApplicableSections(): number[]`: Retrieves the applicable sections.
- `setApplicableSections(applicableSections: number[]): void`: Sets the applicable sections.
- `getSignalStatus(): SignalStatus`: Retrieves the signal status.
- `setSignalStatus(signalStatus: SignalStatus): void`: Sets the signal signal status.
- `setGppString(encodedGppString: string)`: Sets the encoded GPP string.
- `getGppString(): string`: Retrieves the encoded GPP string.
- `setSectionString(sectionName: string, encodedSectionString: string)`: Sets the encoded string for a specific section by name.
- `setSectionStringById(sectionId: number, encodedSectionString: string)`: Sets the encoded string for a specific section by ID.
- `getSectionString(sectionName: string): string`: Retrieves the encoded string for a specific section by name.
- `getSectionStringById(sectionId: number): string`: Retrieves the encoded string for a specific section by ID.
- `setFieldValue(sectionName: string, fieldName: string, value: any)`: Sets a field value within a section by name.
- `setFieldValueBySectionId(sectionId: number, fieldName: string, value: any)`: Sets a field value within a section by ID.
- `getFieldValue(sectionName: string, fieldName: string): any`: Retrieves a field value from a section by name.
- `getFieldValueBySectionId(sectionId: number, fieldName: string)`: Retrieves a field value from a section by ID.
- `getSection(sectionName: string): any`: Retrieves an entire section by name.
- `getSectionById(sectionId: number): any`: Retrieves an entire section by ID.
- `hasSection(sectionName: string): any`: Checks if a section exists by name.
- `hasSectionId(sectionId: number): any`: Checks if a section exists by ID.
- `deleteSection(sectionName: string)`: Deletes a section by name.
- `deleteSectionById(sectionId: number)`: Deletes a section by ID.
- `clear()`: Clears all GPP information.
- `getObject()`: Retrieves the entire GPP object.
- `getGvlFromVendorList(vendorList: VendorList): GVL`: Generates a GVL object from a vendor list.
- `async getGvlFromUrl(gvlUrlConfig: GVLUrlConfig): Promise`: Asynchronously retrieves and generates a GVL object from a URL.
```
--------------------------------
### CMP API Methods
Source: https://github.com/iabtechlab/iabgpp-es/blob/master/modules/cmpapi/README.md
Methods available for CMPs to manage and retrieve GPP consent information.
```APIDOC
## Constructor
### Description
Initializes a new instance of the CmpApi.
### Method
`constructor(cmpId: number, cmpVersion: number, customCommands?: CustomCommands)`
### Parameters
- **cmpId** (number) - Required - The CMP identifier.
- **cmpVersion** (number) - Required - The CMP version.
- **customCommands** (CustomCommands) - Optional - Custom commands for the API.
## fireEvent
### Description
Fires a custom event with associated data.
### Method
`fireEvent(eventName: string, value: any)`
### Parameters
- **eventName** (string) - Required - The name of the event.
- **value** (any) - Required - The data associated with the event.
## fireErrorEvent
### Description
Fires an error event with a specific message.
### Method
`fireErrorEvent(value: string)`
### Parameters
- **value** (string) - Required - The error message.
## fireSectionChange
### Description
Fires an event indicating a change in a specific section.
### Method
`fireSectionChange(value: string)`
### Parameters
- **value** (string) - Required - The identifier of the changed section.
## getEventStatus
### Description
Retrieves the current status of events.
### Method
`getEventStatus()`
## setEventStatus
### Description
Sets the status for events.
### Method
`setEventStatus(eventStatus: EventStatus)`
### Parameters
- **eventStatus** (EventStatus) - Required - The event status to set.
## getCmpStatus
### Description
Retrieves the current status of the CMP.
### Method
`getCmpStatus()`
## setCmpStatus
### Description
Sets the status of the CMP.
### Method
`setCmpStatus(cmpStatus: CmpStatus)`
### Parameters
- **cmpStatus** (CmpStatus) - Required - The CMP status to set.
## getCmpDisplayStatus
### Description
Retrieves the display status of the CMP.
### Method
`getCmpDisplayStatus(): CmpDisplayStatus`
## setCmpDisplayStatus
### Description
Sets the display status of the CMP.
### Method
`setCmpDisplayStatus(cmpDisplayStatus: CmpDisplayStatus)`
### Parameters
- **cmpDisplayStatus** (CmpDisplayStatus) - Required - The CMP display status to set.
## getApplicableSections
### Description
Retrieves the list of applicable GPP sections.
### Method
`getApplicableSections(): number[]`
## setApplicableSections
### Description
Sets the list of applicable GPP sections.
### Method
`setApplicableSections(applicableSections: number[]): void`
### Parameters
- **applicableSections** (number[]) - Required - An array of section IDs.
## getSignalStatus
### Description
Retrieves the current signal status.
### Method
`getSignalStatus(): SignalStatus`
## setSignalStatus
### Description
Sets the signal status.
### Method
`setSignalStatus(signalStatus: SignalStatus): void`
### Parameters
- **signalStatus** (SignalStatus) - Required - The signal status to set.
## setGppString
### Description
Sets the encoded GPP string.
### Method
`setGppString(encodedGppString: string): void`
### Parameters
- **encodedGppString** (string) - Required - The GPP string to set.
## getGppString
### Description
Retrieves the encoded GPP string.
### Method
`getGppString(): string`
## setSectionString
### Description
Sets the encoded string for a specific GPP section by name.
### Method
`setSectionString(sectionName: string, encodedSectionString: string): void`
### Parameters
- **sectionName** (string) - Required - The name of the section.
- **encodedSectionString** (string) - Required - The encoded string for the section.
## setSectionStringById
### Description
Sets the encoded string for a specific GPP section by ID.
### Method
`setSectionStringById(sectionId: number, encodedSectionString: string): void`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
- **encodedSectionString** (string) - Required - The encoded string for the section.
## getSectionString
### Description
Retrieves the encoded string for a specific GPP section by name.
### Method
`getSectionString(sectionName: string): string`
### Parameters
- **sectionName** (string) - Required - The name of the section.
## getSectionStringById
### Description
Retrieves the encoded string for a specific GPP section by ID.
### Method
`getSectionStringById(sectionId: number): string`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
## setFieldValue
### Description
Sets a specific field's value within a GPP section by name.
### Method
`setFieldValue(sectionName: string, fieldName: string, value: any): void`
### Parameters
- **sectionName** (string) - Required - The name of the section.
- **fieldName** (string) - Required - The name of the field.
- **value** (any) - Required - The value to set for the field.
## setFieldValueBySectionId
### Description
Sets a specific field's value within a GPP section by ID.
### Method
`setFieldValueBySectionId(sectionId: number, fieldName: string, value: any): void`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
- **fieldName** (string) - Required - The name of the field.
- **value** (any) - Required - The value to set for the field.
## getFieldValue
### Description
Retrieves the value of a specific field within a GPP section by name.
### Method
`getFieldValue(sectionName: string, fieldName: string): any`
### Parameters
- **sectionName** (string) - Required - The name of the section.
- **fieldName** (string) - Required - The name of the field.
## getFieldValueBySectionId
### Description
Retrieves the value of a specific field within a GPP section by ID.
### Method
`getFieldValueBySectionId(sectionId: number, fieldName: string): any`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
- **fieldName** (string) - Required - The name of the field.
## getSection
### Description
Retrieves the entire object for a specific GPP section by name.
### Method
`getSection(sectionName: string): any`
### Parameters
- **sectionName** (string) - Required - The name of the section.
## getSectionById
### Description
Retrieves the entire object for a specific GPP section by ID.
### Method
`getSectionById(sectionId: number): any`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
## hasSection
### Description
Checks if a specific GPP section exists by name.
### Method
`hasSection(sectionName: string): any`
### Parameters
- **sectionName** (string) - Required - The name of the section.
## hasSectionId
### Description
Checks if a specific GPP section exists by ID.
### Method
`hasSectionId(sectionId: number): any`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
## deleteSection
### Description
Deletes a specific GPP section by name.
### Method
`deleteSection(sectionName: string): void`
### Parameters
- **sectionName** (string) - Required - The name of the section.
## deleteSectionById
### Description
Deletes a specific GPP section by ID.
### Method
`deleteSectionById(sectionId: number): void`
### Parameters
- **sectionId** (number) - Required - The ID of the section.
## clear
### Description
Clears all GPP information.
### Method
`clear(): void`
## getObject
### Description
Retrieves the entire GPP object.
### Method
`getObject(): any`
## getGvlFromVendorList
### Description
Generates a GVL object from a provided VendorList.
### Method
`getGvlFromVendorList(vendorList: VendorList): GVL`
### Parameters
- **vendorList** (VendorList) - Required - The vendor list object.
## getGvlFromUrl
### Description
Asynchronously retrieves and generates a GVL object from a URL.
### Method
`async getGvlFromUrl(gvlUrlConfig: GVLUrlConfig): Promise`
### Parameters
- **gvlUrlConfig** (GVLUrlConfig) - Required - Configuration object for fetching the GVL URL.
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.