反应天然- Advanced

Getting Started

Please refer to ourQuickstart Guide

Sending Events

We recommend tracking only five to seven events in your application instead of tracking too many things to start. Ideally, you track users going through your initial user experience and one key metric that matters for your application (e.g. YouTube might choose "Watched Video" as a key metric).

Once you've initialized the library, you can track an event usingtrack和the event name and properties.

//使用属性mixpanel.track跟踪事件('计划选择',{'plan':'premium'});

Timing Events

您可以跟踪采取行动所花费的时间,例如图像上传或评论帖子,使用timeEvent。这将标志着您的动作的“开始”,直到您完成轨道通话为止。然后将持续时间记录在“持续时间”属性中。

// start the timer for the event "Image Upload" mixpanel.timeEvent("Image Upload"); //...some time later mixpanel.track("Image Upload");

超级特性

It's 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.

为了使事情变得更容易,您可以将这些属性注册为超级属性。如果您只告诉我们这些属性很重要,我们将自动将它们与已发送的所有事件一起包含。超级属性将保存到本地存储中,并将在您的应用程序的调用中持续存在。MixPanel默认情况下已经将一些信息作为超级属性存储;查看MixPanel默认属性的完整列表here

To set super properties, callregisterSuperProperties

mixpanel.registerSuperProperties({'Plan': 'Mega', 'Cost': '2000'});

The next time you track an event, the super properties you just set will be included as properties.

超级属性保存到本地存储中,并将在您的应用程序的执行之间持续存在。

Setting Super Properties Once and Only Once

If you want to store a super property only once (for example, a date of first login), you can useregisterSuperPropertiesOnceregisterSuperPropertiesOncebehaves likeregisterSuperPropertiesand has the same interface, but it doesn't override super properties you've already saved.

这意味着可以安全打电话registerSuperPropertiesOnce和the same property multiple times, and it will only set properties if the super property doesn't exist.

mixpanel.registerSuperPropertiesOnce({'Role': 'Admin'});

More for Super Properties

删除先前注册的超级属性。unregisterSuperProperty是清除所有属性的替代方案,不注册特定的超级属性可防止将其记录在未来事件上。此操作不会影响其他超级属性的价值。任何未注册的属性名称都将忽略。

mixpanel.unregisterSuperProperty('propertyName');

获取用户的超级属性。getuperproperties

const superProperties = await mixpanel.getSuperProperties();

清除用户的所有注册属性。clearSuperProperties

mixpanel.clearSuperProperties();

超级属性生活在本地存储中

我们的移动库将您的超级属性存储在本地存储中。只要安装应用程序(在启动和更新之间),它们就会持续存在。卸载该应用程序将删除客户超级属性。

Managing User Identity

You can handle the identity of a user using the确认andaliasmethods. Proper use of these methods can connect events to the correct user as they move across devices, browsers, and other platforms.

确认

标识具有独特ID的用户,可以跟踪跨设备的用户活动,将用户绑在其事件中,然后创建用户配置文件。如果您从不调用此方法,则使用第一次使用该应用程序的UUID来跟踪唯一访问者。

Argument

Type

Description

distinctId

String
required

A string that uniquely identifies a user - we recommend a user id. Events sent to Mixpanel using the same distinctId will be considered associated with the same visitor/customer for retention and funnel reporting, so be sure that the given value is globally unique for each individual user you intend to track.

Call确认when you know the identity of the current user, typically after log-in or sign-up. We recommend against using确认for anonymous visitors to your site.

// Ensure all future events sent from // the device will have the distinct_id 13791 mixpanel.identify("13791");

ID Merge

If a project hasID Merge启用,识别方法在适当的情况下将连接前后的验证事件。

If a project does not have ID Merge enabled, identify will change the user's local distinct_id to the unique ID you pass. Events tracked prior to authentication will not be connected to the same user identity. If ID Merge is disabled, alias can be used to connect pre and post registration events.

Alias

Thealiasmethod creates an alias which Mixpanel will use to remap one id to another. Multiple aliases can point to the same identifier.

ID Merge

If a project hasID Mergeenabled, just call identify with your chosen identifier as soon as you know who the user is to merge anonymous and identified distinct_ids. Calling alias is no longer required.

Argument

Type

Description

alias

String
required

您想将其用作该用户的标识符的唯一标识符。

distinct_id

String
required

当前的用户标识符。

以下是有效使用alias:

// This makes the current ID (by default an auto-generated GUID) // and '13793' interchangeable distinct ids (but not retroactively). const distinctId = await mixpanel.getDistinctId(); // To create a user profile, you must call identify() mixpanel.alias("New ID", distinctId: distinctId); mixpanel.alias("Newer ID", distinctId: distinctId);

Aliases can also be chained - the following is a valid example:

mixpanel.alias('new_id','asuther_id');//您可以链链别名mixpanel.alias('newer_id','new_id');

