adjust-icon

Send event information

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

Instantiate an AdjustEvent object

Method signature
constructor(eventToken: string)

To send event information with the Adjust SDK, you need to instantiate an AdjustEvent object. This object contains variables that are sent to Adjust when an event occurs in your app.

To instantiate an event object, create a new AdjustEvent instance and pass the following parameters:

var adjustEvent = new AdjustEvent("abc123");
Adjust.trackEvent(adjustEvent);

Send an event

Method signature
trackEvent(adjustEvent: AdjustEvent): void

You can associate your Adjust event tokens to actions in your app to record them. To record an event:

  • Create a new Adjust event instance and pass your event token as a string argument.
  • Call the trackEvent method with your event instance as an argument.
var adjustEvent = new AdjustEvent("abc123");
Adjust.trackEvent(adjustEvent);

Example

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

index.js
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent("deviceready");
var adjustConfig = new AdjustConfig(
"YourAppToken",
AdjustConfig.EnvironmentSandbox,
);
Adjust.initSdk(adjustConfig);
},
receivedEvent: function (id) {
console.log("Received Event: " + id);
var btnRecordSimpleEvent = document.getElementById(
"btnRecordSimpleEvent",
);
btnRecordSimpleEvent.addEventListener(
"click",
function () {
var adjustEvent = new AdjustEvent("g3mfiw");
Adjust.trackEvent(adjustEvent);
},
false,
);
},
};
app.initialize();
Event log
Path: /event
ClientSdk: cordova5.0.3
Parameters:
android_uuid 781f17d5-5048-4fae-a4e5-77b58bab62b9
api_level 34
app_token 2fm9gkqubvpc
15 collapsed lines
app_version 1.0
attribution_deeplink 1
connectivity_type 1
country US
cpu_type arm64-v8a
created_at 2024-01-25T14:13:16.151Z+0100
device_manufacturer Google
device_name sdk_gphone64_arm64
device_type phone
display_height 2205
display_width 1080
environment sandbox
event_buffering_enabled 0
event_count 3
event_token g3mfiw
gps_adid 5962dfc1-3a53-4692-850b-22c4bf4311a5
gps_adid_attempt 2
19 collapsed lines
gps_adid_src service
hardware_name UE1A.230829.036
language en
mcc 310
mnc 260
needs_response_details 1
os_build UE1A.230829.036
os_name android
os_version 14
package_name com.adjust.examples
screen_density high
screen_format long
screen_size normal
session_count 2
session_length 23
subsession_count 1
time_spent 23
tracking_enabled 1
ui_mode 1

Record event revenue

Method signature
setRevenue(revenue: number, currency: string): void

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 setRevenue 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.
var adjustEvent = new AdjustEvent("abc123");
adjustEvent.setRevenue(0.01, "EUR");
Adjust.trackEvent(adjustEvent);

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.

index.js
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent("deviceready");
var adjustConfig = new AdjustConfig(
"YourAppToken",
AdjustConfig.EnvironmentSandbox,
);
Adjust.initSdk(adjustConfig);
},
receivedEvent: function (id) {
console.log("Received Event: " + id);
var btnRecordRevenueEvent = document.getElementById(
"btnRecordRevenueEvent",
);
btnRecordRevenueEvent.addEventListener(
"click",
function () {
var adjustEvent = new AdjustEvent("g3mfiw");
adjustEvent.setRevenue(0.25, "EUR");
Adjust.trackEvent(adjustEvent);
},
false,
);
},
};
app.initialize();
Event log
Path: /event
ClientSdk: cordova5.0.3
Parameters:
environment sandbox
event_count 3
event_token g3mfiw
revenue 0.25
currency EUR

Deduplicate revenue events

Method signature
setDeduplicationId(deduplicationId: string): void

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

To set the identifier, call the setDeduplicationId method and pass your deduplication ID as a string argument.

var adjustEvent = new AdjustEvent("abc123");
adjustEvent.setDeduplicationId(deduplicationId);
Adjust.trackEvent(adjustEvent);

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 using the setDeduplicationId method.

index.js
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent("deviceready");
var adjustConfig = new AdjustConfig(
"YourAppToken",
AdjustConfig.EnvironmentSandbox,
);
Adjust.initSdk(adjustConfig);
},
receivedEvent: function (id) {
console.log("Received Event: " + id);
var btnRecordUniqueEvent = document.getElementById(
"btnRecordUniqueEvent",
);
btnRecordUniqueEvent.addEventListener(
"click",
function () {
var adjustEvent = new AdjustEvent("g3mfiw");
adjustEvent.setDeduplicationId(
"5e85484b-1ebc-4141-aab7-25b869e54c49",
);
Adjust.trackEvent(adjustEvent);
},
false,
);
},
};
app.initialize();
Event log
Path: /event
ClientSdk: cordova5.0.3
Parameters:
environment sandbox
event_count 3
event_token g3mfiw
deduplication_id 5e85484b-1ebc-4141-aab7-25b869e54c49

