ref |> 新增友盟统计
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
6 changed files
with
73 additions
and
2 deletions
| @@ -49,3 +49,5 @@ export { NetworkUtil } from './src/main/ets/utils/NetworkUtil' | @@ -49,3 +49,5 @@ export { NetworkUtil } from './src/main/ets/utils/NetworkUtil' | ||
| 49 | export { NetworkManager } from './src/main/ets/network/NetworkManager' | 49 | export { NetworkManager } from './src/main/ets/network/NetworkManager' |
| 50 | 50 | ||
| 51 | export { NetworkType } from './src/main/ets/network/NetworkType' | 51 | export { NetworkType } from './src/main/ets/network/NetworkType' |
| 52 | + | ||
| 53 | +export { UmengStats } from "./src/main/ets/umeng/UmengStats" |
| @@ -6,5 +6,8 @@ | @@ -6,5 +6,8 @@ | ||
| 6 | "description": "Please describe the basic information.", | 6 | "description": "Please describe the basic information.", |
| 7 | "main": "Index.ets", | 7 | "main": "Index.ets", |
| 8 | "version": "1.0.0", | 8 | "version": "1.0.0", |
| 9 | - "dependencies": {} | 9 | + "dependencies": { |
| 10 | + "@umeng/common": "^1.0.21", | ||
| 11 | + "@umeng/analytics": "^1.0.19" | ||
| 12 | + } | ||
| 10 | } | 13 | } |
| 1 | +import { preInit, InternalPlugin, setLogEnabled, init, onEventObject, onProfileSignOff, | ||
| 2 | + onProfileSignIn } from '@umeng/analytics'; | ||
| 3 | +import { common } from '@kit.AbilityKit'; | ||
| 4 | +import { AccountManagerUtils } from '../utils/AccountManagerUtils'; | ||
| 5 | +import { UserDataLocal } from '../utils/UserDataLocal'; | ||
| 6 | +import { EmitterUtils } from '../utils/EmitterUtils'; | ||
| 7 | + | ||
| 8 | +export class UmengStats { | ||
| 9 | + | ||
| 10 | + private static _inited = false | ||
| 11 | + | ||
| 12 | + // 启动时调用 | ||
| 13 | + static preInit(context: common.UIAbilityContext) { | ||
| 14 | + | ||
| 15 | + // 需在 AppScope/resources/rawfile/umconfig.json 配置key和channel | ||
| 16 | + preInit({ | ||
| 17 | + context: context.getApplicationContext(), | ||
| 18 | + plugins: [new InternalPlugin()], | ||
| 19 | + enableLog: true | ||
| 20 | + | ||
| 21 | + }); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + // 在用户同意隐私政策后再调用此方法 | ||
| 25 | + static initAfterAgreeProtocol() { | ||
| 26 | + init(); | ||
| 27 | + UmengStats._inited = true | ||
| 28 | + | ||
| 29 | + UmengStats.onLogin() | ||
| 30 | + UmengStats.event("testHarmony", {"key1": "value1"}) | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + // TODO: 登录成功调用 | ||
| 34 | + static onLogin() { | ||
| 35 | + AccountManagerUtils.isLogin().then((login) => { | ||
| 36 | + if (!login) { return } | ||
| 37 | + | ||
| 38 | + let userId = UserDataLocal.getUserId() | ||
| 39 | + if (userId.length > 0) { | ||
| 40 | + onProfileSignIn("USER", userId) | ||
| 41 | + } | ||
| 42 | + }) | ||
| 43 | + } | ||
| 44 | + // TODO: 退出登录调用 | ||
| 45 | + static onLogout() { | ||
| 46 | + onProfileSignOff() | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + // 属性key,128位以内的非空字符串,value为256位以内的数值或字符串 | ||
| 50 | + static event(eventId: string, param?: Record<string, string | number>) { | ||
| 51 | + if (!UmengStats._inited) { | ||
| 52 | + return | ||
| 53 | + } | ||
| 54 | + onEventObject(eventId, param); | ||
| 55 | + } | ||
| 56 | +} |
| @@ -12,6 +12,7 @@ import { | @@ -12,6 +12,7 @@ import { | ||
| 12 | NetworkType, | 12 | NetworkType, |
| 13 | SPHelper, | 13 | SPHelper, |
| 14 | StringUtils, | 14 | StringUtils, |
| 15 | + UmengStats, | ||
| 15 | WindowModel | 16 | WindowModel |
| 16 | } from 'wdKit'; | 17 | } from 'wdKit'; |
| 17 | import { HostEnum, HostManager, WDHttp } from 'wdNetwork'; | 18 | import { HostEnum, HostManager, WDHttp } from 'wdNetwork'; |
| @@ -21,6 +22,7 @@ import { WDPushNotificationManager } from 'wdHwAbility/Index'; | @@ -21,6 +22,7 @@ import { WDPushNotificationManager } from 'wdHwAbility/Index'; | ||
| 21 | 22 | ||
| 22 | export default class EntryAbility extends UIAbility { | 23 | export default class EntryAbility extends UIAbility { |
| 23 | onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { | 24 | onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { |
| 25 | + UmengStats.preInit(this.context) | ||
| 24 | SPHelper.init(this.context); | 26 | SPHelper.init(this.context); |
| 25 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); | 27 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); |
| 26 | registerRouter(); | 28 | registerRouter(); |
| @@ -11,7 +11,7 @@ import { WDRouterPage } from 'wdRouter'; | @@ -11,7 +11,7 @@ import { WDRouterPage } from 'wdRouter'; | ||
| 11 | import { LaunchModel } from '../viewModel/LaunchModel' | 11 | import { LaunchModel } from '../viewModel/LaunchModel' |
| 12 | import { LaunchPageModel } from '../viewModel/LaunchPageModel' | 12 | import { LaunchPageModel } from '../viewModel/LaunchPageModel' |
| 13 | import LaunchDataModel from '../viewModel/LaunchDataModel' | 13 | import LaunchDataModel from '../viewModel/LaunchDataModel' |
| 14 | -import { Logger, SPHelper } from 'wdKit/Index'; | 14 | +import { Logger, SPHelper, UmengStats } from 'wdKit/Index'; |
| 15 | import { SpConstants } from 'wdConstant/Index'; | 15 | import { SpConstants } from 'wdConstant/Index'; |
| 16 | 16 | ||
| 17 | @Entry | 17 | @Entry |
| @@ -44,6 +44,7 @@ struct LaunchPage { | @@ -44,6 +44,7 @@ struct LaunchPage { | ||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | onConfirm() { | 46 | onConfirm() { |
| 47 | + UmengStats.initAfterAgreeProtocol() | ||
| 47 | // Save privacy agreement status. | 48 | // Save privacy agreement status. |
| 48 | this.saveIsPrivacy(); | 49 | this.saveIsPrivacy(); |
| 49 | //跳转引导页 | 50 | //跳转引导页 |
| @@ -94,6 +95,9 @@ struct LaunchPage { | @@ -94,6 +95,9 @@ struct LaunchPage { | ||
| 94 | this.dialogController.open(); | 95 | this.dialogController.open(); |
| 95 | // } | 96 | // } |
| 96 | } else { | 97 | } else { |
| 98 | + | ||
| 99 | + UmengStats.initAfterAgreeProtocol() | ||
| 100 | + | ||
| 97 | //需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页 | 101 | //需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页 |
| 98 | //获取本地存储的启动页数据 | 102 | //获取本地存储的启动页数据 |
| 99 | 103 |
-
Please register or login to post a comment