Event Tracking
Before sending any event ensure that the “install” has been successfully tracked. If an “install” is not recorded for the app on a device, Adtrace will receive and store your events, but they will NOT appear in the panel statistics.
Simple Event
You can use adtrace to track events. Let's say you want to track every tap on a particular button.
You would create a new event token in your panel, which has an associated event token - looking something like abc123.
In order to track this event from your web app, you should do following:
Adtrace.trackEvent({
eventToken: 'YOUR_EVENT_TOKEN'
})
Make sure to track event only after you initialize the Adtrace SDK.
Here is the full list of available parameters for the trackEvent method:
Mandatory params
eventToken string
Track event method requires this parameter, make sure to provide valid event token
Optional params
revenue number
In case you want to attach revenue to an event (for example you would like to track some purchase that happened inside your web app)
then you need to provide positive value for this param. It's also mandatory to provide currency param described in the next block
currency string
You need to provide this param if you want to track revenue event. Please use valid currency code like IRR, USD and so on
Example:
Adtrace.trackEvent({
// ... other params go here, including mandatory ones
revenue: 10,
currency: 'IRR'
})
callbackParams array
You can register a callback URL for your events in your panel. We will send a GET request to that URL whenever the event is tracked.
You can add callback parameters to that event by adding callbackParams parameter to the map object passed to trackEvent method.
We will then append these parameters to your callback URL.
Adtrace.trackEvent({
// ... other params go here, including mandatory ones
callbackParams: [
{key: 'key', value: 'value'},
{key: 'foo', value: 'bar'}
]
})
In that case we would track the event and send a request to:
https://www.mydomain.com/callback?key=value&foo=bar
Please note that we don't store any of your custom parameters, but only append them to your callbacks, thus without a callback they will not be saved nor sent to you.
You can read more about using URL callbacks, including a full list of available values, in our callbacks guide.
partnerParams array (SDK ONLY)
You can also add parameters to be transmitted to network partners, which have been activated in your Adtrace panel.
This works similarly to the callback parameters mentioned above,
but can be added by adding partnerParams parameter to the map object passed to trackEvent method:
Adtrace.trackEvent({
// ... other params go here, including mandatory ones
partnerParams: [
{key: 'key', value: 'value'},
{key: 'foo', value: 'bar'}
]
})
valueParams array
You can also add parameters to be transmitted to network values, which have been activated in your Adtrace panel.
This works similarly to the callback parameters mentioned above,
but can be added by adding valueParams parameter to the map object passed to trackEvent method:
Adtrace.trackEvent({
// ... other params go here, including mandatory ones
valueParams: [
{key: 'key', value: 'value'},
{key: 'foo', value: 'bar'}
]
})
deduplicationId string
It's possible to provide event deduplication id in order to avoid tracking duplicated events. Deduplication list limit is set in initialization configuration as described.
Event promise
In case you want to execute and action after event tracked.
for this case to avoid redirect to happen earlier than the event was actually tracked
trackEvent method returns a Promise which is fulfilled after the SDK has sent the event and received a response from the backend
and rejected when some internal error happen.
It might take pretty much time until this promise is settled so it's recommended to use a timeout.
Please note that due to internal requests queue the event wouldn't be lost even if it timed out or an error happened, the SDK will preserve the event to the next time it's loaded and try to send it again.
Example:
Promise
.race([
Adtrace.trackEvent({
eventToken: 'YOUR_EVENT_TOKEN',
// ... other event parameters
}),
new Promise((resolve, reject) => {
setTimeout(() => reject('Timed out'), 2000)
})
])
.catch(error => {
// ...
})
.then(() => {
// ... perform redirect, for example
window.location.href = "https://www.example.org/"
});