Add callback parameters

Method signature
addCallbackParameter(key: string, value: string): void

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 calling the addCallbackParameter method with string key-value arguments. You can add multiple parameters by calling this method multiple times.

var adjustEvent = new AdjustEvent("abc123");
adjustEvent.addCallbackParameter("key", "value");
adjustEvent.addCallbackParameter("foo", "bar");
Adjust.trackEvent(adjustEvent);

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. For example, the {idfa} placeholder for iOS and the {gps_adid} placeholder for Android. 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
index.js
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent("deviceready");
var adjustConfig = new AdjustConfig(
"YourAppToken",
AdjustConfig.EnvironmentSandbox,
);
Adjust.initSdk(adjustConfig);
},
receivedEvent: function (id) {
console.log("Received Event: " + id);
var btnRecordCallbackEvent = document.getElementById(
"btnRecordCallbackEvent",
);
btnRecordCallbackEvent.addEventListener(
"click",
function () {
var adjustEvent = new AdjustEvent("g3mfiw");
adjustEvent.addCallbackParameter("event_token", "g3mfiw");
adjustEvent.addCallbackParameter("revenue_amount", "0.05");
Adjust.trackEvent(adjustEvent);
},
false,
);
},
};
app.initialize();
Event log
Path: /event
ClientSdk: cordova5.0.3
Parameters:
callback_params {"event_token":"g3mfiw","revenue_amount":"0.05"}
environment sandbox
event_count 1
event_token g3mfiw

Add partner parameters

Method signature
addPartnerParameter(key: string, value: string): void

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 calling the addPartnerParameter method with string key-value arguments. You can add multiple parameters by calling this method multiple times.

var adjustEvent = new AdjustEvent("abc123");
adjustEvent.addPartnerParameter("key", "value");
adjustEvent.addPartnerParameter("foo", "bar");
Adjust.trackEvent(adjustEvent);

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
index.js
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent("deviceready");
var adjustConfig = new AdjustConfig(
"YourAppToken",
AdjustConfig.EnvironmentSandbox,
);
Adjust.initSdk(adjustConfig);
},
receivedEvent: function (id) {
console.log("Received Event: " + id);
var btnRecordPartnerParamEvent = document.getElementById(
"btnRecordPartnerParamEvent",
);
btnRecordPartnerParamEvent.addEventListener(
"click",
function () {
var adjustEvent = new AdjustEvent("g3mfiw");
adjustEvent.addPartnerParameter("product_id", "29");
adjustEvent.addPartnerParameter("user_id", "835");
Adjust.trackEvent(adjustEvent);
},
false,
);
},
};
app.initialize();
Event log
Path: /event
ClientSdk: cordova5.0.3
Parameters:
partner_params {"product_id":"29","user_id":"835"}
environment sandbox
event_count 1
event_token g3mfiw

Add a callback identifier

Method signature
setCallbackId(callbackId: string): void

You can add a custom string identifier to each event you want to measure. Adjust’s servers can report on this identifier in event callbacks. This enables you to keep track of which events have been successfully measured.

Set up this identifier by calling the setCallbackId method with the following argument:

  • callbackId (string): your unique callback ID.
var adjustEvent = new AdjustEvent("abc123");
adjustEvent.setCallbackId("Your-Custom-Id");
Adjust.trackEvent(adjustEvent);

Example

This example shows how to record an event with the token g3mfiw whenever a user interacts with a button. In this example, the callbackId is set to f2e728d8-271b-49ab-80ea-27830a215147.

index.js
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
bindEvents: function () {
document.addEventListener("deviceready", this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent("deviceready");
var adjustConfig = new AdjustConfig(
"YourAppToken",
AdjustConfig.EnvironmentSandbox,
);
Adjust.initSdk(adjustConfig);
},
receivedEvent: function (id) {
console.log("Received Event: " + id);
var btnRecordCallbackIdEvent = document.getElementById(
"btnRecordCallbackIdEvent",
);
btnRecordCallbackIdEvent.addEventListener(
"click",
function () {
var adjustEvent = new AdjustEvent("g3mfiw");
adjustEvent.setCallbackId("f2e728d8-271b-49ab-80ea-27830a215147");
Adjust.trackEvent(adjustEvent);
},
false,
);
},
};
app.initialize();
Event log
Path: /event
ClientSdk: cordova5.0.3
Parameters:
environment sandbox
event_count 3
event_token g3mfiw
callback_id f2e728d8-271b-49ab-80ea-27830a215147