xugenyuan

ref |> 新增埋点封装

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
... ... @@ -268,6 +268,18 @@
]
}
]
},
{
"name": "wdTracking",
"srcPath": "./features/wdTracking",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
\ No newline at end of file
... ...
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
... ...
export { TrackingModule } from "./src/main/ets/TrackingModule"
\ No newline at end of file
... ...
{
"apiType": "stageMode",
"buildOption": {
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
},
},
],
"targets": [
{
"name": "default"
}
]
}
\ No newline at end of file
... ...
import { hspTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
... ...
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
\ No newline at end of file
... ...
{
"meta": {
"stableOrder": true
},
"lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/axios@^2.1.1": "@ohos/axios@2.2.0",
"@sensorsdata/analytics@^0.0.2": "@sensorsdata/analytics@0.0.2",
"@umeng/analytics@^1.0.19": "@umeng/analytics@1.0.19",
"@umeng/common@^1.0.21": "@umeng/common@1.0.21",
"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",
"wdBean@../wdBean": "wdBean@../wdBean",
"wdConstant@../../commons/wdConstant": "wdConstant@../../commons/wdConstant",
"wdHwAbility@../wdHwAbility": "wdHwAbility@../wdHwAbility",
"wdJsBridge@../../commons/wdJsBridge": "wdJsBridge@../../commons/wdJsBridge",
"wdKit@../../commons/wdKit": "wdKit@../../commons/wdKit",
"wdLogin@../wdLogin": "wdLogin@../wdLogin",
"wdNetwork@../../commons/wdNetwork": "wdNetwork@../../commons/wdNetwork",
"wdRouter@../../commons/wdRouter": "wdRouter@../../commons/wdRouter",
"wdWebComponent@../../commons/wdWebComponent": "wdWebComponent@../../commons/wdWebComponent"
},
"packages": {
"@ohos/axios@2.2.0": {
"name": "@ohos/axios",
"integrity": "sha512-v1QBWk6DfcN8wUW3D0ieFbHTR1taSI5cOgxp5l6B5cegXuNYhSc8ggKlAIXe6h/14LsfM+NW0ZGfSXcNEIM5yA==",
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/axios/-/axios-2.2.0.har",
"registryType": "ohpm"
},
"@sensorsdata/analytics@0.0.2": {
"name": "@sensorsdata/analytics",
"integrity": "sha512-SQCEmOw8ftGJmKtPl/1qUczZqu/yoQ4F2QHpK2Mayk+XctvNDSHn4QWengHj/pg36AopvuVfa0i6KR9c4KiIuQ==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@sensorsdata/analytics/-/analytics-0.0.2.har",
"registryType": "ohpm"
},
"@umeng/analytics@1.0.19": {
"name": "@umeng/analytics",
"integrity": "sha512-0m9z5l8to+POjDl9UkCQC8s4P+e2E1OILwUglC7ME4QwqfH44e59GLJtQdwF0h6kwpsy3YBft4SoWK8MYbuP7g==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@umeng/analytics/-/analytics-1.0.19.har",
"registryType": "ohpm"
},
"@umeng/common@1.0.21": {
"name": "@umeng/common",
"integrity": "sha512-EbXsd4OoRisTQf5egNY/+z1D2bvrYw9VwC2xu3EJA9TiDPSbnaJZ5+yltA/Se6yZ4oCcFvq6e5/AAfPuumunbw==",
"resolved": "https://ohpm.openharmony.cn/ohpm/@umeng/common/-/common-1.0.21.har",
"registryType": "ohpm",
"dependencies": {
"libcommon.so": "./src/main/cpp/types/libcommon"
}
},
"libcommon.so@../../oh_modules/.ohpm/@umeng+common@1.0.21/oh_modules/@umeng/common/src/main/cpp/types/libcommon": {
"name": "libcommon.so",
"resolved": "../../oh_modules/.ohpm/@umeng+common@1.0.21/oh_modules/@umeng/common/src/main/cpp/types/libcommon",
"registryType": "local"
},
"wdBean@../wdBean": {
"name": "wdbean",
"resolved": "../wdBean",
"registryType": "local"
},
"wdConstant@../../commons/wdConstant": {
"name": "wdconstant",
"resolved": "../../commons/wdConstant",
"registryType": "local"
},
"wdHwAbility@../wdHwAbility": {
"name": "wdhwability",
"resolved": "../wdHwAbility",
"registryType": "local",
"dependencies": {
"wdConstant": "file:../../commons/wdConstant",
"wdLogin": "file:../../features/wdLogin",
"wdKit": "file:../../commons/wdKit",
"wdBean": "file:../../features/wdBean",
"wdNetwork": "file:../../commons/wdNetwork"
},
"packageType": "InterfaceHar"
},
"wdJsBridge@../../commons/wdJsBridge": {
"name": "wdjsbridge",
"resolved": "../../commons/wdJsBridge",
"registryType": "local"
},
"wdKit@../../commons/wdKit": {
"name": "wdkit",
"resolved": "../../commons/wdKit",
"registryType": "local",
"dependencies": {
"@umeng/common": "^1.0.21",
"@umeng/analytics": "^1.0.19"
}
},
"wdLogin@../wdLogin": {
"name": "wdlogin",
"resolved": "../wdLogin",
"registryType": "local",
"dependencies": {
"wdConstant": "file:../../commons/wdConstant",
"wdKit": "file:../../commons/wdKit",
"wdWebComponent": "file:../../commons/wdWebComponent",
"wdBean": "file:../../features/wdBean",
"wdRouter": "file:../../commons/wdRouter",
"wdNetwork": "file:../../commons/wdNetwork"
}
},
"wdNetwork@../../commons/wdNetwork": {
"name": "wdnetwork",
"resolved": "../../commons/wdNetwork",
"registryType": "local",
"dependencies": {
"wdConstant": "file:../wdConstant",
"wdKit": "file:../wdKit",
"@ohos/axios": "^2.1.1"
}
},
"wdRouter@../../commons/wdRouter": {
"name": "wdrouter",
"resolved": "../../commons/wdRouter",
"registryType": "local",
"dependencies": {
"wdKit": "file:../wdKit",
"wdBean": "file:../../features/wdBean",
"wdNetwork": "file:../../commons/wdNetwork",
"wdConstant": "file:../../commons/wdConstant"
}
},
"wdWebComponent@../../commons/wdWebComponent": {
"name": "wdwebcomponent",
"resolved": "../../commons/wdWebComponent",
"registryType": "local",
"dependencies": {
"wdConstant": "file:../wdConstant",
"wdKit": "file:../wdKit",
"wdJsBridge": "file:../wdJsBridge",
"wdBean": "file:../../features/wdBean",
"wdRouter": "file:../wdRouter",
"wdNetwork": "file:../wdNetwork"
}
}
}
}
\ No newline at end of file
... ...
{
"name": "wdtracking",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"packageType": "InterfaceHar",
"dependencies": {
"@sensorsdata/analytics": "^0.0.2",
"wdKit": "file:../../commons/wdKit",
"wdBean": "file:../../features/wdBean",
"wdNetwork": "file:../../commons/wdNetwork",
"wdHwAbility": "file:../../features/wdHwAbility",
"wdConstant": "file:../../commons/wdConstant"
}
}
\ No newline at end of file
... ...
import sensors from '@sensorsdata/analytics';
import { common } from '@kit.AbilityKit';
import { HostEnum, HostManager } from 'wdNetwork/Index';
/// 统计埋点模块
export class TrackingModule {
private static _init = false
static getHasInit() {
return TrackingModule._init;
}
/// 初始化
static startup(context: common.UIAbilityContext) {
// const isOnlineEnv = HostManager.getHost() === HostEnum.HOST_PRODUCT
//
// sensors.init({
// // 服务器接收地址
// server_url: isOnlineEnv ? '正式地址' : "测试地址",
// // Ability 上下文
// context: context,
// // 是否显示日志
// show_log: true,
// // 是否开启采集位置信息,需要 app 授权,默认 false
// enable_track_location: true,
// // 是否开启批量发送,默认 false
// batch_send: true,
// // 数据发送超时时间
// datasend_timeout: 10000,
// // 开启 App 打通 H5
// app_js_bridge: false
// });
// TrackingModule._init = true
}
}
\ No newline at end of file
... ...
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
... ...
import { SpConstants } from 'wdConstant/Index';
import { DeviceUtil, SPHelper, StringUtils } from 'wdKit/Index';
import { HostEnum, HostManager } from 'wdNetwork/Index';
export type ParamType = Record<string, string | number | boolean | Array<string>>
export class PublicParams {
getPublicParams() : Promise<ParamType> {
return new Promise((resolve) => {
let pub: ParamType = {
"userName":"",
"pdUseId":"",
"creatorId":"",
"pdCnsBirthday":"",
"city": PublicParams.getLocationCity(),
"sex":"",
"isSign":"0",
"environment": PublicParams.getEnv(),
"os": "harmonyos",
"actionTime": new Date().getTime() * 0.001,
"channel": "rmrb_china_0000",
"version": PublicParams.getVersionName(),
"deviceId": DeviceUtil.clientId(),
"model":"",
"mpaasId": PublicParams.getMpaasId(),
}
resolve(pub)
})
}
private static getEnv() {
switch (HostManager.getHost()) {
case HostEnum.HOST_UAT:
return "uat"
case HostEnum.HOST_SIT:
return "sit"
case HostEnum.HOST_PRODUCT:
return "prod"
case HostEnum.HOST_DEV:
return "dev"
default:
return "prod"
}
}
private static getLocationCity() {
let cityName = SPHelper.default.getSync(SpConstants.LOCATION_CITY_NAME, '') as string
if (StringUtils.isNotEmpty(cityName)) {
return encodeURI(cityName)
}
return ""
}
private static getBuildVersion() {
// TODO
return '202401242103';
}
private static getVersionCode() {
// TODO
return '10000';
}
private static getVersionName() {
// TODO 读取配置
return '1.0.0';
}
private static getMpaasId() {
// TODO
return 'alsjdflajxaljdlfjaldjfa';
}
}
... ...
import { Logger } from 'wdKit/Index';
import { TrackingModule } from '../TrackingModule';
import sensors from '@sensorsdata/analytics';
import { ParamType, PublicParams } from './PublicParams';
import { HashMap } from '@kit.ArkTS';
const TAG = "WDTracking"
export class Tracking {
static event(eventId: string, params?: ParamType) {
if (!TrackingModule.getHasInit()) {
Logger.warn(TAG, "还没有初始化 " + eventId + " " + JSON.stringify(params))
return
}
//TODO: 添加运行单独线程?
let publicParams = new PublicParams()
publicParams.getPublicParams().then((pubParams) => {
if (params) {
for (const obj of Object.entries(params)) {
Logger.info(TAG, ` ${obj[0]} => ` + `${obj[1]}`);
pubParams[obj[0]] = obj[1]
}
}
sensors.track(eventId, pubParams)
})
}
}
\ No newline at end of file
... ...
{
"module": {
"name": "wdTracking",
"type": "shared",
"description": "$string:shared_desc",
"deviceTypes": [
"phone",
"tablet",
"2in1"
],
"deliveryWithInstall": true,
"pages": "$profile:main_pages"
}
}
\ No newline at end of file
... ...
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
... ...
{
"string": [
{
"name": "shared_desc",
"value": "埋点封装库"
}
]
}
\ No newline at end of file
... ...
import localUnitTest from './LocalUnit.test';
export default function testsuite() {
localUnitTest();
}
\ No newline at end of file
... ...
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
export default function localUnitTest() {
describe('localUnitTest',() => {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(() => {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
});
beforeEach(() => {
// Presets an action, which is performed before each unit test case starts.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: preset action function.
});
afterEach(() => {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
});
afterAll(() => {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
});
it('assertContain', 0, () => {
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
let a = 'abc';
let b = 'b';
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
expect(a).assertContain(b);
expect(a).assertEqual(a);
});
});
}
\ No newline at end of file
... ...
... ... @@ -17,6 +17,7 @@
"wdNetwork": "file:../../commons/wdNetwork",
"wdHwAbility": "file:../../features/wdHwAbility",
"wdJsBridge": "file:../../commons/wdJsBridge",
"wdLogin": "file:../../features/wdLogin"
"wdLogin": "file:../../features/wdLogin",
"wdTracking": "file:../../features/wdTracking"
}
}
... ...
... ... @@ -13,6 +13,7 @@ import { LaunchPageModel } from '../viewModel/LaunchPageModel'
import LaunchDataModel from '../viewModel/LaunchDataModel'
import { Logger, SPHelper, UmengStats } from 'wdKit/Index';
import { SpConstants } from 'wdConstant/Index';
import { TrackingModule } from 'wdTracking/Index'
@Entry
@Component
... ... @@ -45,6 +46,7 @@ struct LaunchPage {
onConfirm() {
UmengStats.initAfterAgreeProtocol()
TrackingModule.startup(getContext(this) as common.UIAbilityContext)
// Save privacy agreement status.
this.saveIsPrivacy();
//跳转引导页
... ... @@ -97,6 +99,7 @@ struct LaunchPage {
} else {
UmengStats.initAfterAgreeProtocol()
TrackingModule.startup(getContext(this) as common.UIAbilityContext)
//需要根据请求数据判断是否需要进入广告页,广告数据为nil则直接跳转到首页
//获取本地存储的启动页数据
... ...