Skip to content

Commit 9de8b78

Browse files
authored
Merge pull request #33 from jpush/dev
Dev
2 parents 9e082db + 91a0fb6 commit 9de8b78

15 files changed

Lines changed: 331 additions & 540 deletions

File tree

android/.idea/gradle.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

android/.idea/misc.xml

Lines changed: 0 additions & 33 deletions
This file was deleted.

android/.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

android/.idea/runConfigurations.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

android/.idea/workspace.xml

Lines changed: 0 additions & 336 deletions
This file was deleted.

android/build.gradle

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
buildscript {
2-
repositories {
3-
jcenter()
4-
}
1+
apply plugin: 'com.android.library'
52

6-
dependencies {
7-
classpath 'com.android.tools.build:gradle:2.3.1'
8-
}
3+
def safeExtGet(prop, fallback) {
4+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
95
}
106

11-
apply plugin: 'com.android.library'
12-
137
android {
14-
compileSdkVersion 23
15-
buildToolsVersion "25.0.2"
8+
compileSdkVersion safeExtGet('compileSdkVersion', 27)
9+
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.2')
1610

1711
defaultConfig {
18-
minSdkVersion 16
19-
targetSdkVersion 22
12+
minSdkVersion safeExtGet('minSdkVersion', 16)
13+
targetSdkVersion safeExtGet('targetSdkVersion', 27)
2014
versionCode 1
2115
versionName "1.0"
2216
}
@@ -34,6 +28,6 @@ repositories {
3428
}
3529

3630
dependencies {
37-
compile fileTree(include: ['*.jar'], dir: 'libs')
38-
compile 'com.facebook.react:react-native:+'
31+
api fileTree(include: ['*.jar'], dir: 'libs')
32+
implementation 'com.facebook.react:react-native:+'
3933
}
-75.8 KB
Binary file not shown.
59.3 KB
Binary file not shown.

android/src/main/java/cn/jpush/reactnativejanalytics/JAnalyticsModule.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package cn.jpush.reactnativejanalytics;
22

3+
import android.util.Log;
4+
5+
import com.facebook.react.bridge.Callback;
36
import com.facebook.react.bridge.ReactApplicationContext;
47
import com.facebook.react.bridge.ReactContextBaseJavaModule;
58
import com.facebook.react.bridge.ReactMethod;
69
import com.facebook.react.bridge.ReadableMap;
710
import com.facebook.react.bridge.ReadableMapKeySetIterator;
811

12+
import cn.jiguang.analytics.android.api.Account;
13+
import cn.jiguang.analytics.android.api.AccountCallback;
914
import cn.jiguang.analytics.android.api.BrowseEvent;
1015
import cn.jiguang.analytics.android.api.CalculateEvent;
1116
import cn.jiguang.analytics.android.api.CountEvent;
@@ -130,4 +135,67 @@ public void stopLogPageView(ReadableMap map) {
130135
if (getCurrentActivity() != null)
131136
JAnalyticsInterface.onPageEnd(getCurrentActivity(), name);
132137
}
138+
139+
@ReactMethod
140+
public void setChannel(ReadableMap map) {
141+
String channel = map.getString("channel");
142+
JAnalyticsInterface.setChannel(getCurrentActivity(), channel);
143+
}
144+
145+
@ReactMethod
146+
public void setAnalyticsReportPeriod(ReadableMap map) {
147+
int period = map.getInt("period");
148+
JAnalyticsInterface.setAnalyticsReportPeriod(getCurrentActivity(), period);
149+
}
150+
151+
/**
152+
* 设置账户维度模型
153+
*/
154+
@ReactMethod
155+
public void identifyAccount(ReadableMap map, final Callback success, final Callback fail) {
156+
Logger.i(JANALYTICS_NAME, "Stopping page statistics");
157+
String accountID = map.getString("accountID");
158+
long creationTime = map.getInt("creationTime");
159+
String name = map.getString("name");
160+
int sex = map.getInt("sex");
161+
int paid = map.getInt("paid");
162+
String birthdate = map.getString("birthdate");
163+
String phone = map.getString("phone");
164+
String email = map.getString("email");
165+
String weiboID = map.getString("weiboID");
166+
String wechatID = map.getString("wechatID");
167+
String qqID = map.getString("qqID");
168+
ReadableMap extras = map.getMap("extras");
169+
170+
Account account = new Account(accountID);
171+
account.setCreationTime(creationTime); // 账户创建的时间戳
172+
account.setName(name);
173+
account.setSex(sex);
174+
account.setPaid(paid);
175+
account.setBirthdate(birthdate); // "19880920"是yyyyMMdd格式的字符串
176+
account.setPhone(phone);
177+
account.setEmail(email);
178+
account.setWeiboId(weiboID);
179+
account.setWechatId(wechatID);
180+
account.setQqId(qqID);
181+
if (extras != null) {
182+
ReadableMapKeySetIterator iterator = extras.keySetIterator();
183+
while (iterator.hasNextKey()) {
184+
String key = (String) iterator.nextKey();
185+
String value = extras.getString(key);
186+
account.setExtraAttr(key, value); // key如果为空,或者以极光内部namespace(符号$)开头,会设置失败并打印日志
187+
}
188+
}
189+
JAnalyticsInterface.identifyAccount(getCurrentActivity(), account, new AccountCallback() {
190+
@Override
191+
public void callback(int code, String msg) {
192+
if (code == 0) {
193+
success.invoke();
194+
} else {
195+
Log.i(JAnalyticsModule.class.getSimpleName(), "Identify account error code " + code + " :" + msg);
196+
fail.invoke(msg);
197+
}
198+
}
199+
});
200+
}
133201
}

docs/AndroidConfig.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ android {
2828
}
2929
...
3030
dependencies {
31-
compile project(':janalytics-react-native')
32-
compile project(':jcore-react-native')
31+
implementation project(':janalytics-react-native')
32+
implementation project(':jcore-react-native')
3333
}
3434
```
3535

0 commit comments

Comments
 (0)