You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-40Lines changed: 54 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
# Optable Web SDK [](https://github.com/Optable/optable-web-sdk/actions/workflows/pull-request.yml)
1
+
# Optable Web SDK [](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
8
-[NPM module](#npm-module)
@@ -11,26 +11,43 @@ JavaScript SDK for integrating with an [Optable Data Connectivity Node (DCN)](ht
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.
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:
914
931
915
-
It is recommended to call this method before making ad calls to ensure that the latest topics are available for targeting.
// Fetch Google Privacy Sandbox topics and send them to the Optable DCN
925
-
optable.instance.ingestTopics();
926
-
});
927
-
</script>
932
+
```javascript
933
+
constpassport=sdk.passport(); // string | null — the raw JWT as stored in localStorage
934
+
constvisitorId=sdk.visitorId(); // string | null — the `id` claim decoded from the passport
928
935
```
929
936
930
-
## Demo Pages
931
-
932
-
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.
933
-
934
-
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/).
935
-
936
-
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).
937
-
938
-
To build and run the demos locally, you will need [Docker](https://www.docker.com/), `docker-compose` and `make`:
939
-
940
-
```shell
941
-
cd path/to/optable-web-sdk
942
-
make
943
-
docker-compose up
944
-
```
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.
945
938
946
-
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:
947
940
948
-
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.
949
943
950
944
## Multi-Node Targeting Resolver
951
945
952
946
Resolves multiple **Node Targeting Rules** based on **priority** or **aggregation**.
953
947
This function is available under `window.optable.utils` as part of a collection of helper methods extending the SDK.
954
948
955
-
### **Usage**
949
+
### Usage
956
950
957
951
Define targeting rules:
958
952
@@ -989,13 +983,13 @@ const result = await window.optable.utils.resolveMultiNodeTargeting(rules);
989
983
console.log(result);
990
984
```
991
985
992
-
### **Rules**
986
+
### Rules
993
987
994
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.
995
989
- If **multiple nodes share the highest priority**, merges their `eids`.
996
990
- If **no priority is set**, aggregates all responses.
997
991
998
-
### **Return Value**
992
+
### Return Value
999
993
1000
994
```typescript
1001
995
typeMultiNodeTargetingResponse= {
@@ -1006,7 +1000,7 @@ type MultiNodeTargetingResponse = {
1006
1000
};
1007
1001
```
1008
1002
1009
-
### **Input Type**
1003
+
### Input Type
1010
1004
1011
1005
```typescript
1012
1006
typeNodeTargetingRule= {
@@ -1024,3 +1018,23 @@ type NodeTargetingRule = {
1024
1018
priority?:number;
1025
1019
};
1026
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.
0 commit comments