监测事件 您可以将Adjust 事件识别码 关联至应用内行为,以此对其进行监测。要监测事件:
创建一个新的 Adjust 事件实例并将事件识别码作为 string argument 进行发送。 使用事件实例作为 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('TrackSimple Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
您可以通过在实例上设定revenue (收入)
和currency (币种)
属性来监测与事件关联的收入。使用此功能来在应用内监测产生收入的行为。
要设置这些属性,可以调用setRevenue
方法并传递以下 argument:
revenue (收入)
值 ( 数字 )currency (币种)
代码 ( 字符串 )币种代码的格式须为 3 个字符且遵循ISO 4217 标准 。Adjust 后端会将收入换算为您选定的报告币种。欢迎查看我们的跟踪不同币种的购买 一文,了解更多信息。
AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
adjustEvent.setRevenue(0.01,'EUR');
//...
Adjust.trackEvent(myAdjustEvent);
如果您正在监测应用内购买,请在购买完成
之后 再调用
trackEvent
。
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有 g3mfiw
标签的事件。我们将此事件的收入
设为 0.25
且币种
属性设置为 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';
// Track revenue event button.
Util.buildCupertinoButton('TrackRevenue Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
您也可以发送一个可选的交易标识符,以避免监测重复事件。SDK 会存储最近 10 个标识符,带有重复交易 ID 的收入事件会被跳过。
要设置标识符,请调用transactionId
方法并将交易 ID 作为 string argument。
AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
myAdjustEvent.transactionId= '{TransactionId}';
//...
Adjust.trackEvent(myAdjustEvent);
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有 g3mfiw
标签的事件。我们创建一个字符串变量,名称为 uniqueId
,值为 5e85484b-1ebc-4141-aab7-25b869e54c49
。随后,我们将此值发送到transactionId
方法来设定TransactionId
属性。
// 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';
// Track revenue event button.
Util.buildCupertinoButton('TrackRevenue Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
您在 Adjust 控制面板中为事件注册回传 URL ,SDK 监测到事件后,Adjust 会向您的回传 URL 发送一个 GET 请求。
您可以为自己的服务器设置回传参数。配置好事件的参数后,SDK 会将参数附加至您的回传 URL 。您可以利用该信息,通过自己的 BI 系统分析用户应用内行为。
使用 字符串 键值对 argument 调用addCallbackParameter
方法,以此向事件添加回传参数。多次调用该方法可添加多个参数。
AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
adjustEvent.addCallbackParameter('key','value');
//...
Adjust.trackEvent(myAdjustEvent);
Adjust SDK 监测事件,并向附加回传参数的 URL 发送请求。例如,如果您注册了 URLhttp://www.mydomain.com/callback
,则回传为:
http://www.mydomain.com/callback?key=value&foo=bar
如果您使用的是 CSV 上传,请务必在 CSV 定义中添加参数 。
Adjust 支持许多占位符,这些占位符可用来将信息从 SDK 发送至您的 URL。例如,iOS 的{idfa}
占位符和安卓的{gps_adid}
占位符。{publisher_parameter}
占位符可在单一字符串中呈现所有回传参数。
若想进一步了解 URL 回传,查看可用参数的完整列表,请参阅我们的回传指南 。
Adjust 不会存储您的自定义回传参数。自定义回传参数只会附加在您的回传 URL 中。
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有 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';
// Track callback event button.
Util.buildCupertinoButton('TrackCallback Event',
() => Adjust.trackEvent(Util.buildCallbackEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
您可以添加合作伙伴参数 ,向渠道合作伙伴发送额外的信息。
Adjust 可向您设置的外部合作伙伴 发送合作伙伴参数。这些信息可用来进行更精细的数据分析,开展再营销活动。您设置好参数并为合作伙伴启用参数转发后,后端就会将这些参数转发给合作伙伴。
合作伙伴参数不会默认出现在原始数据中。您可以添加
{partner_parameters}
占位符,在同一个字符串中接收参数。
使用 字符串 键值对 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';
// Track partner event button.
Util.buildCupertinoButton('TrackPartner Event',
() => Adjust.trackEvent(Util.buildPartnerEvent())),
const Padding(padding: const EdgeInsets.all(7.0))
您可以为想要监测的每个事件添加自定义字符串标识符。Adjust 后端将在事件回传中报告该标识符。这样就能了解哪些事件已经被成功监测。
通过调用callbackId
方法来设置标识符,使用您的 ID 作为 string argument。
AdjustEvent myAdjustEvent = new AdjustEvent('abc123');
//...
myAdjustEvent.callbackId = '{your_callback_id}';
//...
Adjust.trackEvent(myAdjustEvent);
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有 g3mfiw
标签的事件。我们创建一个字符串变量,名称为 callbackId
,值为 f2e728d8-271b-49ab-80ea-27830a215147
。随后,我们将此值发送到callbackId
方法来设定callbackId
属性。
// 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('TrackSimple Event',
() => Adjust.trackEvent(Util.myAdjustEvent())),
const Padding(padding: const EdgeInsets.all(7.0))