1.2.0 • Published 1 year ago

@paginar/gppstring v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

This library is DEPRECATED and will not be maintained

Please use https://github.com/IABTechLab/iabgpp-es instead

Purpose

A client library to construct IAB's Global Privacy Platform (GPP) strings

This library includes support for:

Section IDClient-side API PrefixDescriptionSupported
1tcfeuv1EU TCF v1 section (deprecated)N/A
2tcfeuv2EU TCF v2 sectionNot yet
3GPPHeader section (REQUIRED, see note below)Not yet
4--GPP signal integrity sectionNot yet
5tcfcaCanadian TCF sectionNot yet
6uspv1USPrivacy String (Unencoded Format)Yes
7usnatUS - national sectionNot yet
8uscaUS - California sectionYes
9usvaUS - Virginia sectionNot yet
10uscoUS - Colorado sectionNot yet
11usutUS - Utah sectionNot yet
12usctUS - Connecticut sectionNot yet

Getting started

Installation

Before we get started, you'll need to install Node and Yarn or npm, and create a directory for your project. Then, install the library using Yarn:

yarn add @paginar/gppstring

Or when using npm run:

npm install @paginar/gppstring

The library can be used in CommonJS & ES6/ESM environments. To use the CJS version:

let {
  UspcaSection,
  GPPString,
} = require("@paginar/gppstring/dist/cjs/index.cjs");

To use the ESM version:

import { UspcaSection, GPPString } from "@paginar/gppstring/dist/esm/index.mjs";

Creating a GPP string

In order to create a GPP string, you first need to create & configure each of the Sections you want to support.

For example if your application needs to support CPRA (for details see the California's privacy rights act spec) you would build a uspca section object, assigning the appropiate values to each user consent

import { UspcaSection, GPPString } from "@paginar/gppstring/dist/esm/index.mjs";

let uspca = new UspcaSection.Builder()
  .setSaleOptOutNotice(0)
  .setSharingOptOutNotice(1)
  .setSensitiveDataLimitUseNotice(1)
  .setSaleOptOut(1)
  .setSharingOptOut(1)
  .setSensitiveDataProcessing([0, 0, 0, 0, 0, 0, 0, 0, 0])
  .setKnownChildSensitiveDataConsents([0, 0])
  .setPersonalDataConsents(0)
  .setMspaCoveredTransaction(0)
  .setMspaOptOutOptionMode(0)
  .setMspaServiceProviderMode(0)
  .build();

let gppString = new GPPString.Builder().addSection(uspca).build();
console.log(gppString.encode2Base64Websafe())

In the console you should see the output as a base64-websafe string: "DBABBa~BAAAAAAA"

Examples

See the /examples folder for CommonJS & ESM examples. Also most source files have Jest tests (/src/**/*.test.js) files which should prove useful.

Caveats

  • The base64-websafe encoding does not match 100% the examples given in the spec. This may be due to an improper padding (we are splicing the bit string into 6 bit chars, and padding the remainder with "0").
    • 0000110000010000000000010011 > DBABM (not DBABMA)
    • 000011000001000000000010001101011 > DBACNY (not DBACNYA)
    • 000011000001000000000001100011110000 > DBABdq (not DBABjw)

To do

  • Add all other sections
  • Add console logging (with different log levels)
  • Create the localStorage key names (ie IABGPP_8_String)
  • GPP String decoder function to assist in debugging? (:thumbsdown:)

Contributors