adjust-icon

发送事件信息

Adjust SDK 提供一个 AdjustEvent 对象,用于架构并向 Adjust 服务器发送来自您应用的事件信息。

实例化 AdjustEvent 对象

方法签名
AdjustEvent(string eventToken)

要使用 Adjust SDK 发送事件信息,请实例化一个 AdjustEvent 对象。该对象中包含的变量会在应用中发生事件时被发送给 Adjust。

要实例化事件对象,请创建新的 AdjustEvent 实例,并传送下列参数:

AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
Adjust.trackEvent(myAdjustEvent);

发送事件

方法签名
static void trackEvent(AdjustEvent event)

您可以将Adjust 事件识别码关联至应用内行为,以此对其进行记录。要记录事件:

  • 创建一个新的 Adjust 事件实例并将事件识别码作为字符串参数进行发送。
  • 使用事件实例作为 argument 调用trackEvent方法。
AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
Adjust.trackEvent(myAdjustEvent);

示例

在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw标签的事件。

util.dart
import 'package:adjust_sdk/adjust_event.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Util {
static const String EVENT_TOKEN_SIMPLE = 'g3mfiw';
static Widget buildCupertinoButton(String text, Function action) {
return new CupertinoButton(
child: Text(text),
color: CupertinoColors.activeBlue,
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 30.0),
onPressed: action as void Function()?,
);
}
static AdjustEvent myAdjustEvent() {
return new AdjustEvent(EVENT_TOKEN_SIMPLE);
}
}
// main.dart
import 'util.dart';
Util.buildCupertinoButton('Track Simple Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
事件日志
Path: /event
ClientSdk: flutter4.38.1
Parameters:
android_uuid 781f17d5-5048-4fae-a4e5-77b58bab62b9
api_level 34
41 collapsed lines
app_token 2fm9gkqubvpc
app_version 1.0
attribution_deeplink 1
callback_params {"key":"value","foo":"bar"}
connectivity_type 1
country US
cpu_type arm64-v8a
created_at 2024-01-25T14:13:16.151Z+0100
currency EUR
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
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
partner_params {"key":"value","foo":"bar"}
revenue 0.25
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

记录事件收入

方法签名
void setRevenue(Num revenue, String currency)

您可以通过在实例上设定 revenue (收入) 和 currency (币种) 属性来记录与事件关联的收入。使用此功能来在应用内记录产生收入的行为。

要设置这些属性,可以调用 setRevenue 方法并传递以下参数:

  • revenue (num):事件产生的收入额
  • currency (String):事件币种的ISO 4217 代码
AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
adjustEvent.setRevenue(0.01, 'EUR');
//...
Adjust.trackEvent(myAdjustEvent);

示例

在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw标签的事件。该函数会将该事件的 revenue 属性设为 0.25 ,并将 currency 属性设为 EUR

util.dart
import 'package:adjust_sdk/adjust_event.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Util {
static const String EVENT_TOKEN_REVENUE = 'g3mfiw';
static Widget buildCupertinoButton(String text, Function action) {
return new CupertinoButton(
child: Text(text),
color: CupertinoColors.activeBlue,
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 30.0),
onPressed: action as void Function()?,
);
}
static AdjustEvent myAdjustEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_REVENUE);
event.setRevenue(0.25, 'EUR');
return event;
}
}
// main.dart
import 'util.dart';
// Send revenue event button.
Util.buildCupertinoButton('Send Revenue Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
事件日志
Path: /event
ClientSdk: flutter4.38.1
Parameters:
environment sandbox
event_count 3
event_token abc123
revenue 0.25
currency EUR

收入事件去重

属性声明
String? transactionId;

您也可以发送一个可选的标识符,以避免记录重复事件。SDK 会存储最近 10 个标识符,带有重复交易 ID 的收入事件会被跳过。

要设置标识符,请将您的交易 ID 指定至事件实例的 setTransactionId 属性。

AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
myAdjustEvent.transactionId = '{TransactionId}';
//...
Adjust.trackEvent(myAdjustEvent);

示例

在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw标签的事件。该函数会使用 setTransactionId 方法将 uniqueId 设为 5e85484b-1ebc-4141-aab7-25b869e54c49

util.dart
import 'package:adjust_sdk/adjust_event.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Util {
static const String EVENT_TOKEN_REVENUE = 'g3mfiw';
static const String UNIQUE_ID = '5e85484b-1ebc-4141-aab7-25b869e54c49';
static Widget buildCupertinoButton(String text, Function action) {
return new CupertinoButton(
child: Text(text),
color: CupertinoColors.activeBlue,
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 30.0),
onPressed: action as void Function()?,
);
}
static AdjustEvent myAdjustEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_REVENUE);
event.transactionId = UNIQUE_ID;
return event;
}
}
// main.dart
import 'util.dart';
// Send revenue event button.
Util.buildCupertinoButton('Send Revenue Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
事件日志
Path: /event
ClientSdk: flutter4.38.1
Parameters:
environment sandbox
event_count 3
event_token abc123
transaction_id 5e85484b-1ebc-4141-aab7-25b869e54c49

添加回传参数

方法签名
void addCallbackParameter(String key, String value)

您在 Adjust 控制面板中注册回传 URL,SDK 监测到事件后,会向您的回传 URL 发送一个 GET 请求。

您可以设置发送到服务器的回传参数。配置好事件的参数后,SDK 会将参数附加至您的回传 URL。您可以利用该信息,通过自己的 BI 系统分析用户应用内行为。

使用 String 键值对 argument 调用addCallbackParameter方法,以此向事件添加回传参数。多次调用该方法可添加多个参数。

AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
adjustEvent.addCallbackParameter('key', 'value');
//...
Adjust.trackEvent(myAdjustEvent);

Adjust SDK 监测事件,并向附加回传参数的 URL 发送请求。例如,如果您注册了 URLhttps://www.mydomain.com/callback,则回传为:

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

如果您使用的是 CSV 上传,请务必在 CSV 定义中添加参数。

Adjust 支持许多占位符,这些占位符可用来将信息从 SDK 发送至您的 URL。例如,iOS 的{idfa}占位符和安卓的{gps_adid}占位符。{publisher_parameter}占位符可在单一字符串中呈现所有回传参数。

示例

在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw标签的事件。以下回传参数被添加:

  • . event_token
  • 事件产生的 revenue_amount

产生的回传 URL 如下:

http://www.mydomain.com/callback?event_token=g3mfiw&revenue_amount=0.05
util.dart
import 'package:adjust_sdk/adjust_event.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Util {
static const String EVENT_TOKEN_CALLBACK = 'g3mfiw';
static Widget buildCupertinoButton(String text, Function action) {
return new CupertinoButton(
child: Text(text),
color: CupertinoColors.activeBlue,
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 30.0),
onPressed: action as void Function()?,
);
}
static AdjustEvent buildCallbackEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_CALLBACK);
event.addCallbackParameter('event_token', EVENT_TOKEN_CALLBACK);
event.addCallbackParameter('revenue_amount', '0.05');
return event;
}
}
// main.dart
import 'util.dart';
// Send callback event button.
Util.buildCupertinoButton('Send Callback Event',
() => Adjust.trackEvent(Util.buildCallbackEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
事件日志
Path: /event
ClientSdk: flutter4.38.1
Parameters:
callback_params {"event_token":"g3mfiw","revenue_amount":"0.05"}
environment sandbox
event_count 1
event_token g3mfiw

添加合作伙伴参数

方法签名
void addPartnerParameter(String key, String value)

您可以添加合作伙伴参数,向渠道合作伙伴发送额外的信息。

Adjust 可向您设置的外部合作伙伴发送合作伙伴参数。这些信息可用来进行更精细的数据分析,开展再营销活动。您设置好参数并为合作伙伴启用参数转发后,Adjust 服务器就会将这些参数转发给合作伙伴。

使用 String 键值对 argument 调用addPartnerParameter方法,以此向事件添加合作伙伴参数。多次调用该方法可添加多个参数。

AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
adjustEvent.addPartnerParameter('key', 'value');
//...
Adjust.trackEvent(myAdjustEvent);

示例

在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw标签的事件。以下合作伙伴参数被添加:

  • 相关产品的 product_id
  • 触发事件的用户 user_id
util.dart
import 'package:adjust_sdk/adjust_event.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Util {
static const String EVENT_TOKEN_PARTNER = 'g3mfiw';
static Widget buildCupertinoButton(String text, Function action) {
return new CupertinoButton(
child: Text(text),
color: CupertinoColors.activeBlue,
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 30.0),
onPressed: action as void Function()?,
);
}
static AdjustEvent buildPartnerEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_PARTNER);
event.addPartnerParameter('product_id', '29');
event.addPartnerParameter('user_id', '835');
return event;
}
}
// main.dart
import 'util.dart';
// Send partner event button.
Util.buildCupertinoButton('Send Partner Event',
() => Adjust.trackEvent(Util.buildPartnerEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
事件日志
Path: /event
ClientSdk: flutter4.38.1
Parameters:
partner_params {"product_id":"29","user_id":"835"}
environment sandbox
event_count 1
event_token g3mfiw

添加回传标识符

属性声明
String? callbackId;

您可以为想要监测的每个事件添加自定义字符串标识符。Adjust 服务器将在事件回传中报告该标识符。这样就能了解哪些事件已经被成功监测。

将您的 ID 指定给事件实例的 callbackId 属性,以设置该标识符。

AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
myAdjustEvent.callbackId = '{your_callback_id}';
//...
Adjust.trackEvent(myAdjustEvent);

示例

在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw标签的事件。在该示例中,callbackId 被设为了 f2e728d8-271b-49ab-80ea-27830a215147

util.dart
import 'package:adjust_sdk/adjust_event.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Util {
static const String EVENT_TOKEN_SIMPLE = 'g3mfiw';
static const String CALLBACK_ID = "f2e728d8-271b-49ab-80ea-27830a215147"
static Widget buildCupertinoButton(String text, Function action) {
return new CupertinoButton(
child: Text(text),
color: CupertinoColors.activeBlue,
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 30.0),
onPressed: action as void Function()?,
);
}
static AdjustEvent myAdjustEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_SIMPLE);
event.callbackId = CALLBACK_ID;
return event;
}
// main.dart
import 'util.dart';
Util.buildCupertinoButton('Send Callback Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
事件日志
Path: /event
ClientSdk: flutter4.38.1
Parameters:
environment sandbox
event_count 3
event_token g3mfiw
callback_id f2e728d8-271b-49ab-80ea-27830a215147