Aliasescannot指向多个标识符 - 以下示例将无效:

mixpanel.alias('new_id','asuther_id');//这是无效的,因为'new_id'已经指向'reasun_id'mixpanel.alias('new_id','newer_id');

❗️

ID Merge

If a project does not haveID Mergeenabled, the best practice is to callalias一次,首先为用户创建唯一的ID(例如,当用户首先注册帐户时)。不使用aliasmultiple times for a single user without ID Merge enabled.

Call Reset at Logout

如果经常使用,重置可以填充身份群集

Reset should only be used if multiple users share a device.

经常调用重置可能会导致用户迅速超过每个身份群集限制的500个不同的_id。一旦达到500限制,您将不再能够向用户身份群集添加其他不同的_ID。

resetgenerates 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.

mixpanel.reset();

Storing User Profiles

In addition to events, you can store user profiles in Mixpanel's行为分析product. 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.

Before you send profile updates, you must call mixpanel.identify(). This ensures that you only have actual registered users saved in the system.

Setting Profile Properties

You can set properties on a user profile withmixpanel.getPeople().set

// identify must be called before // user profile properties can be set mixpanel.identify("13793"); // Sets user 13793's "Plan" attribute to "Premium" mixpanel.getPeople().set("Plan", "Premium");

This will set a "Plan" property, with a value "Premium", on user 13793's profile. If there isn't a profile with distinct_id 13793 in Mixpanel already, a new profile will be created. If user 13793 already has a property named "Plan" in their profile, the old value will be overwritten with "Premium".

NOTE

Pick your property names wisely. Once you've sent them to Mixpanel, there is no way to change them. Feel free to use capitalization and spaces in between words.
有一些局限性:

  • Your property names should not begin with$ormp_。这些属性保留给Mixpanel发送的特殊属性。
  • Your property names cannot begin or end with a space as they will automatically be trimmed.
  • Your property names and values cannot be longer than 255 characters. In practice they should be much shorter than that. Property names get cut off by our user interface at about 20 characters.

点击hereto see a list of Mixpanel's reserved user profile properties.

Incrementing Numeric Properties

You can usemixpanel.getPeople().incrementto change the current value of numeric properties. This is useful when you want to keep a running tally of things, such as games played, messages sent, or points earned.

//在MixPanel MixPanel.getPeople()。递增的当前值中添加500个“点已赢得的点”的值(“赢得的点”,500);令properties = {“花费”:17,“剩下的信用”,-34};mixpanel.getPeople()。递增(属性);

Appending to List Properties

mixpanel.getPeople().appendcreates an update that adds an item to a list-valued property. The value you send with the append is added to the end of the list. If the property doesn't exist, it will be created with one element list as its value.

//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");

Other Types of Profile Updates

还有一些其他类型的配置文件更新。可以通过人们class, which is accessible viamixpanel.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.

您可以跟踪一次交易mixpanel.getPeople().trackCharge。This call will add transactions to the individual user profile, which will also be reflected in the Mixpanel Revenue report.

// Make identify has been // called before making revenue updates mixpanel.identify("13793"); // Tracks $100 in revenue for user 13793 mixpanel.getPeople().trackCharge(100); // Refund this user 50 dollars mixpanel.getPeople().trackCharge(-50); // Tracks $25 in revenue for user 13793 // on the 2nd of january mixpanel.getPeople().trackCharge(25, {"$time": "2012-01-02T00:00:00"});

Group Analytics

Add Group Keys

To start tracking groups data,add group keys in project settings。如果您在项目设置中没有看到组键,请与Mixpanel销售团队to purchase Group Analytics.

Mixpanel Group Analytics allows behavioral data analysis by selected groups, as opposed to individual users.

Grouping by identifiers other than thedistinct_idwill allow analysis at a company or group level when using Mixpanel analytics. Readthis articleto learn more about Group Analytics.

A group is identified by thegroup_keyandgroup_id

  • group_keyis the property that connects event data for Group Analytics.
  • group_id是特定组的标识符。

If the property “company” is chosen for Group Analytics, “company” is thegroup_key, and “Mixpanel”, “Company A”, and “13254” are all potentialgroup_idvalues.

A user can belong to multiple groups. All updates to a group operate on thegroup_keyandgroup_id

Creating a Group Key

Administer group keys through your Project Settings. Group keys are event properties. All events need to have a defined group key on them in order to be attributed to a group. Group keys are project specific, and the group key should be set up before group data is sent. Note that Mixpanel does not backfill historical data before the group key was implemented.

To administer group keys, navigate to your Project Settings. Click+Add Group Keyunder the组钥匙section.

1846年1846年

Enter an event property to attribute the group key to. You can also enter a display name for the group key. ClickSave

Adding Users to a Group

Adding users to groups causes thegroup_keyandgroup_idto send as a property key and value for all events triggered by that user on the device. You can add multiple values for a single user to thegroup_keylist property.

