Skip to content

Commit

Permalink
Add support for in-band passport transport (#26)
Browse files Browse the repository at this point in the history
* Regen targeting/prebid-us-east-16.html

* Add support for in-band passport transport

When configuring an instance of OptableSDK, we now support a `cookies`
attribute (`true` by default) which, when set to `false`, will cause the
SDK to use "in-band" passport transport, more specifically:

- The `passport` parameter will be set in the query string in each
  network call to the sandbox
- The sandbox will return a `passport` attribute in any successful JSON
  response payload
- The SDK will attempt to read the returned `passport` attribute and
  store it in LocalStorage, scoped to the sandbox host and site slug
  with which the OptableSDK instance was instantiated
- At the subsequent network call to the sandbox, any passport value
  previously stored in LocalStorage will be retrieved and passed back to
  the sandbox as the `passport` query string parameter value

Also updates README for in-band passport transport, and adds demos for
the in-band passport transport case which can be browsed from
.../demos/index-nocookies.html

Depends on optable-sandbox PR419:
Optable/optable-sandbox#419

* Delete the passport from the returned payload.

This is done when the passport is passed "in-band" and it is done
because the targeting edge handler was initially made to return
targeting data directly in the form of 'key values' on the
returned JSON payload -- if we don't delete the `passport`
attribute here, it may end up sent as targeting data to ad
servers. Not the end of the world, but something we want to avoid
due to passport size.
  • Loading branch information
bmilekic authored Dec 8, 2020
1 parent 95762df commit fe6f8fb
Show file tree
Hide file tree
Showing 25 changed files with 2,857 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.prettierrc
browser/dist
lib/dist
demos/publishers
demos/vanilla/nocookies/targeting/prebid*.js
demos/vanilla/targeting/prebid*.js
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ COPY --from=build /build/demos/vanilla/identify.html ./vanilla/identify.html
COPY --from=build /build/demos/vanilla/profile.html ./vanilla/profile.html
COPY --from=build /build/demos/vanilla/witness.html ./vanilla/witness.html
COPY --from=build /build/demos/vanilla/authenticator.html ./vanilla/authenticator.html
COPY --from=build /build/demos/vanilla/nocookies/targeting/gam360.html ./vanilla/nocookies/targeting/gam360.html
COPY --from=build /build/demos/vanilla/nocookies/targeting/gam360-cached.html ./vanilla/nocookies/targeting/gam360-cached.html
COPY --from=build /build/demos/vanilla/nocookies/targeting/prebid.html ./vanilla/nocookies/targeting/prebid.html
COPY --from=build /build/demos/vanilla/nocookies/targeting/prebid-us-east-16.html ./vanilla/nocookies/targeting/prebid-us-east-16.html
COPY --from=build /build/demos/vanilla/nocookies/targeting/prebid.js ./vanilla/nocookies/targeting/prebid.js
COPY --from=build /build/demos/vanilla/nocookies/targeting/prebid-us-east-16.js ./vanilla/nocookies/targeting/prebid-us-east-16.js
COPY --from=build /build/demos/vanilla/nocookies/identify.html ./vanilla/nocookies/identify.html
COPY --from=build /build/demos/vanilla/nocookies/profile.html ./vanilla/nocookies/profile.html
COPY --from=build /build/demos/vanilla/nocookies/witness.html ./vanilla/nocookies/witness.html
COPY --from=build /build/demos/react/dist/ ./react/dist/
COPY --from=build /build/demos/index.html ./index.html
COPY --from=build /build/demos/css/ ./css/
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ JavaScript SDK for integrating with optable-sandbox from a web site or web appli
- [script tag](#script-tag)
- [Versioning](#versioning)
- [Domains and Cookies](#domains-and-cookies)
- [LocalStorage](#localstorage)
- [Using (npm module)](#using-npm-module)
- [Identify API](#identify-api)
- [Profile API](#profile-api)
Expand Down Expand Up @@ -74,6 +75,18 @@ For example, if your website runs at `www.customer.com` or `customer.com`, then

> :warning: **Optable Visitor ID Scope**: The _visitor ID_ configured by the Optable sandbox will be unique to a browser only within the top-level domain that the sandbox shares with the calling web site.
### LocalStorage

In cases where it is not practical or possible to configure your sandbox to run on the same effective top-level domain plus one (eTLD+1) as your website(s), then the default cookie-based transport that the SDK depends on will not work. Instead, a fallback cookie-less transport utilizing browser `LocalStorage` is recommended. To switch to the cookie-less transport, simply set the optional `cookies` parameter to `false` when creating your SDK instance. For example:

```javascript
import OptableSDK from "@optable/web-sdk";

const sdk = new OptableSDK({ host: "sandbox.customer.com", site: "my-site", cookies: false });
```

Note that the default is `cookies: true` and will be inferred if you do not specify the `cookies` parameter at all.

## Using (npm module)

To configure an instance of `OptableSDK` integrating with an [Optable](https://optable.co/) sandbox running at hostname `sandbox.customer.com`, from a configured web site origin identified by slug `my-site`, you simply create an instance of the `OptableSDK` class exported by the `@optable/web-sdk` module:
Expand Down
9 changes: 8 additions & 1 deletion demos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ html:
envsubst < ./vanilla/targeting/gam360-cached.html.tpl > ./vanilla/targeting/gam360-cached.html && \
envsubst < ./vanilla/targeting/prebid.html.tpl > ./vanilla/targeting/prebid.html && \
envsubst < ./vanilla/targeting/prebid-us-east-16.html.tpl > ./vanilla/targeting/prebid-us-east-16.html && \
envsubst < ./vanilla/authenticator.html.tpl > ./vanilla/authenticator.html
envsubst < ./vanilla/authenticator.html.tpl > ./vanilla/authenticator.html && \
envsubst < ./vanilla/nocookies/identify.html.tpl > ./vanilla/nocookies/identify.html && \
envsubst < ./vanilla/nocookies/witness.html.tpl > ./vanilla/nocookies/witness.html && \
envsubst < ./vanilla/nocookies/profile.html.tpl > ./vanilla/nocookies/profile.html && \
envsubst < ./vanilla/nocookies/targeting/gam360.html.tpl > ./vanilla/nocookies/targeting/gam360.html && \
envsubst < ./vanilla/nocookies/targeting/gam360-cached.html.tpl > ./vanilla/nocookies/targeting/gam360-cached.html && \
envsubst < ./vanilla/nocookies/targeting/prebid.html.tpl > ./vanilla/nocookies/targeting/prebid.html && \
envsubst < ./vanilla/nocookies/targeting/prebid-us-east-16.html.tpl > ./vanilla/nocookies/targeting/prebid-us-east-16.html

.PHONY: react
react:
Expand Down
110 changes: 110 additions & 0 deletions demos/index-nocookies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Optable Web SDK Demos</title>
<meta name="description" content="Optable Web SDK Demos" />
<meta name="author" content="optable.co" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/skeleton.css" />
<link rel="icon" type="image/png" href="/images/favicon.png" />
</head>
<body>
<div class="container">
<div class="row">
<div class="twelve column" style="margin-top: 5%;">
<a href="/index-nocookies.html"><img src="/images/logo.png" width="200" /></a>
<hr />
</div>
</div>
<div class="row">
<div class="twelve column">
<h4>👋 demo.optable.co (cookies=false)</h4>
<p>
To learn about optable-web-sdk integration on your web site or application, see the latest releases, or
report an issue, please check out the
<a href="https://github.com/Optable/optable-web-sdk">web-sdk GitHub README</a>. If you're looking for more
information on Optable itself, visit <a href="https://optable.co/">our company site</a>.
</p>
<p>
In all examples below, the Optable demo environment is used. Data stored by the demo environment is
periodically deleted.
</p>
<p>
<strong
>Note that the examples below initialize the OptableSDK with cookies=false, so all ID transport is done
using browser LocalStorage.</strong
>
Generally, it is preferable to use secure first party HTTP-only cookies for transporting IDs from
OptableSDK. However, when the integrating website does not share the same top-level domain name with the
Optable Sandbox, then first party cookies are not reliable, and the LocalStorage method is suggested. To
enable it, simply initialize the OptableSDK object with the <code>cookies</code> option set to
<code>false</code>, and the SDK will do the rest.
</p>
</div>
</div>
<div class="row">
<div class="twelve column">
<h5>Examples</h5>
<table class="u-full-width">
<thead>
<tr>
<th>Link</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="/vanilla/nocookies/identify.html">identify API</a></td>
<td>
Simple <code>script</code> tag integration showing how to send a hashed Email address and optional
publisher user ID to your sandbox.
</td>
</tr>
<tr>
<td><a href="/vanilla/nocookies/witness.html">witness API</a></td>
<td>Shows how to log events with optional properties to your sandbox.</td>
</tr>
<tr>
<td><a href="/vanilla/nocookies/profile.html">profile API</a></td>
<td>Shows how to set visitor traits (e.g., <code>age=45</code>) and sync them to your sandbox.</td>
</tr>
<tr>
<td><a href="/vanilla/nocookies/targeting/gam360.html">targeting &amp; GAM360 activation</a></td>
<td>
Shows how to load active cohorts for a visitor and pass them to
<a href="https://admanager.google.com/home/">Google Ad Manager</a> (GAM) via the
<a href="https://developers.google.com/publisher-tag/guides/get-started">Google Publisher Tag</a> for
ad targeting.
</td>
</tr>
<tr>
<td>
<a href="/vanilla/nocookies/targeting/gam360-cached.html">cached targeting &amp; GAM360 activation</a>
</td>
<td>
Shows how to load and cache active cohorts in a visitor's browser. Separately, cached cohorts are
passed to <a href="https://admanager.google.com/home/">Google Ad Manager</a> (GAM) via the
<a href="https://developers.google.com/publisher-tag/guides/get-started">Google Publisher Tag</a> for
ad targeting.
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="twelve column" style="font-size: 0.8rem; padding: 10px;">
<center>
<a href="https://www.optable.co/">Home</a> | <a href="https://www.optable.co/company/contact">Contact</a> |
<a href="https://optable.co/privacy">Privacy</a> |
<a href="https://www.linkedin.com/company/optableco/">LinkedIn</a> |
<a href="https://twitter.com/optable_co">Twitter</a>
</center>
</div>
</div>
</div>
</body>
</html>
138 changes: 138 additions & 0 deletions demos/vanilla/nocookies/identify.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Optable Web SDK Demos</title>
<meta name="description" content="Optable Web SDK Demos" />
<meta name="author" content="optable.co" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="/css/normalize.css" />
<link rel="stylesheet" href="/css/skeleton.css" />
<link rel="icon" type="image/png" href="/images/favicon.png" />

<!-- Optable web-sdk loader start -->
<script type="text/javascript">
window.optable = window.optable || { cmd: [] };

optable.cmd.push(function () {
optable.instance = new optable.SDK({
host: "localhost",
site: "web-sdk-demo",
insecure: JSON.parse("true"),
cookies: false,
});

optable.instance.tryIdentifyFromParams();
});
</script>
<script async src="http://localhost:8081/sdk.js"></script>
<!-- Optable web-sdk loader end -->

<style>
.code-result {
padding: 0.2rem 0.5rem;
margin: 0 0.2rem;
font-size: 90%;
background: #f1f1f1;
border: 1px solid #e1e1e1;
border-radius: 4px;
display: block;
padding: 1rem 1.5rem;
white-space: pre;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="twelve column" style="margin-top: 5%;">
<a href="/index-nocookies.html"><img src="/images/logo.png" width="200" /></a>
<hr />
</div>
</div>

<div class="row">
<div class="twelve column">
<h4>Example: identify API</h4>
<p>
Simple <code>script</code> tag integration showing how to send a hashed Email address and optional publisher
user ID to your sandbox.
</p>
</div>
</div>

<div class="row">
<div class="twelve column">
<fieldset>
<div>
<label for="email-checked"><input id="email-checked" type="checkbox" checked /> Email Address:</label>
<input id="email" type="email" size="64" />
</div>
<br />
<div>
<label for="ppid-checked"><input id="ppid-checked" type="checkbox" /> Send PPID:</label>
<input id="ppid" type="text" size="64" disabled />
</div>
<br />
<button id="identify-button" class="button-primary">Identify</button>
</fieldset>
</div>
</div>

<div class="row">
<div class="twelve column code-result" id="result"></div>
</div>

<div class="row">
<div class="twelve column" style="font-size: 0.8rem; padding: 10px;">
<center>
<a href="https://www.optable.co/">Home</a> | <a href="https://www.optable.co/company/contact">Contact</a> |
<a href="https://optable.co/privacy">Privacy</a> |
<a href="https://www.linkedin.com/company/optableco/">LinkedIn</a> |
<a href="https://twitter.com/optable_co">Twitter</a>
</center>
</div>
</div>
</div>

<script>
document.getElementById("email-checked").onchange = function () {
document.getElementById("email").disabled = !this.checked;
};

document.getElementById("ppid-checked").onchange = function () {
document.getElementById("ppid").disabled = !this.checked;
};

document.getElementById("identify-button").addEventListener("click", () => {
const emailCb = document.getElementById("email-checked");
const ppidCb = document.getElementById("ppid-checked");
const result = document.getElementById("result");

var email = null;
var ppid = null;
result.innerHTML = "";

if (emailCb.checked) {
email = document.getElementById("email").value;
result.innerHTML += "Email: " + email + " (" + optable.SDK.eid(email) + ")<br />";
}

if (ppidCb.checked) {
ppid = document.getElementById("ppid").value;
result.innerHTML += "PPID: " + ppid + " (" + optable.SDK.cid(ppid) + ")<br />";
}

optable.instance
.identify(optable.SDK.eid(email), optable.SDK.cid(ppid))
.then(function () {
result.innerHTML += "Sent";
})
.catch((err) => {
result.innerHTML += "Error:<br />" + err.message;
});
});
</script>
</body>
</html>
Loading

0 comments on commit fe6f8fb

Please sign in to comment.