adjust-icon

Send event information

The Adjust SDK provides an event interface which can be used to structure and send event information from your app to Adjust’s servers.

Interface declaration
export type EventParamsT = {|
eventToken: string,
revenue?: number,
currency?: string,
deduplicationId?: string,
callbackParams?: Array<GlobalParamsT>,
partnerParams?: Array<GlobalParamsT>,
|};

Send an event

To send an event, call the Adjust.trackEvent method and pass your Adjust event token as an argument.

Adjust.trackEvent({
eventToken: "{YourEventToken}",
});

Example

This example shows how to record an event with the token g3mfiw whenever a user interacts with a button.

function init(defaultEventConfig = {}) {
_ui.trackEventButton.addEventListener("click", _handleTrackEvent, false);
}
// ...
function _handleTrackEvent() {
const eventConfig = getItem("eventConfig") || { ..._defaultEventConfig };
if (_disabled) {
return;
}
_disabled = true;
_ui.trackEventButton.classList.add("loading");
_ui.trackEventButton.disabled = true;
clearTimeout(_timeoutId);
_timeoutId = setTimeout(() => {
_disabled = false;
_ui.trackEventButton.classList.remove("loading");
_ui.trackEventButton.disabled = false;
Adjust.trackEvent({
eventToken: "g3mfiw",
});
});
}

Record event revenue

You can record revenue associated with an event by setting the revenue and currency properties on your event instance. Use this feature to record revenue-generating actions in your app.

To set these properties, call the Adjust.trackEvent method and pass the following arguments:

  • revenue (number): The amount of revenue generated by the event
  • currency (string): The ISO 4217 code of the event currency.

You must format the currency code as a 3 character string that follows the ISO 4217 standard. Adjust’s servers convert the reported revenue to your chosen reporting currency.

Adjust.trackEvent({
// ... other params go here, including mandatory ones
revenue: 110,
currency: "EUR",
});

Example

This example shows how to record an event with the token g3mfiw whenever a user interacts with a button. The function sets the revenue property of this event to 0.25 and the currency property to EUR.

function init(defaultEventConfig = {}) {
_ui.trackRevenueEventButton.addEventListener(
"click",
_handleTrackEvent,
false,
);
}
//...
function _handleTrackEvent() {
const eventConfig = getItem("eventConfig") || { ..._defaultEventConfig };
if (_disabled) {
return;
}
_disabled = true;
_ui.trackRevenueEventButton.classList.add("loading");
_ui.trackRevenueEventButton.disabled = true;
clearTimeout(_timeoutId);
_timeoutId = setTimeout(() => {
_disabled = false;
_ui.trackRevenueEventButton.classList.remove("loading");
_ui.trackRevenueEventButton.disabled = false;
Adjust.trackEvent({
eventToken: "g3mfiw",
revenue: 0.25,
currency: "EUR",
});
});
}

Deduplicate revenue events

You can pass an optional identifier to avoid measuring duplicate events. The SDK stores the last 10 identifiers and skips revenue events with duplicate transaction IDs.

To configure this, set the deduplicationId property to your transaction ID.

Adjust.trackEvent({
// ... other params go here, including mandatory ones
deduplicationId: "{YourDeduplicationId}",
});

Example

This example shows how to record an event with the token g3mfiw whenever a user interacts with a button. The function sets the deduplicationId to 5e85484b-1ebc-4141-aab7-25b869e54c49.

function init(defaultEventConfig = {}) {
_ui.trackUniqueEventButton.addEventListener(
"click",
_handleTrackEvent,
false,
);
}
//...
function _handleTrackEvent() {
const eventConfig = getItem("eventConfig") || { ..._defaultEventConfig };
if (_disabled) {
return;
}
_disabled = true;
_ui.trackUniqueEventButton.classList.add("loading");
_ui.trackUniqueEventButton.disabled = true;
clearTimeout(_timeoutId);
_timeoutId = setTimeout(() => {
_disabled = false;
_ui.trackUniqueEventButton.classList.remove("loading");
_ui.trackUniqueEventButton.disabled = false;
Adjust.trackEvent({
eventToken: "g3mfiw",
deduplicationId: "5e85484b-1ebc-4141-aab7-25b869e54c49",
});
});
}

You can override the deduplication limit to change the number of identifiers the Adjust SDK stores. To do this, specify the new limit in the eventDeduplicationListLimit argument of the initSdk method.

Adjust.initSdk({
appToken: "YOUR_APP_TOKEN",
environment: "sandbox",
eventDeduplicationListLimit: 20,
});

