|
1 | 1 | package cn.jpush.reactnativejanalytics; |
2 | 2 |
|
| 3 | +import android.util.Log; |
| 4 | + |
| 5 | +import com.facebook.react.bridge.Callback; |
3 | 6 | import com.facebook.react.bridge.ReactApplicationContext; |
4 | 7 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
5 | 8 | import com.facebook.react.bridge.ReactMethod; |
6 | 9 | import com.facebook.react.bridge.ReadableMap; |
7 | 10 | import com.facebook.react.bridge.ReadableMapKeySetIterator; |
8 | 11 |
|
| 12 | +import cn.jiguang.analytics.android.api.Account; |
| 13 | +import cn.jiguang.analytics.android.api.AccountCallback; |
9 | 14 | import cn.jiguang.analytics.android.api.BrowseEvent; |
10 | 15 | import cn.jiguang.analytics.android.api.CalculateEvent; |
11 | 16 | import cn.jiguang.analytics.android.api.CountEvent; |
@@ -130,4 +135,67 @@ public void stopLogPageView(ReadableMap map) { |
130 | 135 | if (getCurrentActivity() != null) |
131 | 136 | JAnalyticsInterface.onPageEnd(getCurrentActivity(), name); |
132 | 137 | } |
| 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 | + } |
133 | 201 | } |
0 commit comments