WideOrbit Streaming Targeting SDK
Installation
You must install the SDK from NPM even if you intend to
include it directly as a <script>
tag.
npm i @wostreaming/targeting-sdk
Quick Usage
const client = new WOSTargetingClient(1234, true);
function initializePlayer(params) {
const qs = params.toString({
});
console.log(`?${qs}`);
}
client.getTargetingParams().then(initializePlayer);
Including the SDK in your code
The provided SDK is built as a UMD module, making it compatible with any
environment or development pattern. You can import
or require
the
module in a bundled or transpiled Node app:
import WOSTargetingClient from "@wostreaming/targeting-sdk";
const WOSTargetingClient = require("@wostreaming/targeting-sdk");
Or if you prefer to use it as a standard <script>
tag, that works too;
but, you'll have to serve the script tag somehow. In the packaged release,
it's available under the dist/wos-targeting-sdk.js
path. You
can serve it as a static file however you prefer.
Example express server
import express from "express";
const app = express();
app.use(
"/static/js/wos-targeting-sdk.js",
express.static(
require.resolve("@wostreaming/targeting-sdk")
)
);
app.listen(3000);
Example <script>
tag
<script
type="text/javascript"
src="/static/js/wos-targeting-sdk.js">
</script>
When you include the script tag it will make a global
variable accessible named WOSTargetingClient
. The
rest of the usage information applies regardless of how
you include the SDK.
API
class WOSTargetingClient
# constructor(clientId: string, hasPrivacyPolicy: boolean)
- clientId Your Lotame client ID as a string or int
- hasPrivacyPolicy Have your users agreed to a privacy policy consenting to anonymized tracking and ad targeting?
# getAudienceInfo(): Promise
Returns a Promise that resolves with a Lotame Profile
object containing the user's audience information for targeting.
You generally shouldn't need to call this directly.
# getTargetingParams(): Promise
Returns a Promise that resolves with a WOSTargetingParams
object for working with audience info parsed and managed by the WOS Targeting SDK.
NOTE: A call to getTargetingParams()
should always succeed, even if something goes really wrong.
class WOSTargetingParams
# constructor(profile: Profile)
- profile The Lotame
Profile
object
# toJSON(): Object -> getParams()
Alias of getParams()
# getParams(): Object
Returns an object of key -> value
pairs representing the URL querystring parameters.
# setParams(paramsObj: Object = {})
Set additional parameters or override existing ones
# toString(additionalParams: Object = {})
Returns a URL encoded querystring with all the parameters managed by this object
as well as optional additional parameters to override or add to the query string but not set
on this object. This will properly filter out private information if dnt
is overridden.