@optable/web-sdk 0.45.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,53 +1,76 @@
1
- # Optable Web SDK [![Continuous Integration](https://github.com/Optable/optable-web-sdk/actions/workflows/pull-request.yml/badge.svg)](https://github.com/Optable/optable-web-sdk/actions/workflows/pull-request.yml)
1
+ # Optable Web SDK [![Continuous Integration](https://github.com/Optable/optable-web-sdk/actions/workflows/pull-request.yml/badge.svg)](https://github.com/Optable/optable-web-sdk/actions/workflows/pull-request.yml) <!-- omit in toc -->
2
2
 
3
3
  JavaScript SDK for integrating with an [Optable Data Connectivity Node (DCN)](https://docs.optable.co/) from a web site or web application.
4
4
 
5
- ## Contents
5
+ ## Contents <!-- omit in toc -->
6
6
 
7
7
  - [Installing](#installing)
8
- - [npm module](#npm-module)
9
- - [script tag](#script-tag)
8
+ - [NPM module](#npm-module)
9
+ - [Script tag](#script-tag)
10
10
  - [Versioning](#versioning)
11
11
  - [Domains and Cookies](#domains-and-cookies)
12
12
  - [LocalStorage](#localstorage)
13
- - [Using the npm module](#using-the-npm-module)
13
+ - [Using the NPM module](#using-the-npm-module)
14
+ - [Initialization Configuration (`InitConfig`)](#initialization-configuration-initconfig)
15
+ - [Required Keys](#required-keys)
16
+ - [Optional Keys](#optional-keys)
17
+ - [Usage Example](#usage-example)
18
+ - [Security \& Privacy](#security--privacy)
14
19
  - [Identify API](#identify-api)
15
20
  - [Profile API](#profile-api)
16
21
  - [Targeting API](#targeting-api)
22
+ - [Single Identifier (Default)](#single-identifier-default)
23
+ - [Multiple Identifiers](#multiple-identifiers)
24
+ - [TypeScript Types](#typescript-types)
25
+ - [Caching Targeting Data](#caching-targeting-data)
17
26
  - [Witness API](#witness-api)
18
27
  - [Using a script tag](#using-a-script-tag)
28
+ - [Option 1: Automatic Initialization](#option-1-automatic-initialization)
29
+ - [Option 2: Manual Initialization with Commands Queue](#option-2-manual-initialization-with-commands-queue)
30
+ - [Integrating PrebidJS analytics](#integrating-prebidjs-analytics)
31
+ - [Script tag](#script-tag-1)
32
+ - [NPM package](#npm-package)
19
33
  - [Integrating GAM360](#integrating-gam360)
20
34
  - [Targeting key values](#targeting-key-values)
21
35
  - [Targeting key values from local cache](#targeting-key-values-from-local-cache)
22
36
  - [Witnessing ad events](#witnessing-ad-events)
23
- - [Passing Secure Signals to GAM](#gam-secure-signals)
37
+ - [GAM Secure Signals](#gam-secure-signals)
24
38
  - [Integrating Prebid](#integrating-prebid)
39
+ - [Open Pair ID Prebid Module](#open-pair-id-prebid-module)
25
40
  - [Seller Defined Audiences](#seller-defined-audiences)
26
41
  - [Custom key values](#custom-key-values)
27
42
  - [Identifying visitors arriving from Email newsletters](#identifying-visitors-arriving-from-email-newsletters)
28
43
  - [Insert oeid into your Email newsletter template](#insert-oeid-into-your-email-newsletter-template)
29
44
  - [Call tryIdentifyFromParams SDK API](#call-tryidentifyfromparams-sdk-api)
30
- - [Fetching Google Privacy Sandbox Topics](#fetching-google-privacy-sandbox-topics)
45
+ - [Passport and Visitor ID](#passport-and-visitor-id)
46
+ - [Multi-Node Targeting Resolver](#multi-node-targeting-resolver)
47
+ - [Usage](#usage)
48
+ - [Rules](#rules)
49
+ - [Return Value](#return-value)
50
+ - [Input Type](#input-type)
31
51
  - [Demo Pages](#demo-pages)
32
52
 
33
53
  ## Installing
34
54
 
35
- The [Optable](https://optable.co/) web SDK can be installed as a ES6 compatible [npm](https://www.npmjs.com/) module paired with module bundlers such as [webpack](https://webpack.js.org/) or [browserify](http://browserify.org/), or can be loaded on a webpage directly by referencing a release build from the page HTML via a `<script>` tag.
55
+ The [Optable](https://optable.co/) web SDK can be installed as a ES6 compatible [npm](https://www.npmjs.com/) module using package managers such as [pnpm](https://pnpm.io/), paired with module bundlers such as [webpack](https://webpack.js.org/) or [browserify](http://browserify.org/), or can be loaded on a webpage directly by referencing a release build from the page HTML via a `<script>` tag.
36
56
 
37
57
  > :warning: **CORS Configuration**: Regardless of how you install the SDK, make sure that the _Allowed HTTP Origins_ setting in the Optable DCN that you are integrating with contains the URL(s) of any web site(s) where the SDK is being used, otherwise your browser may block communication with the DCN.
38
58
 
39
- ### npm module
59
+ ### NPM module
40
60
 
41
- If you're building a web application or want to bundle the SDK functionality with your own JavaScript, then [npm](https://www.npmjs.com/) is the recommended installation method. It pairs nicely with module bundlers such as [webpack](https://webpack.js.org/) or [browserify](http://browserify.org/) and exports types for applications using the [typescript](https://www.typescriptlang.org/) language and type checker. To use it simply install the package:
61
+ If you're building a web application or want to bundle the SDK functionality with your own JavaScript, then using a package manager like [pnpm](https://pnpm.io/) or [npm](https://www.npmjs.com/) is the recommended installation method. It pairs nicely with module bundlers such as [webpack](https://webpack.js.org/) or [browserify](http://browserify.org/) and exports types for applications using the [typescript](https://www.typescriptlang.org/) language and type checker. To use it simply install the package:
42
62
 
43
63
  ```shell
44
- # latest stable release:
64
+ # latest stable release (using pnpm):
65
+ pnpm install @optable/web-sdk
66
+
67
+ # or using npm:
45
68
  npm install @optable/web-sdk
46
69
  ```
47
70
 
48
71
  And then simply `import` and use the `OptableSDK` class as shown in the _Usage_ section below.
49
72
 
50
- ### script tag
73
+ ### Script tag
51
74
 
52
75
  For simple integrations from your web site, you can load the SDK built for the browser from Optable's CDN via a HTML `script` tag. In production it's advised to lock your SDK bundle to a specific major version identified by `vX` or a specific minor version with `vX.Y`, while in development you may want to experiment with `latest`.
53
76
 
@@ -92,7 +115,7 @@ const sdk = new OptableSDK({ host: "dcn.customer.com", site: "my-site", cookies:
92
115
 
93
116
  Note that the default is `cookies: true` and will be inferred if you do not specify the `cookies` parameter at all.
94
117
 
95
- ## Using the npm module
118
+ ## Using the NPM module
96
119
 
97
120
  ## Initialization Configuration (`InitConfig`)
98
121
 
@@ -328,7 +351,7 @@ type WitnessProperties = {
328
351
 
329
352
  ## Using a script tag
330
353
 
331
- For each [SDK release](https://github.com/Optable/optable-web-sdk/releases), a webpack-generated browser bundle targeting the browsers list described by `npx browserslist "> 0.25%, not dead"` can be loaded on a website via a `script` tag.
354
+ For each [SDK release](https://github.com/Optable/optable-web-sdk/releases), a webpack-generated browser bundle targeting the browsers list described by `pnpm dlx browserslist "> 0.25%, not dead"` can be loaded on a website via a `script` tag.
332
355
 
333
356
  As described in the **Installation** section above, the recommended way to load the SDK via `script` tag is asynchronously using the `async` attribute, to avoid blocking page rendering.
334
357
 
@@ -389,6 +412,58 @@ You can also manually initialize the SDK using the cmd queue. This approach is u
389
412
  <input type="text" id="email" value="some.email@address.com" />
390
413
  ```
391
414
 
415
+ ## Integrating PrebidJS analytics
416
+
417
+ The `OptablePrebidAnalytics` addon hooks into [Prebid.js](https://prebid.org/) auction events (`auctionEnd` and `bidWon`) and sends auction analytics to the Optable DCN via the **witness API**. It reports per-bidder EID coverage, bid outcomes, and optional custom key-value pairs, enabling you to measure the impact of Optable targeting on your Prebid auctions.
418
+
419
+ ### Script tag
420
+
421
+ When the SDK is loaded via a `<script>` tag, `OptablePrebidAnalytics` is available as `window.optable.OptablePrebidAnalytics`.
422
+
423
+ ```html
424
+ <!-- Optable SDK async load: -->
425
+ <script async src="https://cdn.optable.co/web-sdk/v0/sdk.js"></script>
426
+
427
+ <!-- Prebid.js async load: -->
428
+ <script async src="prebid.js"></script>
429
+
430
+ <script>
431
+ window.optable = window.optable || { cmd: [] };
432
+ window.pbjs = window.pbjs || { que: [] };
433
+
434
+ optable.cmd.push(function () {
435
+ optable.instance = new optable.SDK({ host: "dcn.customer.com", site: "my-site" });
436
+
437
+ const analytics = new optable.OptablePrebidAnalytics(optable.instance, {
438
+ analytics: true,
439
+ tenant: "my_tenant", // Replace with your Optable tenant name
440
+ });
441
+
442
+ analytics.hookIntoPrebid(window.pbjs);
443
+ });
444
+ </script>
445
+ ```
446
+
447
+ ### NPM package
448
+
449
+ When using the SDK as an NPM package, import `OptablePrebidAnalytics` directly from the addon module:
450
+
451
+ ```javascript
452
+ import OptableSDK from "@optable/web-sdk";
453
+ import OptablePrebidAnalytics from "@optable/web-sdk/lib/addons/prebid/analytics";
454
+
455
+ const sdk = new OptableSDK({ host: "dcn.customer.com", site: "my-site" });
456
+
457
+ const analytics = new OptablePrebidAnalytics(sdk, {
458
+ analytics: true,
459
+ tenant: "my_tenant", // Replace with your Optable tenant name
460
+ });
461
+
462
+ analytics.hookIntoPrebid(window.pbjs);
463
+ ```
464
+
465
+ For extended configuration options such as sampling, debug mode, and custom analytics data, see the [Prebid analytics addon README](lib/addons/prebid/README.md).
466
+
392
467
  ## Integrating GAM360
393
468
 
394
469
  The Optable Web SDK can fetch targeting data from a DCN and map it to be sent to [Google Ad Manager 360](https://admanager.google.com/home/) ad server account for real-time targeting. It's also capable of intercepting advertising events from the [Google Publisher Tag](https://developers.google.com/doubleclick-gpt/guides/get-started) and logging them to a DCN via the **witness API**.
@@ -850,51 +925,28 @@ For example:
850
925
  </script>
851
926
  ```
852
927
 
853
- ## Fetching Google Privacy Sandbox topics
854
-
855
- To fetch Google Privacy Sandbox topics using the Optable SDK, you can use the `getTopics` method. This method asynchronously retrieves topics IDs and taxonomy versions from the Chrome browser. Alternatively, you can use the `ingestTopics` method. This method invokes `getTopics` and sends the retrieved topics to the Optable DCN under the trait "topics_api". See the [Topics API dictionary](https://patcg-individual-drafts.github.io/topics/#dictdef-browsingtopic) for details.
928
+ ## Passport and Visitor ID
856
929
 
857
- It is recommended to call this method before making ad calls to ensure that the latest topics are available for targeting.
930
+ The Optable DCN issues a _passport_ (a signed JWT) that is cached in browser `localStorage`. The passport encodes a unique _visitor ID_ that the DCN uses to anonymously identify the browser. Both values can be read synchronously from the SDK:
858
931
 
859
- ```html
860
- <!-- Optable SDK async load: -->
861
- <script async src="https://cdn.optable.co/web-sdk/latest/sdk.js"></script>
862
- <script>
863
- window.optable = window.optable || { cmd: [] };
864
- optable.cmd.push(function () {
865
- optable.instance = new optable.SDK({ host: "dcn.customer.com", site: "my-site" });
866
- // Fetch Google Privacy Sandbox topics and send them to the Optable DCN
867
- optable.instance.ingestTopics();
868
- });
869
- </script>
932
+ ```javascript
933
+ const passport = sdk.passport(); // string | null — the raw JWT as stored in localStorage
934
+ const visitorId = sdk.visitorId(); // string | null — the `id` claim decoded from the passport
870
935
  ```
871
936
 
872
- ## Demo Pages
937
+ Both methods return `null` until the passport has been populated in `localStorage`. By default (`initPassport: true`) the SDK triggers a `/config` call at construction time, and the DCN response populates the passport.
873
938
 
874
- The demo pages are working examples of both `identify` and `targeting` APIs, as well as an integration with the [Google Ad Manager 360](https://admanager.google.com/home/) ad server, enabling the targeting of ads served by GAM360 to audiences activated in the [Optable](https://optable.co/) DCN.
875
-
876
- You can browse a recent (but not necessarily the latest) released version of the demo pages at [https://demo.optable.co/](https://demo.optable.co/). The source code to the demos can be found in the [demos directory](https://github.com/Optable/optable-web-sdk/tree/master/demos). The demo pages will connect to the [Optable](https://optable.co/) demo DCN at `sandbox.optable.co` and reference the web site slug `web-sdk-demo`. The GAM360 targeting demo loads ads from a GAM360 account operated by [Optable](https://optable.co/).
877
-
878
- Note that the demo pages at [https://demo.optable.co/](https://demo.optable.co/) will by default rely on secure HTTP first-party cookies as described in [this section](https://github.com/Optable/optable-web-sdk#domains-and-cookies). To see an example based on [LocalStorage](https://github.com/Optable/optable-web-sdk#localstorage), see the [index-nocookies variant here](https://demo.optable.co/index-nocookies.html).
879
-
880
- To build and run the demos locally, you will need [Docker](https://www.docker.com/), `docker-compose` and `make`:
881
-
882
- ```shell
883
- cd path/to/optable-web-sdk
884
- make
885
- docker-compose up
886
- ```
887
-
888
- Then head to [https://localhost:8180/](localhost:8180) to see the demo pages. You can modify the code in each demo, then run `make build` and finally refresh the demo pages to see your changes take effect. If you want to test the demos with your own DCN, make sure to update the configuration (hostname and site slug) given to the OptableSDK (see `webpack.config.js` for the react example).
939
+ If the returned value is `null`, the SDK logs a one-time warning per instance to help diagnose the cause. The two expected reasons for a `null` return are:
889
940
 
890
- Note that using HTTP first-party cookies with a local instance of the demos pages pointing to an Optable DCN will not work because [https://localhost:8180/](localhost:8180) does not share the same top-level domain name `.optable.co`. We recommend using [LocalStorage](https://github.com/Optable/optable-web-sdk#localstorage) instead.
941
+ 1. The method was called before the passport was cached (e.g. before `sdk.site()` resolved).
942
+ 2. The DCN is configured to not echo the passport in response bodies, in which case the client-side cache is never populated.
891
943
 
892
944
  ## Multi-Node Targeting Resolver
893
945
 
894
946
  Resolves multiple **Node Targeting Rules** based on **priority** or **aggregation**.
895
947
  This function is available under `window.optable.utils` as part of a collection of helper methods extending the SDK.
896
948
 
897
- ### **Usage**
949
+ ### Usage
898
950
 
899
951
  Define targeting rules:
900
952
 
@@ -931,13 +983,13 @@ const result = await window.optable.utils.resolveMultiNodeTargeting(rules);
931
983
  console.log(result);
932
984
  ```
933
985
 
934
- ### **Rules**
986
+ ### Rules
935
987
 
936
988
  - If **any rule has a `priority`**, the function will return the response with the highest priority (1 being the highest). Lower priorities (2, 3, etc.) are considered progressively less important. Any rules with priority values of 0 or below are ignored.
937
989
  - If **multiple nodes share the highest priority**, merges their `eids`.
938
990
  - If **no priority is set**, aggregates all responses.
939
991
 
940
- ### **Return Value**
992
+ ### Return Value
941
993
 
942
994
  ```typescript
943
995
  type MultiNodeTargetingResponse = {
@@ -948,7 +1000,7 @@ type MultiNodeTargetingResponse = {
948
1000
  };
949
1001
  ```
950
1002
 
951
- ### **Input Type**
1003
+ ### Input Type
952
1004
 
953
1005
  ```typescript
954
1006
  type NodeTargetingRule = {
@@ -966,3 +1018,23 @@ type NodeTargetingRule = {
966
1018
  priority?: number;
967
1019
  };
968
1020
  ```
1021
+
1022
+ ## Demo Pages
1023
+
1024
+ The demo pages are working examples of both `identify` and `targeting` APIs, as well as an integration with the [Google Ad Manager 360](https://admanager.google.com/home/) ad server, enabling the targeting of ads served by GAM360 to audiences activated in the [Optable](https://optable.co/) DCN.
1025
+
1026
+ You can browse a recent (but not necessarily the latest) released version of the demo pages at [https://demo.optable.co/](https://demo.optable.co/). The source code to the demos can be found in the [demos directory](https://github.com/Optable/optable-web-sdk/tree/master/demos). The demo pages will connect to the [Optable](https://optable.co/) demo DCN at `sandbox.optable.co` and reference the web site slug `web-sdk-demo`. The GAM360 targeting demo loads ads from a GAM360 account operated by [Optable](https://optable.co/).
1027
+
1028
+ Note that the demo pages at [https://demo.optable.co/](https://demo.optable.co/) will by default rely on secure HTTP first-party cookies as described in [this section](https://github.com/Optable/optable-web-sdk#domains-and-cookies). To see an example based on [LocalStorage](https://github.com/Optable/optable-web-sdk#localstorage), see the [index-nocookies variant here](https://demo.optable.co/index-nocookies.html).
1029
+
1030
+ To build and run the demos locally, you will need [Docker](https://www.docker.com/), `docker-compose` and `make`:
1031
+
1032
+ ```shell
1033
+ cd path/to/optable-web-sdk
1034
+ make
1035
+ docker-compose up
1036
+ ```
1037
+
1038
+ Then head to [https://localhost:8180/](localhost:8180) to see the demo pages. You can modify the code in each demo, then run `make build` and finally refresh the demo pages to see your changes take effect. If you want to test the demos with your own DCN, make sure to update the configuration (hostname and site slug) given to the OptableSDK (see `webpack.config.js` for the react example).
1039
+
1040
+ Note that using HTTP first-party cookies with a local instance of the demos pages pointing to an Optable DCN will not work because [https://localhost:8180/](localhost:8180) does not share the same top-level domain name `.optable.co`. We recommend using [LocalStorage](https://github.com/Optable/optable-web-sdk#localstorage) instead.