xugenyuan

ref |> 新增埋点封装

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -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 }
  1 +/node_modules
  2 +/oh_modules
  3 +/.preview
  4 +/build
  5 +/.cxx
  6 +/.test
  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 +import { hspTasks } from '@ohos/hvigor-ohos-plugin';
  2 +
  3 +export default {
  4 + system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
  5 + plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
  6 +}
  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 +{
  2 + "meta": {
  3 + "stableOrder": true
  4 + },
  5 + "lockfileVersion": 3,
  6 + "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
  7 + "specifiers": {
  8 + "@ohos/axios@^2.1.1": "@ohos/axios@2.2.0",
  9 + "@sensorsdata/analytics@^0.0.2": "@sensorsdata/analytics@0.0.2",
  10 + "@umeng/analytics@^1.0.19": "@umeng/analytics@1.0.19",
  11 + "@umeng/common@^1.0.21": "@umeng/common@1.0.21",
  12 + "libcommon.so@../../oh_modules/.ohpm/@umeng+common@1.0.21/oh_modules/@umeng/common/src/main/cpp/types/libcommon": "libcommon.so@../../oh_modules/.ohpm/@umeng+common@1.0.21/oh_modules/@umeng/common/src/main/cpp/types/libcommon",
  13 + "wdBean@../wdBean": "wdBean@../wdBean",
  14 + "wdConstant@../../commons/wdConstant": "wdConstant@../../commons/wdConstant",
  15 + "wdHwAbility@../wdHwAbility": "wdHwAbility@../wdHwAbility",
  16 + "wdJsBridge@../../commons/wdJsBridge": "wdJsBridge@../../commons/wdJsBridge",
  17 + "wdKit@../../commons/wdKit": "wdKit@../../commons/wdKit",
  18 + "wdLogin@../wdLogin": "wdLogin@../wdLogin",
  19 + "wdNetwork@../../commons/wdNetwork": "wdNetwork@../../commons/wdNetwork",
  20 + "wdRouter@../../commons/wdRouter": "wdRouter@../../commons/wdRouter",
  21 + "wdWebComponent@../../commons/wdWebComponent": "wdWebComponent@../../commons/wdWebComponent"
  22 + },
  23 + "packages": {
  24 + "@ohos/axios@2.2.0": {
  25 + "name": "@ohos/axios",
  26 + "integrity": "sha512-v1QBWk6DfcN8wUW3D0ieFbHTR1taSI5cOgxp5l6B5cegXuNYhSc8ggKlAIXe6h/14LsfM+NW0ZGfSXcNEIM5yA==",
  27 + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/axios/-/axios-2.2.0.har",
  28 + "registryType": "ohpm"
  29 + },
  30 + "@sensorsdata/analytics@0.0.2": {
  31 + "name": "@sensorsdata/analytics",
  32 + "integrity": "sha512-SQCEmOw8ftGJmKtPl/1qUczZqu/yoQ4F2QHpK2Mayk+XctvNDSHn4QWengHj/pg36AopvuVfa0i6KR9c4KiIuQ==",
  33 + "resolved": "https://ohpm.openharmony.cn/ohpm/@sensorsdata/analytics/-/analytics-0.0.2.har",
  34 + "registryType": "ohpm"
  35 + },
  36 + "@umeng/analytics@1.0.19": {
  37 + "name": "@umeng/analytics",
  38 + "integrity": "sha512-0m9z5l8to+POjDl9UkCQC8s4P+e2E1OILwUglC7ME4QwqfH44e59GLJtQdwF0h6kwpsy3YBft4SoWK8MYbuP7g==",
  39 + "resolved": "https://ohpm.openharmony.cn/ohpm/@umeng/analytics/-/analytics-1.0.19.har",
  40 + "registryType": "ohpm"
  41 + },
  42 + "@umeng/common@1.0.21": {
  43 + "name": "@umeng/common",
  44 + "integrity": "sha512-EbXsd4OoRisTQf5egNY/+z1D2bvrYw9VwC2xu3EJA9TiDPSbnaJZ5+yltA/Se6yZ4oCcFvq6e5/AAfPuumunbw==",
  45 + "resolved": "https://ohpm.openharmony.cn/ohpm/@umeng/common/-/common-1.0.21.har",
  46 + "registryType": "ohpm",
  47 + "dependencies": {
  48 + "libcommon.so": "./src/main/cpp/types/libcommon"
  49 + }
  50 + },
  51 + "libcommon.so@../../oh_modules/.ohpm/@umeng+common@1.0.21/oh_modules/@umeng/common/src/main/cpp/types/libcommon": {
  52 + "name": "libcommon.so",
  53 + "resolved": "../../oh_modules/.ohpm/@umeng+common@1.0.21/oh_modules/@umeng/common/src/main/cpp/types/libcommon",
  54 + "registryType": "local"
  55 + },
  56 + "wdBean@../wdBean": {
  57 + "name": "wdbean",
  58 + "resolved": "../wdBean",
  59 + "registryType": "local"
  60 + },
  61 + "wdConstant@../../commons/wdConstant": {
  62 + "name": "wdconstant",
  63 + "resolved": "../../commons/wdConstant",
  64 + "registryType": "local"
  65 + },
  66 + "wdHwAbility@../wdHwAbility": {
  67 + "name": "wdhwability",
  68 + "resolved": "../wdHwAbility",
  69 + "registryType": "local",
  70 + "dependencies": {
  71 + "wdConstant": "file:../../commons/wdConstant",
  72 + "wdLogin": "file:../../features/wdLogin",
  73 + "wdKit": "file:../../commons/wdKit",
  74 + "wdBean": "file:../../features/wdBean",
  75 + "wdNetwork": "file:../../commons/wdNetwork"
  76 + },
  77 + "packageType": "InterfaceHar"
  78 + },
  79 + "wdJsBridge@../../commons/wdJsBridge": {
  80 + "name": "wdjsbridge",
  81 + "resolved": "../../commons/wdJsBridge",
  82 + "registryType": "local"
  83 + },
  84 + "wdKit@../../commons/wdKit": {
  85 + "name": "wdkit",
  86 + "resolved": "../../commons/wdKit",
  87 + "registryType": "local",
  88 + "dependencies": {
  89 + "@umeng/common": "^1.0.21",
  90 + "@umeng/analytics": "^1.0.19"
  91 + }
  92 + },
  93 + "wdLogin@../wdLogin": {
  94 + "name": "wdlogin",
  95 + "resolved": "../wdLogin",
  96 + "registryType": "local",
  97 + "dependencies": {
  98 + "wdConstant": "file:../../commons/wdConstant",
  99 + "wdKit": "file:../../commons/wdKit",
  100 + "wdWebComponent": "file:../../commons/wdWebComponent",
  101 + "wdBean": "file:../../features/wdBean",
  102 + "wdRouter": "file:../../commons/wdRouter",
  103 + "wdNetwork": "file:../../commons/wdNetwork"
  104 + }
  105 + },
  106 + "wdNetwork@../../commons/wdNetwork": {
  107 + "name": "wdnetwork",
  108 + "resolved": "../../commons/wdNetwork",
  109 + "registryType": "local",
  110 + "dependencies": {
  111 + "wdConstant": "file:../wdConstant",
  112 + "wdKit": "file:../wdKit",
  113 + "@ohos/axios": "^2.1.1"
  114 + }
  115 + },
  116 + "wdRouter@../../commons/wdRouter": {
  117 + "name": "wdrouter",
  118 + "resolved": "../../commons/wdRouter",
  119 + "registryType": "local",
  120 + "dependencies": {
  121 + "wdKit": "file:../wdKit",
  122 + "wdBean": "file:../../features/wdBean",
  123 + "wdNetwork": "file:../../commons/wdNetwork",
  124 + "wdConstant": "file:../../commons/wdConstant"
  125 + }
  126 + },
  127 + "wdWebComponent@../../commons/wdWebComponent": {
  128 + "name": "wdwebcomponent",
  129 + "resolved": "../../commons/wdWebComponent",
  130 + "registryType": "local",
  131 + "dependencies": {
  132 + "wdConstant": "file:../wdConstant",
  133 + "wdKit": "file:../wdKit",
  134 + "wdJsBridge": "file:../wdJsBridge",
  135 + "wdBean": "file:../../features/wdBean",
  136 + "wdRouter": "file:../wdRouter",
  137 + "wdNetwork": "file:../wdNetwork"
  138 + }
  139 + }
  140 + }
  141 +}
  1 +{
  2 + "name": "wdtracking",
  3 + "version": "1.0.0",
  4 + "description": "Please describe the basic information.",
  5 + "main": "Index.ets",
  6 + "author": "",
  7 + "license": "Apache-2.0",
  8 + "packageType": "InterfaceHar",
  9 + "dependencies": {
  10 + "@sensorsdata/analytics": "^0.0.2",
  11 + "wdKit": "file:../../commons/wdKit",
  12 + "wdBean": "file:../../features/wdBean",
  13 + "wdNetwork": "file:../../commons/wdNetwork",
  14 + "wdHwAbility": "file:../../features/wdHwAbility",
  15 + "wdConstant": "file:../../commons/wdConstant"
  16 + }
  17 +}
  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 +@Entry
  2 +@Component
  3 +struct Index {
  4 + @State message: string = 'Hello World';
  5 +
  6 + build() {
  7 + Row() {
  8 + Column() {
  9 + Text(this.message)
  10 + .fontSize(50)
  11 + .fontWeight(FontWeight.Bold)
  12 + }
  13 + .width('100%')
  14 + }
  15 + .height('100%')
  16 + }
  17 +}
  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 +{
  2 + "module": {
  3 + "name": "wdTracking",
  4 + "type": "shared",
  5 + "description": "$string:shared_desc",
  6 + "deviceTypes": [
  7 + "phone",
  8 + "tablet",
  9 + "2in1"
  10 + ],
  11 + "deliveryWithInstall": true,
  12 + "pages": "$profile:main_pages"
  13 + }
  14 +}
  1 +{
  2 + "color": [
  3 + {
  4 + "name": "white",
  5 + "value": "#FFFFFF"
  6 + }
  7 + ]
  8 +}
  1 +{
  2 + "string": [
  3 + {
  4 + "name": "shared_desc",
  5 + "value": "埋点封装库"
  6 + }
  7 + ]
  8 +}
  1 +import localUnitTest from './LocalUnit.test';
  2 +
  3 +export default function testsuite() {
  4 + localUnitTest();
  5 +}
  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 //获取本地存储的启动页数据