Adjust SDK 提供一个 ADJEvent
对象,用于架构并向 Adjust 服务器发送来自您应用的事件信息。
实例化 ADJEvent 对象
+ (nullable ADJEvent *)eventWithEventToken:(nonnull NSString *)eventToken;
要使用 Adjust SDK 发送事件信息,请实例化一个 ADJEvent
对象。该对象中包含的变量会在应用中发生事件时被发送给 Adjust。
要实例化事件对象,请创建新的 ADJEvent
实例,并传送下列参数:
eventToken
(NSString
):您的 Adjust 事件识别码。
let event = ADJEvent(eventToken: "abc123")Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent("abc123");Adjust.trackEvent(adjustEvent);
发送事件
+ (void)trackEvent:(nullable ADJEvent *)event;
您可以将Adjust 事件识别码关联至应用内行为,以此对其进行记录。要记录事件:
- 创建一个新的 Adjust 事件实例并将事件识别码作为字符串参数进行发送。
- 使用事件实例作为 argument 调用
trackEvent
方法。
let event = ADJEvent(eventToken: "abc123")Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent("abc123");Adjust.trackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。
import Adjustimport UIKit
class ViewControllerSwift: UIViewController { @IBOutlet weak var btnRecordEventSimple: UIButton?
@IBAction func btnRecordEventSimple(_sender: UIButton) { let event = ADJEvent(eventToken: "g3mfiw"); Adjust.trackEvent(event); }}
#import "Adjust.h"#import "Constants.h"#import "ViewControllerObjC.h"
@interface ViewControllerObjC ()
@property (weak, nonatomic) IBOutlet UIButton *btnRecordDeduplicatedEvent;
@end
@implementation ViewControllerObjC
- (IBAction)clickRecordSimpleEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken: @"g3mfiw"];
[Adjust trackEvent:event];}
@end
<html> <body> <script> setupWebViewJavascriptBridge(function(bridge) { let adjustConfig = new AdjustConfig('2fm9gkqubvpc', AdjustConfig.EnvironmentSandbox); adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
Adjust.appDidLaunch(adjustConfig);
var btnRecordDeduplicatedEvent = document.getElementById('btnRecordDeduplicatedEvent') btnRecordDeduplicatedEvent.onclick = function(e) { e.preventDefault() var adjustEvent = new AdjustEvent('g3mfiw') Adjust.trackEvent(adjustEvent) } } </script> <div id="buttons"> <div style="width:300px;height:35px;text-align:center;"> <button id="btnRecordDeduplicatedEvent">Record simple event</button> </div> </div> </body></html>
Path: /eventClientSdk: ios4.38.4Parameters: app_token 2fm9gkqubvpc app_version 1.035 collapsed lines
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 Apple device_type phone display_height 2205 display_width 1080 environment sandbox event_buffering_enabled 0 event_count 3 event_token g3mfiw hardware_name UE1A.230829.036 language en mcc 310 mnc 260 needs_response_details 1 os_build UE1A.230829.036 os_name ios 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:(double)amount currency:(nonnull NSString *)currency;
您可以通过在实例上设定 revenue (收入) 和 currency (币种) 属性来记录与事件关联的收入。使用此功能来在应用内记录产生收入的行为。
要设置这些属性,可以调用 setRevenue
方法并传递以下参数:
revenue
(double
):事件产生的收入额currency
(NSString
):事件币种的ISO 4217 代码。
let event = ADJEvent(eventToken: "abc123")event?.setRevenue(0.01, currency: "EUR")Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[event setRevenue:0.01 currency:@"EUR"];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent(eventToken);adjustEvent.setRevenue(0.01, "EUR");Adjust.trackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。该函数会将该事件的 revenue
属性设为 0.25
,并将 currency
属性设为 EUR
。
import Adjustimport UIKit
class ViewControllerSwift: UIViewController { @IBOutlet weak var btnRecordEventRevenue: UIButton?
@IBAction func btnRecordEventRevenue(_sender: UIButton) { let event = ADJEvent(eventToken: "g3mfiw"); event?.setRevenue(0.25, currency: "EUR"); Adjust.trackEvent(event); }}
#import "Adjust.h"#import "Constants.h"#import "ViewControllerObjC.h"
@interface ViewControllerObjC ()
@property (weak, nonatomic) IBOutlet UIButton *btnRecordRevenueEvent;
@end
@implementation ViewControllerObjC
- (IBAction)clickRecordRevenueEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"g3mfiw"]; [event setRevenue:0.25 currency:@"EUR"]; [Adjust trackEvent:event];}
@end
<html> <body> <script> setupWebViewJavascriptBridge(function(bridge) { let adjustConfig = new AdjustConfig('2fm9gkqubvpc', AdjustConfig.EnvironmentSandbox); adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
Adjust.appDidLaunch(adjustConfig);
var btnRecordRevenueEvent = document.getElementById('btnRecordRevenueEvent') btnRecordRevenueEvent.onclick = function(e) { e.preventDefault() var adjustEvent = new AdjustEvent('g3mfiw') adjustEvent.setRevenue(0.25, 'EUR') Adjust.trackEvent(adjustEvent) } } </script> <div id="buttons"> <div style="width:300px;height:35px;text-align:center;"> <button id="btnRecordRevenueEvent">Record revenue event</button> </div> </div> </body></html>
Path: /eventClientSdk: ios4.38.4Parameters: environment sandbox event_count 3 event_token abc123 currency EUR revenue 0.25
收入事件去重
- (void)setTransactionId:(nonnull NSString *)transactionId;
您也可以发送一个可选的标识符,以避免记录重复事件。SDK 会存储最近 10 个标识符,带有重复交易 ID 的收入事件会被跳过。
要设置标识符,请将您的交易 ID 指定至事件实例的 setTransactionId
属性。
let event = ADJEvent(eventToken: "abc123")event?.setTransactionId(transaction.transactionIdentifier)Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[event setTransactionId:transaction.transactionIdentifier];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent(eventToken);adjustEvent.setTransactionId(orderId);Adjust.trackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。该函数会使用 setTransactionId
方法将 uniqueId
设为 5e85484b-1ebc-4141-aab7-25b869e54c49
。
import Adjustimport UIKit
class ViewControllerSwift: UIViewController { @IBOutlet weak var btnRecordEventSimple: UIButton?
@IBAction func btnRecordEventSimple(_sender: UIButton) { let event = ADJEvent(eventToken: "g3mfiw"); event.setTransactionId("5e85484b-1ebc-4141-aab7-25b869e54c49") Adjust.trackEvent(event); }}
#import "Adjust.h"#import "Constants.h"#import "ViewControllerObjC.h"
@interface ViewControllerObjC ()
@property (weak, nonatomic) IBOutlet UIButton *btnRecordDeduplicatedEvent;
@end
@implementation ViewControllerObjC
- (IBAction)clickRecordSimpleEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken: @"g3mfiw"]; [event setTransactionId: @"5e85484b-1ebc-4141-aab7-25b869e54c49"] [Adjust trackEvent:event];}
@end
<html> <body> <script> setupWebViewJavascriptBridge(function(bridge) { let adjustConfig = new AdjustConfig('2fm9gkqubvpc', AdjustConfig.EnvironmentSandbox); adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
Adjust.appDidLaunch(adjustConfig);
var btnRecordDeduplicatedEvent = document.getElementById('btnRecordDeduplicatedEvent') btnRecordDeduplicatedEvent.onclick = function(e) { e.preventDefault() var adjustEvent = new AdjustEvent('g3mfiw') adjustEvent.setTransactionId("5e85484b-1ebc-4141-aab7-25b869e54c49") Adjust.trackEvent(adjustEvent) } } </script> <div id="buttons"> <div style="width:300px;height:35px;text-align:center;"> <button id="btnRecordDeduplicatedEvent"> Record dedupicated event </button> </div> </div> </body></html>
Path: /eventClientSdk: ios4.38.4Parameters: environment sandbox event_count 3 event_token abc123 transaction_id 5e85484b-1ebc-4141-aab7-25b869e54c49
添加回传参数
- (void)addCallbackParameter:(nonnull NSString *)key value:(nonnull NSString *)value;
您在 Adjust 控制面板中注册回传 URL,SDK 监测到事件后,会向您的回传 URL 发送一个 GET 请求。
您可以设置发送到服务器的回传参数。配置好事件的参数后,SDK 会将参数附加至您的回传 URL。您可以利用该信息,通过自己的 BI 系统分析用户应用内行为。
使用 NSString
键值对 argument 调用addCallbackParameter
方法,以此向事件添加回传参数。多次调用该方法可添加多个参数。
let event = ADJEvent(eventToken: "abc123")event?.addCallbackParameter("key", value: "value")event?.addCallbackParameter("foo", value: "bar")Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[event addCallbackParameter:@"key" value:@"value"];[event addCallbackParameter:@"foo" value:@"bar"];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent(eventToken);adjustEvent.addCallbackParameter("key", "value");adjustEvent.addCallbackParameter("foo", "bar");Adjust.trackEvent(adjustEvent);
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
import Adjustimport UIKit
class ViewControllerSwift: UIViewController { @IBOutlet weak var btnRecordEventCallbacks: UIButton?
@IBAction func btnRecordEventCallbacks(_sender: UIButton) { let event = ADJEvent(eventToken: "g3mfiw"); event?.addCallbackParameter("event_token", value: "g3mfiw") event?.addCallbackParameter("revenue_amount", value: "0.05") Adjust.trackEvent(event); }}
#import "Adjust.h"#import "Constants.h"#import "ViewControllerObjC.h"
@interface ViewControllerObjC ()
@property (weak, nonatomic) IBOutlet UIButton *btnRecordCallbackEvent;
@end
@implementation ViewControllerObjC
- (IBAction)clickRecordCallbackEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"g3mfiw"]; [event addCallbackParameter:@"event_token" value:@"g3mfiw"]; [event addCallbackParameter:@"revenue_amount" value:@"0.05"]; [Adjust trackEvent:event];}
@end
<html> <body> <script> setupWebViewJavascriptBridge(function(bridge) { let adjustConfig = new AdjustConfig('2fm9gkqubvpc', AdjustConfig.EnvironmentSandbox); adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
Adjust.appDidLaunch(adjustConfig);
var btnRecordCallbackEvent = document.getElementById('btnRecordCallbackEvent') btnRecordCallbackEvent.onclick = function(e) { e.preventDefault() var adjustEvent = new AdjustEvent('g3mfiw'); adjustEvent.addCallbackParameter('event_token', 'g3mfiw'); adjustEvent.addCallbackParameter('revenue_amount', '0.05'); Adjust.trackEvent(adjustEvent); } } </script> <div id="buttons"> <div style="width:300px;height:35px;text-align:center;"> <button id="btnRecordCallbackEvent"> Record event with callback parameters </button> </div> </div> </body></html>
Path: /eventClientSdk: ios4.38.4Parameters: callback_params {"event_token":"g3mfiw","revenue_amount":"0.05"} environment sandbox event_count 1 event_token g3mfiw
添加合作伙伴参数
- (void)addPartnerParameter:(nonnull NSString *)key value:(nonnull NSString *)value;
您可以添加合作伙伴参数,向渠道合作伙伴发送额外的信息。
Adjust 可向您设置的外部合作伙伴发送合作伙伴参数。这些信息可用来进行更精细的数据分析,开展再营销活动。您设置好参数并为合作伙伴启用参数转发后,Adjust 服务器就会将这些参数转发给合作伙伴。
使用 NSString
键值对 argument 调用addPartnerParameter
方法,以此向事件添加合作伙伴参数。多次调用该方法可添加多个参数。
let event = ADJEvent(eventToken: "abc123")event?.addPartnerParameter("key", value: "value")event?.addPartnerParameter("foo", value: "bar")Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[event addPartnerParameter:@"key" value:@"value"];[event addPartnerParameter:@"foo" value:@"bar"];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent(eventToken);adjustEvent.addPartnerParameter("key", "value");adjustEvent.addPartnerParameter("foo", "bar");Adjust.trackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。以下合作伙伴参数被添加:
- 相关产品的
product_id
- 触发事件的用户
user_id
import Adjustimport UIKit
class ViewControllerSwift: UIViewController { @IBOutlet weak var btnRecordEventPartnerParams: UIButton?
@IBAction func btnRecordEventPartnerParams(_sender: UIButton) { let event = ADJEvent(eventToken: "g3mfiw"); event?.addPartnerParameter("product_id", value: "29") event?.addPartnerParameter("user_id", value: "835") Adjust.trackEvent(event); }}
#import "Adjust.h"#import "Constants.h"#import "ViewControllerObjC.h"
@interface ViewControllerObjC ()
@property (weak, nonatomic) IBOutlet UIButton *btnRecordPartnerParamsEvent;
@end
@implementation ViewControllerObjC
- (IBAction)clickRecordPartnerParamsEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"g3mfiw"]; [event addPartnerParameter:@"product_id" value:@"29"]; [event addPartnerParameter:@"user_id" value:@"835"]; [Adjust trackEvent:event];}
@end
<html> <body> <script> setupWebViewJavascriptBridge(function(bridge) { let adjustConfig = new AdjustConfig('2fm9gkqubvpc', AdjustConfig.EnvironmentSandbox); adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
Adjust.appDidLaunch(adjustConfig);
var btnRecordPartnerParamsEvent = document.getElementById('btnRecordPartnerParamsEvent') btnRecordPartnerParamsEvent.onclick = function(e) { e.preventDefault() var adjustEvent = new AdjustEvent('g3mfiw'); adjustEvent.addPartnerParameter('product_id', '29'); adjustEvent.addPartnerParameter('user_id', '835'); Adjust.trackEvent(adjustEvent); } } </script> <div id="buttons"> <div style="width:300px;height:35px;text-align:center;"> <button id="btnRecordPartnerParamsEvent"> Record event with partner parameters </button> </div> </div> </body></html>
Path: /eventClientSdk: ios4.38.4Parameters: partner_params {"product_id":"29","user_id":"835"} environment sandbox event_count 1 event_token g3mfiw
添加回传标识符
- (void)setCallbackId:(nonnull NSString *)callbackId;
您可以为想要监测的每个事件添加自定义字符串标识符。Adjust 服务器将在事件回传中报告该标识符。这样就能了解哪些事件已经被成功监测。
通过调用 setCallbackId
方法来设置标识符,使用您的 ID 作为 NSString
参数。
let event = ADJEvent(eventToken: "abc123")event?.setCallbackId("Your-Custom-ID")Adjust.trackEvent(event)
ADJEvent *event = [ADJEvent eventWithEventToken:@"abc123"];[event setCallbackId:@"Your-Custom-ID"];[Adjust trackEvent:event];
var adjustEvent = new AdjustEvent("abc123");adjustEvent.setCallbackId("Your-Custom-ID");Adjust.trackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。在该示例中,callbackId
被设为了 f2e728d8-271b-49ab-80ea-27830a215147
。
import Adjustimport UIKit
class ViewControllerSwift: UIViewController { @IBOutlet weak var btnRecordEventCallbackId: UIButton?
@IBAction func btnRecordEventCallbackId(_sender: UIButton) { let event = ADJEvent(eventToken: "g3mfiw"); event?.setCallbackId("f2e728d8-271b-49ab-80ea-27830a215147") Adjust.trackEvent(event); }}
#import "Adjust.h"#import "Constants.h"#import "ViewControllerObjC.h"
@interface ViewControllerObjC ()
@property (weak, nonatomic) IBOutlet UIButton *btnRecordCallbackIdEvent;
@end
@implementation ViewControllerObjC
- (IBAction)clickRecordCallbackIdEvent:(UIButton *)sender { ADJEvent *event = [ADJEvent eventWithEventToken:@"g3mfiw"]; [event setCallbackId:@"f2e728d8-271b-49ab-80ea-27830a215147"]; [Adjust trackEvent:event];}
@end
<html> <body> <script> setupWebViewJavascriptBridge(function(bridge) { let adjustConfig = new AdjustConfig('2fm9gkqubvpc', AdjustConfig.EnvironmentSandbox); adjustConfig.setLogLevel(AdjustConfig.LogLevelVerbose);
Adjust.appDidLaunch(adjustConfig);
var btnRecordCallbackIdEvent = document.getElementById('btnRecordCallbackIdEvent') btnRecordCallbackIdEvent.onclick = function(e) { e.preventDefault() var adjustEvent = new AdjustEvent('g3mfiw'); adjustEvent.setCallbackId('f2e728d8-271b-49ab-80ea-27830a215147'); Adjust.trackEvent(adjustEvent); } } </script> <div id="buttons"> <div style="width:300px;height:35px;text-align:center;"> <button id="btnRecordCallbackIdEvent"> Record event with callback ID </button> </div> </div> </body></html>
Path: /eventClientSdk: ios4.38.4Parameters: callback_id f2e728d8-271b-49ab-80ea-27830a215147 environment sandbox event_count 1 event_token g3mfiw