Add callback parameters

Interface declaration
export type GlobalParamsT = {|
key: string,
value: string,
|};

If you register a callback URL in the Adjust dashboard, the SDK sends a GET request to your callback URL when it records an event.

You can configure callback parameters to send to your servers. Once you configure parameters on an event, the SDK appends them to your callback URL. You can use this information to analyze your users’ in-app behavior with your BI system.

Add callback parameters to your event by creating a callbackParams array containing GlobalParam objects.

Adjust.trackEvent({
// ... other params go here, including mandatory ones
callbackParams: [
{ key: "key", value: "value" },
{ key: "foo", value: "bar" },
],
});

The Adjust SDK measures the event and sends a request to your URL with the callback parameters. For example, if you register the URL https://www.mydomain.com/callback, your callback looks like this:

https://www.mydomain.com/callback?key=value&foo=bar

If you’re using CSV uploads, make sure to add the parameters to your CSV definition.

Adjust supports many placeholders which you can use to pass information from the SDK to your URL. The {publisher_parameter} placeholder presents all callback parameters in a single string.

Example

This example shows how to record an event with the token g3mfiw whenever a user interacts with a button. The following callback parameters are added:

  • The event_token
  • The revenue_amount generated by the event

The resulting callback URL looks like this:

http://www.mydomain.com/callback?event_token=g3mfiw&revenue_amount=0.05
function init(defaultEventConfig = {}) {
_ui.trackCallbackEventButton.addEventListener(
"click",
_handleTrackEvent,
false,
);
}
//...
function _handleTrackEvent() {
const eventConfig = getItem("eventConfig") || { ..._defaultEventConfig };
if (_disabled) {
return;
}
_disabled = true;
_ui.trackCallbackEventButton.classList.add("loading");
_ui.trackCallbackEventButton.disabled = true;
clearTimeout(_timeoutId);
_timeoutId = setTimeout(() => {
_disabled = false;
_ui.trackCallbackEventButton.classList.remove("loading");
_ui.trackCallbackEventButton.disabled = false;
Adjust.trackEvent({
eventToken: "g3mfiw",
callbackParams: [
{ key: "eventToken", value: "g3mfiw" },
{ key: "revenue_amount", value: "0.05" },
],
});
});
}

Add partner parameters

Interface declaration
export type GlobalParamsT = {|
key: string,
value: string,
|};

You can send extra information to your network partners by adding partner parameters.

Adjust sends partner parameters to external partners you have set up. This information is useful for more granular analysis and retargeting purposes. Adjust’s servers forward these parameters once you have set them up and enabled them for a partner.

Add partner parameters to your event by creating a partnerParams array containing GlobalParam objects.

Adjust.trackEvent({
// ... other params go here, including mandatory ones
partnerParams: [
{ key: "key", value: "value" },
{ key: "foo", value: "bar" },
],
});

Example

This example shows how to record an event with the token g3mfiw whenever a user interacts with a button. The following partner parameters are added:

  • The product_id of the associated product
  • The user_id of the user who triggered the event
function init(defaultEventConfig = {}) {
_ui.trackPartnerEventButton.addEventListener(
"click",
_handleTrackEvent,
false,
);
}
//...
function _handleTrackEvent() {
const eventConfig = getItem("eventConfig") || { ..._defaultEventConfig };
if (_disabled) {
return;
}
_disabled = true;
_ui.trackPartnerEventButton.classList.add("loading");
_ui.trackPartnerEventButton.disabled = true;
clearTimeout(_timeoutId);
_timeoutId = setTimeout(() => {
_disabled = false;
_ui.trackPartnerEventButton.classList.remove("loading");
_ui.trackPartnerEventButton.disabled = false;
Adjust.trackEvent({
eventToken: "g3mfiw",
partnerParams: [
{ key: "product_id", value: "29" },
{ key: "user_id", value: "835" },
],
});
});
}

Record event and redirect to an external page

Method signature
function trackEvent(params: EventParamsT): Promise<void> {
return _internalTrackEvent(params);
}

You can record redirects to external pages as events with the Adjust SDK. To ensure the SDK records the event before the redirect happens, the trackEvent method returns a Promise. This Promise is fulfilled after the SDK receives a response from Adjust’s servers. If an internal error response is returned, the Promise is rejected.

The Adjust SDK saves events to an internal queue. This means that even if your request times out or an error occurs, the SDK preserves the event to retry later.

Example

Promise.race([
Adjust.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/";
});