@bigbeakads/smartads-sdk-js
v0.0.6
Published
BigBeak Smart Ads SDK for JavaScript
Readme
SmartAds SDK for JavaScript
Lightweight JavaScript SDK for SmartAds event tracking and attribution reporting. Supports both ES Module and UMD formats, works seamlessly in modern frameworks and vanilla HTML pages.
Quick Start
ES Module
npm install @bigbeakads/smartads-sdk-jsimport SmartAds from '@bigbeakads/smartads-sdk-js';
const smartAds = new SmartAds({
accessToken: 'YOUR_ACCESS_TOKEN',
});
const smartId = new URL(window.location.href).searchParams.get('smartId');
await smartAds.report({
smartId: smartId,
eventName: 'EVENT_CONTENT_VIEW',
});UMD (Script Tag)
<script src="https://unpkg.com/@bigbeakads/smartads-sdk-js/dist/umd/smartads-sdk-js.min.js"></script>
<script>
const smartAds = new SmartAds({
accessToken: 'YOUR_ACCESS_TOKEN',
});
const smartId = new URL(window.location.href).searchParams.get('smartId');
smartAds.report({
smartId: smartId,
eventName: 'EVENT_CONTENT_VIEW',
});
</script>API Reference
new SmartAds(options)
Creates a SmartAds SDK instance.
| Parameter | Type | Required | Description |
| --------------------- | -------- | -------- | ----------------------------- |
| options.accessToken | string | Yes | Your application access token |
smartAds.report(options, callback?)
Reports an event to the SmartAds server. Returns a Promise<Response>. Supports both Promise and callback patterns.
Note: When users are redirected to your landing page, a
smartIdparameter will be included in the URL. You should extract this value and pass it to thereportmethod.
Parameters
| Parameter | Type | Required | Default | Description |
| ----------- | -------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| smartId | string | Yes | — | Smart ID, obtained from URL parameters |
| eventName | EventName| Yes | — | The event name to report. Supported values: EVENT_ADD_TO_CART, EVENT_PURCHASE, EVENT_CONTENT_VIEW, EVENT_COMPLETE_REGISTRATION, EVENT_FIRST_DEPOSIT, EVENT_INITIATE_CHECKOUT |
| currency | string | No | — | Currency code, e.g. USD |
| value | number | No | — | Value amount, e.g. 2.99 |
Callback (Second Parameter)
| Parameter | Type | Required | Description |
| ---------- | -------------------- | -------- | ---------------- |
| callback | (response) => void | No | Response callback |
Promise Usage
const smartId = new URL(window.location.href).searchParams.get('smartId');
const response = await smartAds.report({
smartId: smartId,
eventName: 'EVENT_PURCHASE',
});
console.log('Response:', response);Callback Usage
const smartId = new URL(window.location.href).searchParams.get('smartId');
smartAds.report(
{
smartId: smartId,
eventName: 'EVENT_PURCHASE',
},
(response) => {
console.log('Response:', response);
},
);