Getting started with the Web SDK
This guide walks you through the initial setup of the Adtrace Web SDK. You will install the SDK, initialize it on each page load, set attribution data, and verify that installs are recorded.
Example apps: framework examples, demo app.
1. Add the Adtrace SDK
Add the Adtrace Web SDK to your site or web app using a script tag or NPM.
The SDK works with CommonJS, AMD, and global Adtrace when loaded through a <script> tag.
Script tag (CDN or self-hosted)
Paste this into your page <head>. Load the SDK once per page:
<script type="application/javascript" src="./dist/adtrace-latest.min.js"></script>
Replace the path with your hosted copy or build output. Check the releases page for the latest version.
NPM
npm install web-adtrace --save
import Adtrace from 'web-adtrace';
2. Initialize the SDK
Call Adtrace.initSdk as early as possible on each page load. The SDK should be initialized once per page load.
Required parameters
| Parameter | Type | Description |
|---|---|---|
appToken | string | Your app token from the Adtrace panel. |
environment | string | sandbox for testing, production for live traffic. |
Example
Adtrace.initSdk({
appToken: '{YourAppToken}',
environment: 'sandbox',
logLevel: 'verbose',
});
Optional configuration
Pass additional read-only options in the same object. See Configuration for:
- Log level
- External device ID
- Default tracker
- Namespace
- Event deduplication limit
- Data residency
- Custom URL
Register an attribution callback in initSdk if you need install or reattribution notifications.
3. Set referrer
For proper attribution, call setReferrer as close as possible to initialization:
Adtrace.setReferrer('adtrace_external_click_id%3DEXTERNAL_CLICK_ID');
The referrer string must be URL-encoded.
4. Test the integration
A successful install (first session in a browser profile) must be recorded before sessions and events appear correctly in Adtrace.
Prepare a clean test environment
To simulate a fresh install:
- Clear browser storage completely (
localStorageand IndexedDB used by the SDK). - Set
environment: 'sandbox'andlogLevel: 'verbose'ininitSdk. - Load the page and wait for the first session to be sent.
Test with logs
- Open the browser developer console.
- After first open, search logs for an
adidvalue in SDK responses.
"adid": "mhxd6or7d3u57fnbdy2r4urdrdxr7tlr"
Receiving adid means the install was recorded. If you do not see adid, review the setup steps and the example apps.
Test in the Adtrace panel
- Read
web_uuidwithAdtrace.getWebUUID(). - Open Settings → Testing Console in the Adtrace panel.
- Enter the
web_uuidand check whether an install is recorded.
7c67ef26-830e-49b7-8948-b868b19bf4b3
Test with attribution callback
If you set attributionCallback in initSdk, the callback should fire after install. When attribution.adid is present, the install was tracked successfully.
See Send callback information.
5. Track events
After install is verified, track events with Adtrace.trackEvent. See Track events.
Adtrace.trackEvent({
eventToken: '{YourEventToken}',
});
6. Build for production
Before you ship:
- Set
environmenttoproduction. - Set
logLeveltoerrorornone.
Adtrace.initSdk({
appToken: '{YourAppToken}',
environment: 'production',
logLevel: 'error',
});