Similar to adistinct_id, thegroup_keyallows Mixpanel to group events by an identifier for analysis. Agroup_key, however, is a group level identifier and not a user level identifier like thedistinct_id

You can add users to groups by calling thesetGroupmethod.

mixpanel.setGroup("group key", "group id");

你可以打电话addGroupto add any additional groups to an existing list.

mixpanel.addGroup("group key", "group id");

你可以打电话消除Group从现有列表中删除所有其他组。

mixpanel.removeGroup("group key", "group id");

Creating Group Profiles

It is possible to create a Group profile that is similar to a user profile. You must callgetGroup().set()to build a group profile. It is important to the group_key, group_id, and one property so that the profile is not empty.

mixpanel.getGroup(MixpanelToken, "company_id", 12345).set("SET NAME", "SET VALUE");

Setting Group Profile Properties

You can add details to Groups by adding properties to them.

为了更新组配置文件属性,您必须指定需要通过调用需要更新的组getGroup().set()

mixpanel.getGroup("group key", "group id").set("SET NAME", "SET VALUE");

The getGroup() method can be chained with other commands that edit properties specific to the group.

You can set the property $name to populate the name field at the top of the group profile.

These operations are similar to the corresponding operations for user profile property updates.

set

getGroup().set()updates or adds a property to a group.

mixpanel.getGroup("group key", "group id").set("SET NAME", "SET VALUE");

set once

getGroup().setOnce()adds a property value to a group only if it has not been set before.

mixpanel.getGroup("group key", "group id").setOnce("SET ONCE NAME", "SET ONCE VALUE");

unset

getGroup().unset()unsets a specific property in the group.

mixpanel.getGroup(“组键”,“组ID”)。unset(“ unse name”);

消除

getGroup().remove()在列表属性中删除特定值。

mixPanel.getGroup(“组密钥”,“组ID”)。删除(“属性名称”,“ to remove”);

union

getGroup()。union()adds the specified values to a list property and ensures that those values only appear once.

mixPanel.getGroup(“组键”,“组ID”)。联合(“联合名称”,[“ prop_value_a”,“ prop_value_b”]);

delete

getGroup().deleteGroup()deletes a group.

mixpanel.getGroup("group key", "group id").deleteGroup();

EU Data Residency

Route data to Mixpanel's EU servers by setting theserverURLproperty after initializing the client.

mixpanel.setserverurl(“ https://api-eu.www.jy710.com”);

选择用户退出跟踪

Client-side tracking of individual user data can be stopped or resumed by controlling a user’s opt-out/opt-in state. Opt-out methods and library configuration settings only affect data sent from a single library instance. Data sent from other sources to Mixpanel’s APIs will still be ingested regardless of whether the user is opted out locally.

用户的退出/选择状态由存储在用户设备的本地存储中的选择输出标志控制。如果标志的值为真,则将选择用户选择,并且不会跟踪。如果选择输出标志为false,则跟踪用户。初始化SDK时未设置标志,因此既未选择也没有选择初始状态。如果没有标志集,则默认情况下将跟踪用户。

To opt a user out of tracking locally, use theoptouttrackingmethod. To resume tracking for an individual user, useoptInTrackingCallhasOptedOutTrackingto check user’s opt-out status locally. By default, an "$opt_in" event is sent every time that a user opts in.

// Check user’s opt-out status locally let hasOptedOut = await mixpanel.hasOptedOutTracking(); mixpanel.optOutTracking(); // To opt a user out of tracking locally, use the optOutTracking method. Before calling this method call flush() if you want to send all the events or updates to mixpanel otherwise it will be deleted mixpanel.optOutTracking(); // To opt-in an already opted-out user from tracking. After using this method people updates and track calls will be sent to Mixpanel. // Opt-in without any parameters mixpanel.optInTracking();

选择用户退出跟踪by Default

Mixpanel’s tracking libraries will send user data by default. Explicitly setting a default opt-out state of true will opt-out all users by default, preventing data from sending unless a user’s opt-out state is set to false.

const mixpanel = await Mixpanel.init('Your mixpanel token', true, true /* DEFAULT_OPT_OUT */);

删除现有数据

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.

调试和伐木

Enabling Mixpanel debugging and logging allows you to see the debug output from the Mixpanel library. This may be useful in determining when track calls go out. To enable Mixpanel debugging and logging, you can callsetLoggingEnabled(true)true, then run your iOS project with Xcode or android project with Android Studio. The logs should be available in the console.

Flushing Events

To preserve battery life and customer bandwidth, the Mixpanel library doesn't send the events you record immediately. Instead, it sends batches to the Mixpanel servers every 60 seconds while your application is running, as well as when the application transitions to the background. You can call冲洗如果您想在特定时刻强制冲洗,请手动。

mixpanel.flush();