XEvent 是一个基于事件流的跨平台 配置化打点框架。 XEvent is a cross-platform, structured event report framework based on event flow.
中文文档点 这!
XEvent...
- Simplify User Work,if you want to multi-platform event report, just need to write a DSL(Descriptive language) Configuration which maybe js or xml.
- Data unification, multi-platform uses a set of DSL configuration, the rules are the same, and the reporting logic is the same
- strong Data reliability, business logic and data reporting logic is not associated, modify business will not affect data reporting
- good fluency, data reporting logic is placed in the child thread message queue, does not affect the main thread rendering process
- Development speed fast, faster configuration, faster publish, which one need 1 day to develop before and now just need 5 minites (example)
- easy debugging, automated testing, recording user events, replay user events, inspection event report
- Rules dynamically publish, do not rely on the release version publish
Mainly covers 3 aspects:
XEvent Technical selection
Underlying modeling,Event、Tracker、Stream、Description and more Concept
DSL(language) select
-
The reported data of iOS and the data reported by Android are always inconsistent
XEvent will ensure that the data reporting logic of multiple consumers is the same through configuration rules
-
The data reporting code is complex and involves multiple moments (such as a card with 50%+ area exposure for 1 s), coupling data reporting code in the logic code, and reported data always fluctuates when a new version is published
-
The data reporting service is always changeable and needs to be released hot. The traditional publishing solution needs to follow the version, and it is fatal for data statistics and business development.
XEvent Deliver configuration (js、XML) rules in real time
-
The code for reporting data is sometimes complicated, affecting the performance of the main thread (such as calculating the exposure of the card when scroll, needing to listen to each scroll and traversing the calculation), and it is more troublesome to do thread processing in every place.
The events Event send are processed in the child thread, and the processed result can be defined whether it is handed to the main thread or processed in the child thread.
-
Maybe you still want some features, such as automated testing, data reporting stability, event playback, user behavior analysis, then let's enjoin it!!!
XEvent has 2 sets of implementations, corresponding to xevent, xeventjs under the project library directory, so 2 access methods are provided below.
-
xevent
The data reporting configuration framework based on event flow developed by native Java is characterized by excellent performance. The disadvantage is that there is no iOS implementation.
-
xeventjs
The configuration data reporting framework based on event flow implemented by JavaScript, characterized by cross-platform (h5, Android, iOS can use it), the disadvantage
JS Bridge
time-consuming
-
init engine (sample code in
app/MyApplication
)// 1. init engine XEvent.getInstance().init(); // 2. set stream to dispatch event XEvent.getInstance().setDefaultEventStream(new SimpleEventStream(Utils.getStringFromAsset(EVENT_CONFIG_NAME, this))); // 3. set your handle callback XEvent.getInstance().setIStreamLogCallback(new IStreamLogCallback() { @Override public void onEventLog(String eventName, Map<String, Object> attrs) { // handler you data to report } });
-
config data report rule DSL (sample code in
app/assets/xevent_log_test.xml
)this configuration is to statistics time from
onRsume status
toonPause status
,and reporting thekeep_time
event<?xml version="1.0" encoding="utf-8"?> <trackers> <!--统计页面停留时长 Statistics page duration--> <tracker log_name="keep_time" resend_event="toast"> <!--进入 enter--> <description alias="A" id="onresume"/> <!--退出 exit--> <description alias="B" id="onpause" put_value="{'toast_str':'coasting time of page staying :' + (event_time - A.event_time)/1000 + ' second'}"/> </tracker> </trackers>
-
register rule (sample code in
app/MyApplication
)//如果是采用第一步的方式 默认已经初始化了 可跳过 //if you use 1 step implemention, it has used, so jump this step simpleEventStream.registerTrakerByConfig(Utils.getStringFromAsset(EVENT_CONFIG_NAME, this));
-
send event (sample code in
app/MainActivity
)@Override protected void onResume() { super.onResume(); XEvent.getInstance().sendEvent(new XPEvent(EventConstant.EVENT_ONRESUME)); //onresume } @Override protected void onPause() { super.onPause(); XEvent.getInstance().sendEvent(new XPEvent(EventConstant.EVENT_ONPAUSE)); //onpause }
Preview effect
we can see the repoting data when activity is onPause
-
init js engine
XEventJsTool.init(MainActivity.this);
XEventJsTool
Is the simple version of Js runtime, it depends on the JSCore environment of WebViewMainly related to the following operations:
-
JSCore loads runtime js code files
webView.evaluateJavascript(Utils.getStringFromAsset("libxevent.js", mContext), null);
-
Js runtime injects Java Bridge object (used to callback Java methods)
webView.addJavascriptInterface(new JsTool(null, mContext), "xpEventManager");
-
Initialize the type of system, js code has some iOS, Android differentiation
webView.evaluateJavascript("init(0)", null);
-
-
send framework init event
// 发送框架初始化事件,告知js解析tracker并生成 // send init framework init event, and tell js to create tracker XEventWrapper.sendEvent(new XPEvent(EventConstant.XP_EVENT_XEVENT_FRAMEWORK));
- config your project build.gradle like XEvent/build.gradle (maybe need)
allprojects {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/samwangzhibo3/xevent/' }
}
}
- config your moudle build.gradle like XEvent/app/build.gradle
compile 'com.wzb.xevent:xevent:1.0'
<dependency>
<groupId>com.wzb.xevent</groupId>
<artifactId>xevent</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
Or download the latest JAR from JCenter.
XEvent(Java) is just a transitional version, it is recommended to use the XEvent(js) version because it is cross-platform
-
Both XEvent code (js) and XEvent configuration (js) support dynamic distribution of rules, independent of the release version
-
The form of the event stream is convenient for intercepting user events for playback and automated testing.
-
You can fit the model based on user behavior on the client.
-
why?
-
- Save money and save machines, slow down the server's computing pressure on real-time modeling of user behavior
- Save time, the server does not need to wait until the next day to run the full amount of user data for the model fit.
-
principle
-
- DSL and Rule dispatch immediately
-