@lingxiads/smartads-sdk-js
v0.0.10
Published
Lingxi Smart Ads SDK for JavaScript
Downloads
244
Readme
SmartAds SDK for JavaScript
Lightweight JavaScript SDK for SmartAds event tracking and attribution reporting. Works seamlessly in vanilla HTML pages.
Quick Start
Script Tag
<script src="https://unpkg.com/@lingxiads/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, EVENT_PWA_ACTIVATE |
| 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);
},
);