ref |> Revert "Revert "ref |> 新增埋点封装""
This reverts commit c9b1e177.
Showing
23 changed files
with
309 additions
and
6 deletions
| @@ -268,6 +268,18 @@ | @@ -268,6 +268,18 @@ | ||
| 268 | ] | 268 | ] |
| 269 | } | 269 | } |
| 270 | ] | 270 | ] |
| 271 | + }, | ||
| 272 | + { | ||
| 273 | + "name": "wdTracking", | ||
| 274 | + "srcPath": "./features/wdTracking", | ||
| 275 | + "targets": [ | ||
| 276 | + { | ||
| 277 | + "name": "default", | ||
| 278 | + "applyToProducts": [ | ||
| 279 | + "default" | ||
| 280 | + ] | ||
| 281 | + } | ||
| 282 | + ] | ||
| 271 | } | 283 | } |
| 272 | ] | 284 | ] |
| 273 | } | 285 | } |
sight_harmony/features/wdTracking/.gitignore
0 → 100644
sight_harmony/features/wdTracking/Index.ets
0 → 100644
| 1 | +export { TrackingModule } from "./src/main/ets/TrackingModule" |
| 1 | +{ | ||
| 2 | + "apiType": "stageMode", | ||
| 3 | + "buildOption": { | ||
| 4 | + }, | ||
| 5 | + "buildOptionSet": [ | ||
| 6 | + { | ||
| 7 | + "name": "release", | ||
| 8 | + "arkOptions": { | ||
| 9 | + "obfuscation": { | ||
| 10 | + "ruleOptions": { | ||
| 11 | + "enable": true, | ||
| 12 | + "files": [ | ||
| 13 | + "./obfuscation-rules.txt" | ||
| 14 | + ] | ||
| 15 | + } | ||
| 16 | + } | ||
| 17 | + }, | ||
| 18 | + }, | ||
| 19 | + ], | ||
| 20 | + "targets": [ | ||
| 21 | + { | ||
| 22 | + "name": "default" | ||
| 23 | + } | ||
| 24 | + ] | ||
| 25 | +} |
| 1 | +# Define project specific obfuscation rules here. | ||
| 2 | +# You can include the obfuscation configuration files in the current module's build-profile.json5. | ||
| 3 | +# | ||
| 4 | +# For more details, see | ||
| 5 | +# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md | ||
| 6 | + | ||
| 7 | +# Obfuscation options: | ||
| 8 | +# -disable-obfuscation: disable all obfuscations | ||
| 9 | +# -enable-property-obfuscation: obfuscate the property names | ||
| 10 | +# -enable-toplevel-obfuscation: obfuscate the names in the global scope | ||
| 11 | +# -compact: remove unnecessary blank spaces and all line feeds | ||
| 12 | +# -remove-log: remove all console.* statements | ||
| 13 | +# -print-namecache: print the name cache that contains the mapping from the old names to new names | ||
| 14 | +# -apply-namecache: reuse the given cache file | ||
| 15 | + | ||
| 16 | +# Keep options: | ||
| 17 | +# -keep-property-name: specifies property names that you want to keep | ||
| 18 | +# -keep-global-name: specifies names that you want to keep in the global scope |
| 1 | -../../../../oh_modules/.ohpm/@sensorsdata+analytics@0.0.2/oh_modules/@sensorsdata/analytics |
| 1 | -../../wdBean |
| 1 | -../../../commons/wdConstant |
| 1 | -../../../commons/wdKit |
| 1 | -../../../commons/wdNetwork |
| 1 | +import sensors from '@sensorsdata/analytics'; | ||
| 2 | +import { common } from '@kit.AbilityKit'; | ||
| 3 | +import { HostEnum, HostManager } from 'wdNetwork/Index'; | ||
| 4 | + | ||
| 5 | +/// 统计埋点模块 | ||
| 6 | +export class TrackingModule { | ||
| 7 | + | ||
| 8 | + private static _init = false | ||
| 9 | + static getHasInit() { | ||
| 10 | + return TrackingModule._init; | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + /// 初始化 | ||
| 14 | + static startup(context: common.UIAbilityContext) { | ||
| 15 | + | ||
| 16 | + // const isOnlineEnv = HostManager.getHost() === HostEnum.HOST_PRODUCT | ||
| 17 | + // | ||
| 18 | + // sensors.init({ | ||
| 19 | + // // 服务器接收地址 | ||
| 20 | + // server_url: isOnlineEnv ? '正式地址' : "测试地址", | ||
| 21 | + // // Ability 上下文 | ||
| 22 | + // context: context, | ||
| 23 | + // // 是否显示日志 | ||
| 24 | + // show_log: true, | ||
| 25 | + // // 是否开启采集位置信息,需要 app 授权,默认 false | ||
| 26 | + // enable_track_location: true, | ||
| 27 | + // // 是否开启批量发送,默认 false | ||
| 28 | + // batch_send: true, | ||
| 29 | + // // 数据发送超时时间 | ||
| 30 | + // datasend_timeout: 10000, | ||
| 31 | + // // 开启 App 打通 H5 | ||
| 32 | + // app_js_bridge: false | ||
| 33 | + // }); | ||
| 34 | + // TrackingModule._init = true | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + | ||
| 38 | +} |
| 1 | +import { SpConstants } from 'wdConstant/Index'; | ||
| 2 | +import { DeviceUtil, SPHelper, StringUtils } from 'wdKit/Index'; | ||
| 3 | +import { HostEnum, HostManager } from 'wdNetwork/Index'; | ||
| 4 | + | ||
| 5 | +export type ParamType = Record<string, string | number | boolean | Array<string>> | ||
| 6 | + | ||
| 7 | +export class PublicParams { | ||
| 8 | + | ||
| 9 | + getPublicParams() : Promise<ParamType> { | ||
| 10 | + return new Promise((resolve) => { | ||
| 11 | + | ||
| 12 | + let pub: ParamType = { | ||
| 13 | + "userName":"", | ||
| 14 | + "pdUseId":"", | ||
| 15 | + "creatorId":"", | ||
| 16 | + "pdCnsBirthday":"", | ||
| 17 | + "city": PublicParams.getLocationCity(), | ||
| 18 | + "sex":"", | ||
| 19 | + "isSign":"0", | ||
| 20 | + "environment": PublicParams.getEnv(), | ||
| 21 | + "os": "harmonyos", | ||
| 22 | + "actionTime": new Date().getTime() * 0.001, | ||
| 23 | + "channel": "rmrb_china_0000", | ||
| 24 | + "version": PublicParams.getVersionName(), | ||
| 25 | + "deviceId": DeviceUtil.clientId(), | ||
| 26 | + "model":"", | ||
| 27 | + "mpaasId": PublicParams.getMpaasId(), | ||
| 28 | + } | ||
| 29 | + resolve(pub) | ||
| 30 | + }) | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + private static getEnv() { | ||
| 34 | + switch (HostManager.getHost()) { | ||
| 35 | + case HostEnum.HOST_UAT: | ||
| 36 | + return "uat" | ||
| 37 | + case HostEnum.HOST_SIT: | ||
| 38 | + return "sit" | ||
| 39 | + case HostEnum.HOST_PRODUCT: | ||
| 40 | + return "prod" | ||
| 41 | + case HostEnum.HOST_DEV: | ||
| 42 | + return "dev" | ||
| 43 | + default: | ||
| 44 | + return "prod" | ||
| 45 | + } | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + private static getLocationCity() { | ||
| 49 | + let cityName = SPHelper.default.getSync(SpConstants.LOCATION_CITY_NAME, '') as string | ||
| 50 | + if (StringUtils.isNotEmpty(cityName)) { | ||
| 51 | + return encodeURI(cityName) | ||
| 52 | + } | ||
| 53 | + return "" | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + private static getBuildVersion() { | ||
| 57 | + // TODO | ||
| 58 | + return '202401242103'; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + private static getVersionCode() { | ||
| 62 | + // TODO | ||
| 63 | + return '10000'; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + private static getVersionName() { | ||
| 67 | + // TODO 读取配置 | ||
| 68 | + return '1.0.0'; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + private static getMpaasId() { | ||
| 72 | + // TODO | ||
| 73 | + return 'alsjdflajxaljdlfjaldjfa'; | ||
| 74 | + } | ||
| 75 | +} |
| 1 | +import { Logger } from 'wdKit/Index'; | ||
| 2 | +import { TrackingModule } from '../TrackingModule'; | ||
| 3 | +import sensors from '@sensorsdata/analytics'; | ||
| 4 | +import { ParamType, PublicParams } from './PublicParams'; | ||
| 5 | +import { HashMap } from '@kit.ArkTS'; | ||
| 6 | + | ||
| 7 | +const TAG = "WDTracking" | ||
| 8 | + | ||
| 9 | +export class Tracking { | ||
| 10 | + | ||
| 11 | + static event(eventId: string, params?: ParamType) { | ||
| 12 | + | ||
| 13 | + if (!TrackingModule.getHasInit()) { | ||
| 14 | + Logger.warn(TAG, "还没有初始化 " + eventId + " " + JSON.stringify(params)) | ||
| 15 | + return | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + //TODO: 添加运行单独线程? | ||
| 19 | + | ||
| 20 | + let publicParams = new PublicParams() | ||
| 21 | + publicParams.getPublicParams().then((pubParams) => { | ||
| 22 | + | ||
| 23 | + if (params) { | ||
| 24 | + for (const obj of Object.entries(params)) { | ||
| 25 | + Logger.info(TAG, ` ${obj[0]} => ` + `${obj[1]}`); | ||
| 26 | + pubParams[obj[0]] = obj[1] | ||
| 27 | + } | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + sensors.track(eventId, pubParams) | ||
| 31 | + }) | ||
| 32 | + } | ||
| 33 | +} |
| 1 | +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; | ||
| 2 | + | ||
| 3 | +export default function localUnitTest() { | ||
| 4 | + describe('localUnitTest',() => { | ||
| 5 | + // Defines a test suite. Two parameters are supported: test suite name and test suite function. | ||
| 6 | + beforeAll(() => { | ||
| 7 | + // Presets an action, which is performed only once before all test cases of the test suite start. | ||
| 8 | + // This API supports only one parameter: preset action function. | ||
| 9 | + }); | ||
| 10 | + beforeEach(() => { | ||
| 11 | + // Presets an action, which is performed before each unit test case starts. | ||
| 12 | + // The number of execution times is the same as the number of test cases defined by **it**. | ||
| 13 | + // This API supports only one parameter: preset action function. | ||
| 14 | + }); | ||
| 15 | + afterEach(() => { | ||
| 16 | + // Presets a clear action, which is performed after each unit test case ends. | ||
| 17 | + // The number of execution times is the same as the number of test cases defined by **it**. | ||
| 18 | + // This API supports only one parameter: clear action function. | ||
| 19 | + }); | ||
| 20 | + afterAll(() => { | ||
| 21 | + // Presets a clear action, which is performed after all test cases of the test suite end. | ||
| 22 | + // This API supports only one parameter: clear action function. | ||
| 23 | + }); | ||
| 24 | + it('assertContain', 0, () => { | ||
| 25 | + // Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function. | ||
| 26 | + let a = 'abc'; | ||
| 27 | + let b = 'b'; | ||
| 28 | + // Defines a variety of assertion methods, which are used to declare expected boolean conditions. | ||
| 29 | + expect(a).assertContain(b); | ||
| 30 | + expect(a).assertEqual(a); | ||
| 31 | + }); | ||
| 32 | + }); | ||
| 33 | +} |
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | "wdNetwork": "file:../../commons/wdNetwork", | 17 | "wdNetwork": "file:../../commons/wdNetwork", |
| 18 | "wdHwAbility": "file:../../features/wdHwAbility", | 18 | "wdHwAbility": "file:../../features/wdHwAbility", |
| 19 | "wdJsBridge": "file:../../commons/wdJsBridge", | 19 | "wdJsBridge": "file:../../commons/wdJsBridge", |
| 20 | - "wdLogin": "file:../../features/wdLogin" | 20 | + "wdLogin": "file:../../features/wdLogin", |
| 21 | + "wdTracking": "file:../../features/wdTracking" | ||
| 21 | } | 22 | } |
| 22 | } | 23 | } |
| @@ -13,6 +13,7 @@ import { LaunchPageModel } from '../viewModel/LaunchPageModel' | @@ -13,6 +13,7 @@ import { LaunchPageModel } from '../viewModel/LaunchPageModel' | ||
| 13 | import LaunchDataModel from '../viewModel/LaunchDataModel' | 13 | import LaunchDataModel from '../viewModel/LaunchDataModel' |
| 14 | import { Logger, SPHelper, UmengStats } from 'wdKit/Index'; | 14 | import { Logger, SPHelper, UmengStats } from 'wdKit/Index'; |
| 15 | import { SpConstants } from 'wdConstant/Index'; | 15 | import { SpConstants } from 'wdConstant/Index'; |
| 16 | +import { TrackingModule } from 'wdTracking/Index' | ||
| 16 | 17 | ||
| 17 | @Entry | 18 | @Entry |
| 18 | @Component | 19 | @Component |
| @@ -45,6 +46,7 @@ struct LaunchPage { | @@ -45,6 +46,7 @@ struct LaunchPage { | ||
| 45 | 46 | ||
| 46 | onConfirm() { | 47 | onConfirm() { |
| 47 | UmengStats.initAfterAgreeProtocol() | 48 | UmengStats.initAfterAgreeProtocol() |
| 49 | + TrackingModule.startup(getContext(this) as common.UIAbilityContext) | ||
| 48 | // Save privacy agreement status. | 50 | // Save privacy agreement status. |
| 49 | this.saveIsPrivacy(); | 51 | this.saveIsPrivacy(); |
| 50 | //跳转引导页 | 52 | //跳转引导页 |
| @@ -97,6 +99,7 @@ struct LaunchPage { | @@ -97,6 +99,7 @@ struct LaunchPage { | ||
| 97 | } else { | 99 | } else { |
| 98 | 100 | ||
| 99 | UmengStats.initAfterAgreeProtocol() | 101 | UmengStats.initAfterAgreeProtocol() |
| 102 | + TrackingModule.startup(getContext(this) as common.UIAbilityContext) | ||
| 100 | 103 | ||
| 101 | //需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页 | 104 | //需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页 |
| 102 | //获取本地存储的启动页数据 | 105 | //获取本地存储的启动页数据 |
-
Please register or login to post a comment