Adjust SDK 提供一个 AdjustEvent
对象,用于架构并向 Adjust 服务器发送来自您应用的事件信息。
实例化 AdjustEvent 对象
public AdjustEvent(string eventToken);
要使用 Adjust SDK 发送事件信息,请实例化一个 AdjustEvent
对象。该对象中包含的变量会在应用中发生事件时被发送给 Adjust。
要实例化事件对象,请创建新的 AdjustEvent
实例,并传送下列参数:
eventToken
(string
):您的 Adjust 事件识别码。
var adjustEvent = new AdjustEvent("abc123");Adjust.TrackEvent(adjustEvent);
发送事件
public static void TrackEvent(AdjustEvent adjustEvent);
您可以将Adjust 事件识别码关联至应用内行为,以此对其进行记录。要记录事件:
- 创建一个新的 Adjust 事件实例并将事件识别码作为字符串参数进行发送。
- 使用事件实例作为 argument 调用
TrackEvent
方法。
var adjustEvent = new AdjustEvent("abc123");Adjust.TrackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。
using AdjustSdk;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;
namespace AdjustWSExample{ public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }
private void btnSimpleEvent_Click(object sender, RoutedEventArgs e) { var simpleEvent = new AdjustEvent("g3mfiw"); Adjust.TrackEvent(simpleEvent); } }}
<page x:Class="AdjustWSExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AdjustWSExample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <button x:Name="btnSimpleEvent" Content="Record simple event" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="btnSimpleEvent_Click" > </Grid></Page>
记录事件收入
public void SetRevenue(double revenue, string currency);
您可以通过在实例上设定 revenue (收入) 和 currency (币种) 属性来记录与事件关联的收入。使用此功能来在应用内记录产生收入的行为。
要设置这些属性,可以调用 SetRevenue
方法并传递以下参数:
revenue
(double
):事件产生的收入额currency
(string
):事件币种的ISO 4217 代码。
var adjustEvent = new AdjustEvent("abc123");adjustEvent.SetRevenue(0.01, "EUR");Adjust.TrackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。该函数会将该事件的 revenue
属性设为 0.25
,并将 currency
属性设为 EUR
。
using AdjustSdk;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;
namespace AdjustWSExample{ public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }
private void btnRevenueEvent_Click(object sender, RoutedEventArgs e) { var revenueEvent = new AdjustEvent("g3mfiw"); revenueEvent.SetRevenue(0.25, "EUR") Adjust.TrackEvent(revenueEvent); } }}
<page x:Class="AdjustWSExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AdjustWSExample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <button x:Name="btnRevenueEvent" Content="Record revenue event" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="btnRevenueEvent_Click" > </Grid></Page>
收入事件去重
public string PurchaseId { get; set; }
您也可以发送一个可选的标识符,以避免记录重复事件。SDK 会存储最近 10 个标识符,带有重复购买 ID 的收入事件会被跳过。
将您的购买 ID 指定到事件对象的 PurchaseId
属性,以设置该标识符。
AdjustEvent event = new AdjustEvent("abc123");
event.SetRevenue(0.01, "EUR");event.PurchaseId = "{PurchaseId}";
Adjust.trackEvent(event);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。该函数将 PurchaseId
属性设为 5e85484b-1ebc-4141-aab7-25b869e54c49
。
using AdjustSdk;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;
namespace AdjustWSExample{ public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }
private void btnUniqueEvent_Click(object sender, RoutedEventArgs e) { var uniqueEvent = new AdjustEvent("g3mfiw"); var uniqueId = "5e85484b-1ebc-4141-aab7-25b869e54c49" uniqueEvent.PurchaseId = uniqueId Adjust.TrackEvent(uniqueEvent); } }}
<page x:Class="AdjustWSExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AdjustWSExample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <button x:Name="btnUniqueEvent" Content="Record unique event" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="btnUniqueEvent_Click" > </Grid></Page>
添加回传参数
public void AddCallbackParameter(string key, string value);
您在 Adjust 控制面板中注册回传 URL,SDK 监测到事件后,会向您的回传 URL 发送一个 GET 请求。
您可以设置发送到服务器的回传参数。配置好事件的参数后,SDK 会将参数附加至您的回传 URL。您可以利用该信息,通过自己的 BI 系统分析用户应用内行为。
使用 string
键值对 argument 调用addCallbackParameter
方法,以此向事件添加回传参数。多次调用该方法可添加多个参数。
var adjustEvent = new AdjustEvent("abc123");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
using AdjustSdk;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;
namespace AdjustWSExample{ public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }
private void btnCallbackEvent_Click(object sender, RoutedEventArgs e) { var callbackEvent = new AdjustEvent("g3mfiw"); callbackEvent.AddCallbackParameter("event_token", "g3mfiw") callbackEvent.AddCallbackParameter("revenue_amount", "0.05") Adjust.TrackEvent(callbackEvent); } }}
<page x:Class="AdjustWSExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AdjustWSExample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <button x:Name="btnCallbackEvent" Content="Record callback event" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="btnCallbackEvent_Click" > </Grid></Page>
添加合作伙伴参数
public void AddPartnerParameter(string key, string value);
您可以添加合作伙伴参数,向渠道合作伙伴发送额外的信息。
Adjust 可向您设置的外部合作伙伴发送合作伙伴参数。这些信息可用来进行更精细的数据分析,开展再营销活动。您设置好参数并为合作伙伴启用参数转发后,Adjust 服务器就会将这些参数转发给合作伙伴。
使用 string
键值对 argument 调用addPartnerParameter
方法,以此向事件添加合作伙伴参数。多次调用该方法可添加多个参数。
var adjustEvent = new AdjustEvent("abc123");adjustEvent.AddPartnerParameter("key", "value");adjustEvent.AddPartnerParameter("foo", "bar");Adjust.TrackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。以下合作伙伴参数被添加:
- 相关产品的
product_id
- 触发事件的用户
user_id
using AdjustSdk;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;
namespace AdjustWSExample{ public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }
private void btnPartnerEvent_Click(object sender, RoutedEventArgs e) { var partnerEvent = new AdjustEvent("g3mfiw"); partnerEvent.AddPartnerParameter("product_id", "29") partnerEvent.AddPartnerParameter("user_id", "835") Adjust.TrackEvent(partnerEvent); } }}
<page x:Class="AdjustWSExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AdjustWSExample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <button x:Name="btnPartnerEvent" Content="Record partner event" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="btnPartnerEvent_Click" > </Grid></Page>
添加回传标识符
public string CallbackId { get; set; }
您可以为想要监测的每个事件添加自定义字符串标识符。Adjust 服务器将在事件回传中报告该标识符。这样就能了解哪些事件已经被成功监测。
将您的标识符指定到事件对象的 CallbackId
属性,以设置该标识符。
var adjustEvent = new AdjustEvent("abc123");adjustEvent.CallbackId = "Your-Custom-Id";Adjust.TrackEvent(adjustEvent);
示例
在此示例中,每次用户与某个按钮互动时,我们就监测到一个带有g3mfiw
标签的事件。在该示例中,callbackId
被设为了 f2e728d8-271b-49ab-80ea-27830a215147
。
using AdjustSdk;using Windows.UI.Xaml;using Windows.UI.Xaml.Controls;
namespace AdjustWSExample{ public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent(); }
private void btnCustomEvent_Click(object sender, RoutedEventArgs e) { var customEvent = new AdjustEvent("g3mfiw"); customEvent.CallbackId = "f2e728d8-271b-49ab-80ea-27830a215147" Adjust.TrackEvent(customEvent); } }}
<page x:Class="AdjustWSExample.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:AdjustWSExample" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <button x:Name="btnCustomEvent" Content="Record custom event" HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Click="btnCustomEvent_Click" > </Grid></Page>