安卓- Advanced
入门
请参考我们的快速入门指南。
发送事件
Once you've initialized the library, you can track an event usingmixpanelapi.Trackwith the event name and properties.
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);JSONObject props = new JSONObject(); props.put("Gender", "Female"); props.put("Plan", "Premium"); mixpanel.track("Plan Selected", props);
Timing Events
You can track the time it took for an action to occur, such as an image upload or a comment post, usingtimeEvent。This will mark the "start" of your action, which will be timed until you finish with a track call. The time duration is then recorded in the "Duration" property.
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);//启动事件“图像上传” MixPanel.TimeEvent(“ Image Upload”)的计时器;//如果imageupload()方法返回true如果(imageupload()){mixpanel.track(“ image upload”);}
Super Properties
It's very common to have certain properties that you want to include with each event you send. Generally, these are things you know about the user rather than about a specific event - for example, the user's age, gender, source, or initial referrer.
To make things easier, you can register these properties as super properties. If you tell us just once that these properties are important, we will automatically include them with all events sent. Super properties are saved to device storage, and will persist across invocations of your app. Mixpanel already stores some information as super properties by default; see a full list of Mixpanel default properties这里。
要设置超级属性,请致电MixpanelAPI.registerSuperProperties。
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);// Send a "User Type: Paid" property will be sent // with all future track calls. JSONObject props = new JSONObject(); props.put("User Type", "Paid"); mixpanel.registerSuperProperties(props);
这next time you track an event, the super properties you just set will be included as properties.
超级属性被保存到设备存储中,并将在您的应用程序的执行之间持续存在。
仅设置超级属性一次
如果您只想存储超级属性一次(例如,首次登录日期),可以使用mixpanelapi.registersuperpropertiesonce。寄存器PropertiesOncebehaves like寄存器Properties并且具有相同的接口,但并没有覆盖您已经保存的超级属性。
This means it's safe to call寄存器PropertiesOncewith the same property multiple times, and it will only set properties if the super property doesn't exist.
Super Properties Live in Local Storage
Our mobile libraries store your super properties in local storage. They will persist so long as the app is installed (between launches and updates). Uninstalling the app will remove that customers super properties.
管理用户身份
You can handle the identity of a user using theidentify和aliasmethods. Proper use of these methods can connect events to the correct user as they move across devices, browsers, and other platforms.
Identify
Identify a user with a unique ID to track user activity across devices, tie a user to their events, and create a user profile. If you never call this method, unique visitors are tracked using a UUID that generates the first time they use the app.
称呼identify
when you know the identity of the current user, typically after log-in or sign-up. We recommend against usingidentify
for anonymous visitors to your site. To assign your own distinct_ids, you can useMixpanelapi。识别
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);//确保从//发送的所有未来事件将具有独特的_ID 13793 mixPanel.Identify(“ 13793”);
通常,如果您使用identify,,,,you should call it as soon as the user logs in to your application. This will track all of their authenticated application usage to the correct user ID.
ID合并
If a project hasID合并enabled, the identify method will connect pre- and post-authentication events when appropriate.
如果项目未启用ID合并,则标识将将用户的本地独立_ID更改为您通过的唯一ID。在身份验证之前跟踪的事件将不会连接到相同的用户身份。如果禁用ID合并,则可以使用别名来连接预注册事件。
一种lias
这alias方法会创建一个别名,将Mixpanel用来将一个ID重新映射到另一个ID。多个别名可以指向相同的标识符。
ID合并
If a project hasID合并已启用,只需在您知道用户将合并匿名并确定不同的dinters_ids时,请立即与您选择的标识符识别识别。不再需要调用别名。
争论 |
类型 |
Description |
---|---|---|
alias |
细绳 |
一种unique identifier that you want to use as an identifier for this user. |
区别 |
细绳 |
这current user identifier. |
这following is a valid use ofalias
:
mixpanel.alias(“ new_id”,“ asuther_id”);//You can add multiple id aliases to the existing id mixpanel.alias("newer_id", "existing_id");
一种liases can also be chained - the following is a valid example:
mixpanel.alias(“ new_id”,“ asuther_id”);//您可以链链别名mixpanel.alias(“ newer_id”,“ new_id”);
一种liases cannot point to multiple identifiers - the following example will not work:
mixpanel.alias(“ new_id”,“ asuther_id”);//this is invalid as 'new_id' already points to 'existing_id' mixpanel.alias("new_id", "newer_id");
ID合并
如果一个项目没有ID合并启用,最好的做法是致电
alias
once when a unique ID is first created for a user (e.g., when a user first registers for an account). Do not usealias
对于没有ID合并的单个用户多次启用。
称呼重置at Logout
重置can fill an identity cluster if used frequently
重置should only be used if multiple users share a device.
称呼ing reset frequently can lead to users quickly exceeding the 500 distinct_id per identity cluster limit. Once the 500 limit is reached you will no longer be able to add additional distinct_ids to the users identity cluster.
重置generates a new random distinct_id and clears super properties. Call reset to clear data attributed to a user when that user logs out. This allows you to handle multiple users on a single device. For more information about maintaining user identity, see theIdentity Management: Best Practicesarticle.
Storing User Profiles
除活动外,您还可以将用户配置文件存储在Mixpanel的Behavioral Analyticsproduct. Profiles are persistent sets of properties that describe a user - things like name, email address, and signup date. You can use profiles to explore and segment users by who they are, rather than what they did. You can also use profiles to send messages, such as emails, SMS, or push notifications.
在发送个人资料更新之前,您必须致电identify。该库为用户记录使用单独的ID,您必须设置此值以发送更新。
Setting Profile Properties
您可以在用户配置文件上设置属性mixpanelapi.getPeople()。。
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);//必须在可以设置MixPanel.Identify(“ 13793”)之前调用标识//用户配置文件属性。//将用户13793的“计划”属性设置为“ premium” mixpanel.getPeople()。set(“ plan”,“ premium”);
这将在用户13793的配置文件上设置具有“ PROUP”的“计划”属性。如果已经在Mixpanel中没有具有独特的_ID 13793的配置文件,将创建一个新的配置文件。如果用户13793已经在其个人资料中具有名为“计划”的属性,则旧值将被“ Premium”覆盖。
笔记
明智地选择您的财产名称。一旦将它们发送到Mixpanel,就无法更改它们。可以随意使用大写和单词之间的空间。
这re are a few limitations:
- 您的财产名称不应开始
$
ormp_
。这se properties are reserved for special properties sent by Mixpanel.- Your property names cannot begin or end with a space as they will automatically be trimmed.
- 您的属性名称和值不能超过255个字符。实际上,它们应该比这短得多。属性名称被我们的用户界面以约20个字符的形式切断。
Click这里要查看Mixpanel保留的用户配置文件属性列表。
增加数字属性
您可以使用mixpanelapi.getPeople()。increment更改数字属性的当前值。当您想保持诸如玩游戏,发送消息或获得的点之类的内容时,这很有用。
// Add 500 to the current value of // "points earned" in Mixpanel mixpanel.getPeople().increment("points earned", 500); // Pass a Map to increment multiple properties Map properties = new HashMap(); properties.put("dollars spent", 17); // Subtract by passing a negative value properties.put("credits remaining", -34); mixpanel.getPeople().increment(properties);
附加列出属性
getPeople.append()创建一个将项目添加到列表值属性的更新。您发送附加的值添加到列表的末尾。如果该属性不存在,它将以一个元素列表作为其值创建。
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);//Identify the user profile that is going to be updated mixpanel.identify("13793"); //Add the color green to the list property "Favorite Colors" //A new list property is created if it doesn't already exist mixpanel.getPeople().append("Favorite Colors", "Green")
其他类型的个人资料更新
这re are a few other types of profile updates. They can be accessed through theMixpanelPeople class,,,,which is accessible viamixpanelapi.getPeople()。
Tracking Revenue
Mixpanel makes it easy to analyze the revenue you make from individual customers. By associating charges with User Analytics profiles, you can compare revenue across different customer segments and calculate customer lifetime value.
You can track a single transaction withmixpanelapi.getPeople()。trackCharge。此呼叫将为单个用户配置文件增加交易,这也将反映在Mixpanel收入报告中。
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);// make getPeople()识别已被调用//在进行收入更新mixpanel.Identify(“ 13793”)之前已被调用。//跟踪用户100美元的收入13793 mixpanel.getPeople()。trackcharge(100,null);//退还此用户50美元mixpanel.getPeople()。trackcharge(-50,null);//跟踪用户13793 //的$ 25收入//在1月2日的jsonobject properties = new JSONOBJECT()properties.put(“ $ time”,“ 2012-01-02T00:00:00:00”);mixpanel.getPeople()。跟踪费(25,属性);
小组分析
添加组键
要开始跟踪组数据,在项目设置中添加组键。If you don't see group keys in your Project Settings, reach out to theMixpanel Sales Team购买小组分析。
Mixpanel组分析允许选定组而不是单个用户进行行为数据分析。
通过标识符进行分组distinct_id
使用MixPanel Analytics时,将允许在公司或小组级别进行分析。读本文to learn more about Group Analytics.
一种group is identified by thegroup_key
和group_id
。
group_key
是将事件数据连接用于组分析的属性。group_id
is the identifier for a specific group.
If the property “company” is chosen for Group Analytics, “company” is thegroup_key
,,,,和“Mixpanel”, “Company A”, and “13254” are all potentialgroup_id
values.
用户可以属于多个组。对组的所有更新都在group_key
和group_id
。
Creating a Group Key
通过您的项目设置管理组钥匙。组键是事件属性。所有事件都需要在其上具有定义的组键,以归因于组。组密钥是特定于项目的,并且在发送组数据之前应设置组密钥。请注意,Mixpanel在实施组密钥之前不会回填历史数据。
To administer group keys, navigate to your Project Settings. Click+添加组密钥在下面GROUP KEYS部分。
Enter an event property to attribute the group key to. You can also enter a display name for the group key. Click救。
将用户添加到组
一种dding users to groups causes thegroup_key
和group_id
作为属性密钥和值发送的所有事件,由该用户在设备上触发的所有事件。您可以将单个用户的多个值添加到group_key
列表属性。
Similar to adistinct_id
, 这group_key
允许Mixpanel通过标识符进行分析。一种group_key
但是,是组级标识符,而不是像用户级标识符distinct_id
。
You can add users to groups by calling thesetGroup()方法。
mMixpanel.setGroup("group key", "group id");
You can calladdGroup()to add any additional groups to an existing list.
mmixpanel.AddGroup(“组密钥”,“组ID”);
You can callremove group()to remove any additional groups from an existing list.
mmixpanel.removegroup(“组密钥”,“组ID”);
创建组配置文件
可以创建类似于用户配置文件的组配置文件。你必须打电话getGroup()。set()to build a group profile. It is important to thegroup_key
,,,,group_id
,,,,和one property so that the profile is not empty.
mMixpanel.getGroup("group key", "group id").set("SET NAME", "SET VALUE");
设置组配置文件属性
You can add details to Groups by adding properties to them.
In order to update Group profile properties, you must specify the group that needs to be updated by callinggetGroup()。set()。
mMixpanel.getGroup("group key", "group id").set("SET NAME", "SET VALUE"); mMixpanel.getGroup("group key", "group id").setMap((new HashMap<>()).put("SET MAP INT", 1));
这getGroup()方法可以用其他编辑特定属性的命令链接。
您可以设置属性$name
要填充组配置文件顶部的名称字段。
这些操作类似于用户配置文件属性更新的相应操作。
放
mixpanel.getGroup()。set()更新或将属性添加到组中。
mMixpanel.getGroup("group key", "group id").set("SET NAME", "SET VALUE"); mMixpanel.getGroup("group key", "group id").setMap((new HashMap<>()).put("SET MAP INT", 1));
设置一次
mixpanel.getGroup().set_once()adds a property value to a group only if it has not been set before.
mmixpanel.getGroup(“组键”,“组ID”)。setOnce(“ set a bern name”,“ set berne berne value”);mmixpanel.getGroup(“组键”,“组ID”)。SetOnCemap(((新哈希马普<>())。put(“ set bern bern map str”,“ set bern map abor abor”));
不设置
mixpanel.getGroup()。unset()在小组中安排特定属性。
mMixpanel.getGroup("group key", "group id").unset("UNSET NAME");
remove
mixpanel.getGroup()。remove()removes a specific value in a list property.
mmixpanel.getGroup(“组密钥”,“组ID”)。删除(“属性名称”,“ to remove”);
联盟
mixpanel.getGroup().union()adds the specified values to a list property and ensures that those values only appear once.
mmixpanel.getGroup(“ group key”,“ group id”)。联合(“联合名称”,new jsonarray(“ [100]”));
删除
mixpanel.getGroup().deleteGroup()删除一个小组。
mMixpanel.getGroup("group key", "group id").deleteGroup();
应用链接跟踪
这Mixpanel library has built in support for tracking in-bound and out-bound一种pp Links。应用链接是一个规范,可帮助标准化应用程序之间的深入链接,并为您提供有关用户如何访问您自己的移动应用程序的其他信息。
要求
In order for Mixpanel to track App Links, your app must statisfy the following dependencies:
- Bolts Framework> = V1.1.2
- 安卓Support Library v4。
笔记
如果您的应用程序不符合这些要求,则MixPanel库将记录有关未启用应用程序链接的调试消息。这不是错误,可以安全地忽略。
跟踪内部应用程序链接
如果用户通过应用程序链接来到您的应用程序,则MixPanel将自动跟踪“ $ al_nav_in”事件,其中包含有关其来自何处的元信息。
Tracking Out-bound App lLnks
如果您使用螺栓框架链接到其他应用程序,则Mixpanel将跟踪$ al_nav_out
事件具有有关用户在哪里链接到位置的其他元信息。
bolts.AppLinkNavigation.navigateInBackground(this, "http://anotherapp.com/app/link");
Opting Users Out of Tracking
可以通过控制用户的选择退出/选择输入状态来停止或恢复各个用户数据的客户端跟踪。退出方法和库配置设置仅影响从单个库实例发送的数据。从其他来源发送到Mixpanel API的数据仍然会被摄入,而不管用户是否在本地选择退出。
这opt-out/opt-in state of a user is controlled by an opt-out flag that is stored in the local storage of the user’s device. If the value of the flag is true, then the user is opted-out and will not be tracked. If the opt-out flag is false, then the user is tracked. The flag is not set when the SDK is initialized, so the initial state is neither opted in nor opted out. Without the flag set, the user will be tracked by default.
要选择当地的用户,请使用optOutTracking方法。要恢复个人用户的跟踪,请使用OptIntracking。称呼hasOptedOutTracking在本地检查用户的退出状态。默认情况下,每次用户选择进入时,都会发送“ $ opt_in”事件。
mixpanelapi mixpanel = mixpanelapi.getInstance(上下文,mixpanel_token,true);// Opt a user out of data collection mixpanel.optOutTracking(); // Check a user's opt-out status // Returns true of user is opted out of tracking locally Boolean hasOptedOutTracking = mixpanel.hasOptedOutTracking();
默认情况下选择用户退出跟踪
MixPanel的跟踪库将默认情况下发送用户数据。明确设置默认的选择状态true的默认情况下将退出所有用户,除非用户的选择退出状态设置为false,否则可以防止数据发送。
//初始化true的默认选择输出状态//将防止默认情况下收集数据,mixpanelapi mixpaneloptoutdefault = mixpanelapi.getInstance(context,mixpanel_token,true,true/true,true/ * opt opt opt opt opt,true/ * opt opt opt opt opt opt opt opt opt fimept off fimeptault */);
Delete Existing Data
Opting users out of tracking will stop any future tracking. This does not automatically delete data that has already been collected. Mixpanel's deletion API can be used to delete existing data.
Debugging and Logging
Enabling Mixpanel debugging and logging allows you to see the debug output from the Mixpanel Android library. This may be useful in determining when track calls go out or in-app messages are fetched. To enable Mixpanel debugging and logging, you will want to add the following permission within yourandroidManifest.xml
在 - 的里面
标签:
... ... < /application> ...
欧盟数据居住
将数据路由到Mixpanel的欧盟服务器,通过在下面添加元数据条目
您应用程序的标签androidManifest.xml
。
Release History
更新 大约1个月以前