@quantcast-labs/events-sdk
v0.1.4
Published
The `@quantcast-labs/events-sdk` is a JavaScript library for interacting with the Quantcast Conversion API. It provides a simple way to acquire browser tokens for tracking offline conversion events. This SDK is an alternative to the main Quantcast JavaScr
Keywords
Readme
Quantcast Events SDK
The @quantcast-labs/events-sdk is a JavaScript library for interacting with
the Quantcast Conversion API. It provides a simple way to acquire browser
tokens for tracking offline conversion events. This SDK is an alternative to
the main Quantcast JavaScript tag (Live Tag) and is suitable for environments
where you need more control over the integration or have specific security
protocols.
Introduction
The Quantcast Platform Conversion API helps you track online events and conversions, which enables both measurement and the creation of predictive models for ad targeting in the Quantcast Platform. While the recommended method for web integration is the Quantcast Live Tag, this SDK provides an alternative for environments where the Live Tag is not suitable. The primary function of this SDK is to acquire a browser token that can be used to link offline conversion events to web activity.
Installation
You can install the package using npm:
npm install @quantcast-labs/events-sdkUsage
The main function exported by the SDK is token. This function acquires a
browser token from the Quantcast API.
Acquiring a Browser Token
To get a browser token, import and call the token function with your
Quantcast account ID. The function returns a promise that resolves with an
object containing the token and its expiration time.
import token from "@quantcast-labs/events-sdk";
token("<account-id>")
.then((tokenData) => {
// tokenData.token contains the browser token string
// tokenData.expires contains the expiration time in Unix Epoch time
// Send the token to your server to be used in subsequent
// Offline Conversion API calls.
navigator.sendBeacon("/store-token", JSON.stringify(tokenData));
})
.catch(console.error);Reporting Offline Conversions
Once you have a browser token, you can use it to report offline conversions via
the Quantcast Offline Conversion API. This is done by making a POST request to
the /conversion endpoint. The user object in the request body should contain
the token.
Example API Call
Here is an example of how to report a conversion using curl:
curl -X POST -H 'Content-Type: application/json' -d \
'[{ "user": { "token": "<token>" }, "name": "Conversion API TEST" }]' \
'https://pixel.quantserve.com/conversion?a=p-YOUR_ACCOUNT_ID'For more details on the Offline Conversion API and its parameters, please refer to the official Quantcast API documentation.
