keytops-game-framework 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +214 -0
  2. package/dist/app/base/RuntimeApplicationImpl.d.ts +22 -0
  3. package/dist/app/base/base.d.ts +113 -0
  4. package/dist/app/base/event/Event.d.ts +12 -0
  5. package/dist/app/base/event/EventDispatcher.d.ts +66 -0
  6. package/dist/app/base/pool/IRecoverable.d.ts +13 -0
  7. package/dist/app/base/pool/Pool.d.ts +45 -0
  8. package/dist/app/base/utils/Handler.d.ts +69 -0
  9. package/dist/app/base/utils/Injector.d.ts +19 -0
  10. package/dist/app/base/utils/Json.d.ts +14 -0
  11. package/dist/app/base/utils/MathUtils.d.ts +74 -0
  12. package/dist/app/base/utils/NativeUtils.d.ts +4 -0
  13. package/dist/app/base/utils/PromiseUtils.d.ts +20 -0
  14. package/dist/app/base/utils/StringUtils.d.ts +66 -0
  15. package/dist/app/module/abTesting/ABTesting.d.ts +41 -0
  16. package/dist/app/module/analytics/ALiAnalyticsSender.d.ts +59 -0
  17. package/dist/app/module/analytics/AnalyticsAble.d.ts +191 -0
  18. package/dist/app/module/analytics/AnalyticsAbleConst.d.ts +20 -0
  19. package/dist/app/module/analytics/BaseDimension.d.ts +19 -0
  20. package/dist/app/module/analytics/KeytopsAnalyticsSender.d.ts +67 -0
  21. package/dist/app/module/analytics/ad/ADAnalyticsAble.d.ts +19 -0
  22. package/dist/app/module/analytics/ad/ADBehaviorReporter.d.ts +90 -0
  23. package/dist/app/module/analytics/ad/AdDimension.d.ts +34 -0
  24. package/dist/app/module/analytics/index.d.ts +65 -0
  25. package/dist/app/module/analytics/launch/LaunchAnalyticsAble.d.ts +11 -0
  26. package/dist/app/module/analytics/level/GameDimension.d.ts +39 -0
  27. package/dist/app/module/analytics/level/LevelAnalyticsAble.d.ts +86 -0
  28. package/dist/app/module/analytics/level/LevelBehaviorReporter.d.ts +29 -0
  29. package/dist/app/module/analytics/level/LevelStatsDimension.d.ts +70 -0
  30. package/dist/app/module/analytics/level/PlayerAbilityDimension.d.ts +147 -0
  31. package/dist/app/module/analytics/session/SessionAnalyticsAble.d.ts +9 -0
  32. package/dist/app/module/analytics/session/SessionDimension.d.ts +48 -0
  33. package/dist/app/module/analytics/social/SocialAnalyticsAble.d.ts +14 -0
  34. package/dist/app/module/analytics/social/SocialDimension.d.ts +14 -0
  35. package/dist/app/module/bidding/Bidding.d.ts +37 -0
  36. package/dist/app/module/business/BusinessCenter.d.ts +33 -0
  37. package/dist/app/module/business/IBusiness.d.ts +6 -0
  38. package/dist/app/module/business/RewardVideoMaskBusiness.d.ts +18 -0
  39. package/dist/app/module/config/ConfigHelper.d.ts +142 -0
  40. package/dist/app/module/ecs/Component.d.ts +125 -0
  41. package/dist/app/module/ecs/ECS.d.ts +162 -0
  42. package/dist/app/module/ecs/ECSManager.d.ts +56 -0
  43. package/dist/app/module/ecs/Entity.d.ts +1 -0
  44. package/dist/app/module/ecs/Mask.d.ts +12 -0
  45. package/dist/app/module/ecs/System.d.ts +54 -0
  46. package/dist/app/module/fsm/Fsm.d.ts +44 -0
  47. package/dist/app/module/fsm/FsmBase.d.ts +28 -0
  48. package/dist/app/module/fsm/FsmManager.d.ts +67 -0
  49. package/dist/app/module/fsm/IFsm.d.ts +67 -0
  50. package/dist/app/module/fsm/IFsmState.d.ts +38 -0
  51. package/dist/app/module/logger/Logger.d.ts +58 -0
  52. package/dist/app/module/native/INativeHelper.d.ts +6 -0
  53. package/dist/app/module/native/NativeHelper.d.ts +10 -0
  54. package/dist/app/module/net/NetInterface.d.ts +22 -0
  55. package/dist/app/module/net/NetManager.d.ts +24 -0
  56. package/dist/app/module/net/byte/ByteView.d.ts +391 -0
  57. package/dist/app/module/net/http/HttpNode.d.ts +104 -0
  58. package/dist/app/module/net/http/HttpRequest.d.ts +104 -0
  59. package/dist/app/module/net/server/IServer.d.ts +20 -0
  60. package/dist/app/module/net/server/LevelOnlineConfig.d.ts +9 -0
  61. package/dist/app/module/net/server/Server.d.ts +105 -0
  62. package/dist/app/module/net/server/SystemOnlineConfig.d.ts +34 -0
  63. package/dist/app/module/net/socket/BaseProtocolHelper.d.ts +31 -0
  64. package/dist/app/module/net/socket/Socket.d.ts +145 -0
  65. package/dist/app/module/net/socket/SocketNode.d.ts +63 -0
  66. package/dist/app/module/publisher/IADAble.d.ts +46 -0
  67. package/dist/app/module/publisher/IAble.d.ts +6 -0
  68. package/dist/app/module/publisher/IDevice.d.ts +42 -0
  69. package/dist/app/module/publisher/IGameUpdateAble.d.ts +21 -0
  70. package/dist/app/module/publisher/ILoginAble.d.ts +38 -0
  71. package/dist/app/module/publisher/IPayAble.d.ts +11 -0
  72. package/dist/app/module/publisher/IPublisher.d.ts +154 -0
  73. package/dist/app/module/publisher/IPublisherManager.d.ts +69 -0
  74. package/dist/app/module/publisher/IRecordAble.d.ts +16 -0
  75. package/dist/app/module/publisher/IShareAble.d.ts +39 -0
  76. package/dist/app/module/publisher/PublisherManager.d.ts +106 -0
  77. package/dist/app/module/publisher/PublisherManagerImpl.d.ts +24 -0
  78. package/dist/app/module/publisher/ks/KSAd.d.ts +7 -0
  79. package/dist/app/module/publisher/ks/KSDevice.d.ts +8 -0
  80. package/dist/app/module/publisher/ks/KSLogin.d.ts +7 -0
  81. package/dist/app/module/publisher/ks/KSPublisher.d.ts +34 -0
  82. package/dist/app/module/publisher/ks/KSRecorder.d.ts +13 -0
  83. package/dist/app/module/publisher/ks/KSShare.d.ts +32 -0
  84. package/dist/app/module/publisher/my/MYAd.d.ts +13 -0
  85. package/dist/app/module/publisher/my/MYDevice.d.ts +7 -0
  86. package/dist/app/module/publisher/my/MYLogin.d.ts +6 -0
  87. package/dist/app/module/publisher/my/MYPublisher.d.ts +6 -0
  88. package/dist/app/module/publisher/native/NativeAd.d.ts +22 -0
  89. package/dist/app/module/publisher/native/NativeAnalyticsSender.d.ts +9 -0
  90. package/dist/app/module/publisher/native/NativeDevice.d.ts +6 -0
  91. package/dist/app/module/publisher/native/NativeLogin.d.ts +27 -0
  92. package/dist/app/module/publisher/native/NativePay.d.ts +6 -0
  93. package/dist/app/module/publisher/native/NativePublisher.d.ts +21 -0
  94. package/dist/app/module/publisher/native/NativeRecord.d.ts +10 -0
  95. package/dist/app/module/publisher/native/NativeShare.d.ts +23 -0
  96. package/dist/app/module/publisher/tk/TKAd.d.ts +14 -0
  97. package/dist/app/module/publisher/tk/TKAnalyticsSender.d.ts +7 -0
  98. package/dist/app/module/publisher/tk/TKDevice.d.ts +9 -0
  99. package/dist/app/module/publisher/tk/TKLogin.d.ts +5 -0
  100. package/dist/app/module/publisher/tk/TKPublisher.d.ts +34 -0
  101. package/dist/app/module/publisher/tt/TTAd.d.ts +14 -0
  102. package/dist/app/module/publisher/tt/TTAnalyticsSender.d.ts +7 -0
  103. package/dist/app/module/publisher/tt/TTDevice.d.ts +9 -0
  104. package/dist/app/module/publisher/tt/TTLogin.d.ts +6 -0
  105. package/dist/app/module/publisher/tt/TTPay.d.ts +4 -0
  106. package/dist/app/module/publisher/tt/TTPublisher.d.ts +34 -0
  107. package/dist/app/module/publisher/tt/TTRecorder.d.ts +11 -0
  108. package/dist/app/module/publisher/tt/TTShare.d.ts +50 -0
  109. package/dist/app/module/publisher/tt/TTUpdateGameAble.d.ts +7 -0
  110. package/dist/app/module/publisher/wx/WXAd.d.ts +14 -0
  111. package/dist/app/module/publisher/wx/WXAnalyticsSender.d.ts +7 -0
  112. package/dist/app/module/publisher/wx/WXDevice.d.ts +8 -0
  113. package/dist/app/module/publisher/wx/WXLogin.d.ts +9 -0
  114. package/dist/app/module/publisher/wx/WXPay.d.ts +4 -0
  115. package/dist/app/module/publisher/wx/WXPublisher.d.ts +33 -0
  116. package/dist/app/module/publisher/wx/WXShare.d.ts +56 -0
  117. package/dist/app/module/publisher/wx/WXUpdateGameAble.d.ts +7 -0
  118. package/dist/app/module/storage/Storage.d.ts +123 -0
  119. package/dist/app/module/storage/StorageImpl.d.ts +13 -0
  120. package/dist/app/module/structure/Dictionary.d.ts +48 -0
  121. package/dist/app/module/structure/Link.d.ts +149 -0
  122. package/dist/app/module/structure/List.d.ts +93 -0
  123. package/dist/app/module/task/Task.d.ts +33 -0
  124. package/dist/app/module/task/TaskQueue.d.ts +17 -0
  125. package/dist/app/module/task/TaskSequence.d.ts +19 -0
  126. package/dist/app/module/timer/ITimer.d.ts +4 -0
  127. package/dist/app/module/timer/Timer.d.ts +133 -0
  128. package/dist/app/module/timer/TimerImpl.d.ts +10 -0
  129. package/dist/app/module/utils/md5.d.ts +3 -0
  130. package/dist/app/module/view/IView.d.ts +94 -0
  131. package/dist/app/module/view/IViewLoader.d.ts +48 -0
  132. package/dist/app/module/view/ViewManager.d.ts +242 -0
  133. package/dist/audio/AudioManager.d.ts +146 -0
  134. package/dist/business/AudioBusiness.d.ts +11 -0
  135. package/dist/cocos.d.ts +1 -0
  136. package/dist/index.d.ts +146 -0
  137. package/dist/index.js +14981 -0
  138. package/dist/native/CocosNativeHelper.d.ts +12 -0
  139. package/dist/resource/ResourceManager.d.ts +187 -0
  140. package/dist/utils/Async.d.ts +28 -0
  141. package/dist/utils/CocosStorageUtils.d.ts +10 -0
  142. package/dist/utils/GeometryUtils.d.ts +31 -0
  143. package/dist/view/CCPViewLoader.d.ts +95 -0
  144. package/dist/view/CCSceneLoader.d.ts +25 -0
  145. package/dist/view/CocosViewManager.d.ts +12 -0
  146. package/dist/view/Scene.d.ts +35 -0
  147. package/dist/view/View.d.ts +151 -0
  148. package/dist/view/ViewControl.d.ts +106 -0
  149. package/dist/view/tips/TipsView.d.ts +12 -0
  150. package/dist/vitest.config.d.ts +2 -0
  151. package/package.json +33 -0
@@ -0,0 +1,66 @@
1
+ export declare class StringUtils {
2
+ static random(length: number, chars?: string): string;
3
+ /**
4
+ * 判断是否是远程资源
5
+ * @param url
6
+ * @returns
7
+ */
8
+ static isRemote(url: string): boolean;
9
+ /**
10
+ * 是否为空
11
+ * @param str
12
+ */
13
+ static isEmpty(str: string): boolean;
14
+ /**
15
+ * 替换全部字符串
16
+ * @param string src 源串
17
+ * @param string from_ch 被替换的字符
18
+ * @param string to_ch 替换的字符
19
+ *
20
+ * @return string 结果字符串
21
+ */
22
+ static replaceAll(src: string, from_ch: string, to_ch: string): string;
23
+ /**
24
+ * 参数替换
25
+ * @param str
26
+ * @param rest
27
+ *
28
+ * @example
29
+ *
30
+ * var str:string = "here is some info '{0}' and {1}";
31
+ * trace(StringUtil.substitute(str, 15.4, true));
32
+ *
33
+ * // this will output the following string:
34
+ * // "here is some info '15.4' and true"
35
+ */
36
+ static format(str: string, ...rest: any[]): string;
37
+ /**
38
+ *
39
+ * 格式化数字
40
+ * @param amount 目标数字
41
+ * @param format 支持{1:"", 100:"百", 1000:"千", 10000:"万", 100000:"十万", 1000000:"百万", 10000000:"千万", 100000000:"亿", 1000000000000:"兆"}等
42
+ * @returns
43
+ */
44
+ static formatNumber(amount: number, format: any): string;
45
+ /**
46
+ * 带自动补全的秒数格式。
47
+ * @param second 秒数
48
+ * @param format 格式化文本
49
+ * @param pad 填充文本,默认为“0”
50
+ * @example
51
+ * formatSecond(86400, "ddd天hh小时mm分ss秒")=>"001天00小时00分00秒"
52
+ * formatSecond(86400, "dd天hh小时mm分ss秒")=>"01天00小时00分00秒"
53
+ * formatSecond(86400, "hh小时mm分ss秒")=>"24小时00分00秒"
54
+ * formatSecond(86400, "mm分ss秒")=>"1440分00秒"
55
+ * @returns
56
+ */
57
+ static formatSecond(second: number, format: string, pad?: string): string;
58
+ /**
59
+ * 带自动补全的时间戳格式化
60
+ * @param milliseconds
61
+ * @param format
62
+ * @param pad 填充文本,默认为“0”
63
+ * @returns
64
+ */
65
+ static formatTimestamp(milliseconds: number, format: string, pad?: string): string;
66
+ }
@@ -0,0 +1,41 @@
1
+ export type ABTestingProportion = -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100;
2
+ /**
3
+ * ABTesting配置
4
+ */
5
+ export type ABTestingConfig = {
6
+ [key: string]: ABTestingProportion;
7
+ };
8
+ declare class ABTesting {
9
+ private _flags;
10
+ private _nameToKey;
11
+ private _config;
12
+ init(abConfig: {
13
+ [name: string]: ABTestingConfig;
14
+ }, install?: boolean, launch?: boolean): void;
15
+ /**
16
+ * 以当前启动粒度,从一组区间配置中获取命中key。
17
+ * @param name AB测试的配置名称,需要先调用setFlagConfigs进行配置,否则固定返回Invalid
18
+ * @returns
19
+ */
20
+ getLaunchFlag(name: string): string;
21
+ /**
22
+ * 以客户端安装粒度,获取key对应的命中key
23
+ * @param name AB测试的配置名称,从一组区间配置中获取命中key。
24
+ * @returns
25
+ */
26
+ getInstallFlag(name: string): string;
27
+ /**
28
+ * 以临时粒度,获取key对应的命中key
29
+ * @param name AB测试的配置名称,从一组区间配置中获取命中key。
30
+ * @returns
31
+ */
32
+ getTempFlag(name: string): string;
33
+ private _getGroupFlag;
34
+ private _getFlag;
35
+ private _updateAnalytics;
36
+ }
37
+ /**
38
+ * AB测试
39
+ */
40
+ export declare const ab: ABTesting;
41
+ export {};
@@ -0,0 +1,59 @@
1
+ import { EmptyAnalyticsSender } from "./AnalyticsAble";
2
+ /**
3
+ * 阿里云日志时间配置
4
+ */
5
+ export type AliAnalyticsConfig = {
6
+ /**
7
+ * 所在区域的host, 默认为`cn-hangzhou.log.aliyuncs.com`
8
+ */
9
+ host?: string;
10
+ /**
11
+ * project名称
12
+ */
13
+ project: string;
14
+ /**
15
+ * logstore名称
16
+ */
17
+ logstore: string;
18
+ /**
19
+ * 时间戳的获取函数
20
+ * @returns
21
+ */
22
+ timestampCall: () => number;
23
+ /**
24
+ * 发送数据的CD,默认是2秒
25
+ */
26
+ cd?: number;
27
+ /**
28
+ * 发送数据的条数,默认是5条
29
+ */
30
+ count?: number;
31
+ };
32
+ /**
33
+ * 内部阿里云日志事件上报器
34
+ */
35
+ export declare class ALiAnalyticsSender extends EmptyAnalyticsSender {
36
+ private _tracker;
37
+ private _config;
38
+ protected _eventCache: any[];
39
+ protected _index: number;
40
+ private _storageKey;
41
+ /**
42
+ *
43
+ * @param project
44
+ * @param logstore
45
+ * @param host
46
+ * @param exclude
47
+ * @param cd
48
+ * @param count
49
+ */
50
+ constructor(config: AliAnalyticsConfig, exclude?: string[]);
51
+ private _setConfig;
52
+ private _loadStoredEvents;
53
+ private _storeEvents;
54
+ private _startLoop;
55
+ private _addListen;
56
+ private _restoreEvents;
57
+ protected _doReport(maxCount?: number, store?: boolean): boolean;
58
+ send(eventName: string, data: any): Promise<void>;
59
+ }
@@ -0,0 +1,191 @@
1
+ /**
2
+ * 上报数据通用格式定义,方便项目间的通用数据统计
3
+ */
4
+ export type AnalyticsData = {
5
+ /**
6
+ * 标记型ID,可用于关卡id、道具\装备id、广告id等的标记
7
+ */
8
+ id?: string | number;
9
+ /**
10
+ * number类型,定义偏向索引,可用于对象的顺序、位置等信息的描述
11
+ */
12
+ index?: number;
13
+ /**
14
+ * string类型,定义偏向于标记,可用于关卡名称、道具名称、行为分类名称等的标记
15
+ */
16
+ name?: string;
17
+ /**
18
+ * string类型,定义偏向于结果,可用于行为后的结果消息等。
19
+ */
20
+ msg?: string;
21
+ /**
22
+ * number类型,定义偏向于结果,可用于行为后的结果code等。
23
+ */
24
+ code?: number;
25
+ /**
26
+ * number类型,定义偏向计数数值,可以用于模型行为的计数、数量等。
27
+ */
28
+ count?: number;
29
+ [key: string]: string | boolean | number;
30
+ };
31
+ export interface IAnalyticsSender {
32
+ /**
33
+ * 是否需要发送
34
+ * @param eventName
35
+ */
36
+ sendAble(eventName: string): boolean;
37
+ /**
38
+ * 设置排除
39
+ * @param excludeList 排除事件名称或者名称列表。
40
+ */
41
+ exclude(...excludeList: string[]): void;
42
+ /**
43
+ * 上报
44
+ * @param eventName 事件名称
45
+ * @param data 事件数据
46
+ */
47
+ send(eventName: string, data: any): Promise<void>;
48
+ }
49
+ export declare class EmptyAnalyticsSender implements IAnalyticsSender {
50
+ protected _exclude: string[];
51
+ /**
52
+ * @param [exclude] 其他排除的上报日志, 默认不排除
53
+ */
54
+ constructor(exclude?: string[]);
55
+ /**
56
+ * 设置排除
57
+ * @param excludeList 排除事件名称或者名称列表。
58
+ */
59
+ exclude(...excludeList: string[]): void;
60
+ sendAble(eventName: string): boolean;
61
+ send(eventName: string, data: any): Promise<void>;
62
+ }
63
+ /**
64
+ * 统计分析能力
65
+ */
66
+ export declare class AnalyticsAble {
67
+ private _inited;
68
+ get inited(): boolean;
69
+ private _hasSetDefaultProperty;
70
+ protected _debugMode: boolean;
71
+ protected _senderList: IAnalyticsSender[];
72
+ protected _staticProperties: AnalyticsData;
73
+ protected _dynamicCalls: (() => AnalyticsData)[];
74
+ protected _userProperties: AnalyticsData;
75
+ protected _userOnceProperties: AnalyticsData;
76
+ protected _userAddProperties: AnalyticsData;
77
+ protected _timeEvents: Map<string, {
78
+ start: number;
79
+ once: boolean;
80
+ offset: number;
81
+ }>;
82
+ /**
83
+ * 初始化
84
+ */
85
+ init(senders: IAnalyticsSender[], debugMode?: boolean): AnalyticsAble;
86
+ private _initSenderList;
87
+ /**
88
+ * 设置排除
89
+ * @param excludeEvents 排除事件名称或者名称列表。
90
+ * @param senderClass [可选] 特定的SenderClass
91
+ */
92
+ setExclude<T extends IAnalyticsSender>(excludeEvents: string | string[], senderClass?: {
93
+ new (): T;
94
+ }): void;
95
+ protected _onAppShow(): void;
96
+ protected _onAppHide(): void;
97
+ /**
98
+ * 设置所有上报事件的基础属性
99
+ */
100
+ private _setDefaultProperty;
101
+ /**
102
+ * 设置事件公共属性
103
+ * @param key 公共属性key
104
+ * @param value
105
+ */
106
+ setProperty(key: string, value: string | number | boolean): void;
107
+ /**
108
+ * 删除事件的公共属性
109
+ * @param key
110
+ * @returns
111
+ */
112
+ unsetProperty(key: string): boolean;
113
+ /**
114
+ * 设置事件公共动态属性,上报事件时会触发回调函数,并把返回的AnalyticsData加入到事件属性中
115
+ * @param dynamicCall 动态属性的生成函数,事件上报时实时调用
116
+ */
117
+ setDynamicProperties(dynamicCall: () => AnalyticsData): void;
118
+ /**
119
+ * 对于一般的用户属性,您可以调用 userSet 来进行设置。
120
+ * 使用该接口上传的属性将会覆盖原有的属性值,如果之前不存在该用户属性,则会新建该用户属性,类型与传入属性的类型一致。
121
+ * 用户名为例:
122
+ * ```
123
+ * // username为TA
124
+ * userSet("username", "TA");
125
+ * //username为TE
126
+ * userSet("username", "TE");
127
+ * ```
128
+ * @param key 属性key
129
+ * @param value
130
+ */
131
+ userSet(key: string, value: string | number | boolean): void;
132
+ /**
133
+ * 如果您要上传的用户属性只要设置一次,则可以调用 userSetOnce 来进行设置。
134
+ * 当该属性之前已经有值的时候,将会忽略这条信息,比如设置首次付费时间:
135
+ * ```
136
+ * //first_payment_time为2018-01-01 01:23:45.678
137
+ * userOnce("first_payment_time", "2018-01-01 01:23:45.678");
138
+ * //first_payment_time仍然为2018-01-01 01:23:45.678
139
+ * userOnce("first_payment_time", "2018-12-31 01:23:45.678");
140
+ * ```
141
+ * @param key 属性key
142
+ * @param value
143
+ * @returns
144
+ */
145
+ userOnce(key: string, value: string | number | boolean): void;
146
+ /**
147
+ *设置用户累积属性,当您要上传数值型的属性时,您可以调用 userAdd 来对该属性进行累加操作,
148
+ * 如果该属性还未被设置,则会赋值 0 后再进行计算。
149
+ * 如果传入负值,等同于减法操作。
150
+ * ```
151
+ * userAdd("total_revenue", 30); //此时total_revenue为30
152
+ * userAdd("total_revenue", 648); //此时total_revenue为678
153
+ * ```
154
+ * @param key 累积属性key
155
+ * @param value 累积的偏移值
156
+ */
157
+ userAdd(key: string, value: number): void;
158
+ /**
159
+ * 移除用户属性。当您要清空用户的用户属性值时,您可以调用 userUnset 来对指定属性进行清空操作,如果该属性还未在集群中被创建,则 user_unset 不会创建该属性
160
+ * @param key
161
+ */
162
+ userUnset(key: string): void;
163
+ /**
164
+ * 上报错误
165
+ * @param error 错误信息
166
+ */
167
+ error(error: string): void;
168
+ /**
169
+ * 开始事件计时
170
+ * 如果您需要记录某个事件的持续时长,可以调用 timeEvent 来开始计时。
171
+ * 配置您想要计时的事件名称,当您上传该事件时,将会自动在您的事件属性中加入 _dt_ 这一属性来表示记录的时长,单位为秒。
172
+ * 需要注意的是,同一个事件名只能有一个在计时的任务。
173
+ * @param eventName
174
+ */
175
+ time(eventName: string, once?: boolean, offset?: number): void;
176
+ /**
177
+ * 取消事件计时
178
+ * @param eventName
179
+ * @returns
180
+ */
181
+ cancelTime(eventName: string): boolean;
182
+ /**
183
+ * 上报事件
184
+ * @param eventName 事件名称
185
+ * @param data 事件数据
186
+ */
187
+ report(eventName: string, data?: AnalyticsData): Promise<void>;
188
+ private _sendAble;
189
+ private _copyToData;
190
+ protected _sendReport(eventName: string, data: any): Promise<void>;
191
+ }
@@ -0,0 +1,20 @@
1
+ export declare enum DimensionType {
2
+ ACTIVITY = 0,
3
+ AD = 1,
4
+ PAYMENT = 2,
5
+ SOCIAL = 3,
6
+ PLAYER_ABILITY = 4,
7
+ LEVEL_STATS = 5
8
+ }
9
+ export type ConfigMatchedUnit = {
10
+ configName: string;
11
+ publishId?: string;
12
+ fingerprint: string;
13
+ variantId?: string;
14
+ variantFingerprint?: string;
15
+ };
16
+ export type ConfigResolveMeta = {
17
+ method: string;
18
+ resolveKey: string;
19
+ matchedUnits: ConfigMatchedUnit[];
20
+ };
@@ -0,0 +1,19 @@
1
+ export declare abstract class BaseDimension {
2
+ protected _name: string;
3
+ protected _data: Record<string, number>;
4
+ protected _initialized: boolean;
5
+ protected _dirty: boolean;
6
+ constructor(name: string);
7
+ get name(): string;
8
+ protected _ensureInit(): void;
9
+ protected _loadFromStorage(): void;
10
+ protected _saveToStorage(): Promise<void>;
11
+ protected _updateValue(key: string, value: number): void;
12
+ protected _incrementValue(key: string, delta?: number): void;
13
+ protected _getValue(key: string, defaultValue?: number): number;
14
+ getData(): Record<string, number>;
15
+ protected _compress(data: Record<string, number>): string;
16
+ protected _decompress(str: string): Record<string, number>;
17
+ abstract getMetrics(order?: string[]): number[];
18
+ clear(): void;
19
+ }
@@ -0,0 +1,67 @@
1
+ import { EmptyAnalyticsSender } from "./AnalyticsAble";
2
+ export interface KeytopsAnalyticsConfig {
3
+ /**
4
+ * 上报地址
5
+ */
6
+ url: string;
7
+ /**
8
+ * 时间戳的获取函数
9
+ * @returns
10
+ */
11
+ timestampCall?: () => number;
12
+ /**
13
+ * 发送数据的CD,默认是2秒
14
+ */
15
+ cd?: number;
16
+ /**
17
+ * 发送数据的条数,默认是5条
18
+ */
19
+ count?: number;
20
+ /**
21
+ * 本地缓存触发刷新的最大字节数
22
+ */
23
+ maxBufferedBytes?: number;
24
+ /**
25
+ * 本地缓存的独立key,避免不同行为混用缓存
26
+ */
27
+ cacheKey?: string;
28
+ /**
29
+ * 需要排除的事件名称
30
+ */
31
+ exclude?: string[];
32
+ }
33
+ type KeytopsAnalyticsEvent = {
34
+ appid: string;
35
+ openid: string;
36
+ deviceid: string;
37
+ sessionid: string;
38
+ level: number;
39
+ data: any;
40
+ event: string;
41
+ timestamp: number;
42
+ };
43
+ export declare class KeytopsAnalyticsSender extends EmptyAnalyticsSender {
44
+ private _config;
45
+ private _storageKey;
46
+ private _sending;
47
+ private _flushScheduled;
48
+ protected _eventCache: KeytopsAnalyticsEvent[];
49
+ protected _index: number;
50
+ constructor(config: KeytopsAnalyticsConfig, exclude?: string[]);
51
+ private _setConfig;
52
+ private _loadStoredEvents;
53
+ private _storeEvents;
54
+ private _estimateBytes;
55
+ private _currentBufferedBytes;
56
+ private _startLoop;
57
+ private _addListen;
58
+ private _restoreEvents;
59
+ private _scheduleFlush;
60
+ private _buildRequestBody;
61
+ private buildRequestId;
62
+ private _sendBatch;
63
+ private _sendBatchWithRetry;
64
+ protected _doReport(maxCount?: number, store?: boolean): Promise<boolean>;
65
+ send(eventName: string, data: any): Promise<void>;
66
+ }
67
+ export {};
@@ -0,0 +1,19 @@
1
+ import { AnalyticsAble } from "../AnalyticsAble";
2
+ import { ADType, AdFrom } from "./ADBehaviorReporter";
3
+ export declare class ADAnalyticsAble {
4
+ private _reporter;
5
+ private _dimension;
6
+ constructor(baseAble: AnalyticsAble);
7
+ onStartLoad(type: ADType, from: AdFrom, msg?: string): void;
8
+ onLoadComplete(type: ADType, from: AdFrom): void;
9
+ onLoadFail(type: ADType, from: AdFrom, msg?: string): void;
10
+ onStartShow(type: ADType, from: AdFrom): void;
11
+ onShowComplete(type: ADType, from: AdFrom, isEnded: boolean): void;
12
+ onShowFail(type: ADType, from: AdFrom, msg?: string): void;
13
+ onCloseByUser(type: ADType, from: AdFrom): void;
14
+ getMetrics(): number[];
15
+ /**
16
+ * 广告维度
17
+ */
18
+ private get dimension();
19
+ }
@@ -0,0 +1,90 @@
1
+ import { AnalyticsAble, AnalyticsData } from "../AnalyticsAble";
2
+ export declare enum ADType {
3
+ BANNER = 0,
4
+ INTERSTITIAL = 1,
5
+ REWARD_VIDEO = 2,
6
+ NATIVE = 3
7
+ }
8
+ export declare enum ADEvent {
9
+ LOAD = 0,
10
+ LOAD_COMPLETE = 1,
11
+ LOAD_FAIL = 2,
12
+ SHOW = 3,
13
+ SHOW_COMPLETE = 4,
14
+ SHOW_FAIL = 5,
15
+ CLOSE_BY_USER = 6
16
+ }
17
+ export type AdFrom = {
18
+ /**
19
+ * 广告调起的动作(按钮)
20
+ */
21
+ action?: string;
22
+ /**
23
+ * 广告发生的模块
24
+ */
25
+ group?: string;
26
+ [key: string]: string | boolean | number;
27
+ } & AnalyticsData;
28
+ export declare class ADBehaviorReporter {
29
+ private baseAble;
30
+ private _groupCount;
31
+ constructor(baseAble: AnalyticsAble);
32
+ /**
33
+ * 重置单个模块的广告计数
34
+ * @param group 模块名称,默认为game
35
+ */
36
+ resetGroupCount(group?: string): void;
37
+ /**
38
+ * 开始加载广告
39
+ * @param type 广告类型
40
+ * @param from 广告来源
41
+ * @param msg 广告失败原因
42
+ */
43
+ onStartLoad(type: ADType, from: AdFrom, msg?: string): void;
44
+ /**
45
+ * 广告加载完成
46
+ * @param type 广告类型
47
+ * @param from 广告来源
48
+ */
49
+ onLoadComplete(type: ADType, from: AdFrom): void;
50
+ /**
51
+ * 广告加载失败
52
+ * @param type 广告类型
53
+ * @param from 广告来源
54
+ * @param msg 广告失败原因
55
+ */
56
+ onLoadFail(type: ADType, from: AdFrom, msg?: string): void;
57
+ /**
58
+ * 显示广告
59
+ * @param type 广告类型
60
+ * @param from 广告来源
61
+ */
62
+ onShow(type: ADType, from: AdFrom): void;
63
+ /**
64
+ * 广告显示完成
65
+ * @param type 广告类型
66
+ * @param from 广告来源
67
+ */
68
+ onShowComplete(type: ADType, from: AdFrom): void;
69
+ /**
70
+ * 广告显示失败
71
+ * @param type 广告类型
72
+ * @param from 广告来源
73
+ * @param msg 广告失败原因
74
+ */
75
+ onShowFail(type: ADType, from: AdFrom, msg?: string): void;
76
+ /**
77
+ * 用户关闭广告
78
+ * @param type 广告类型
79
+ * @param from 广告来源
80
+ */
81
+ onCloseByUser(type: ADType, from: AdFrom): void;
82
+ /**
83
+ * 上报广告事件
84
+ * @param type 广告类型
85
+ * @param event 广告事件
86
+ * @param from 广告来源
87
+ * @param msg 广告失败原因
88
+ */
89
+ report(type: ADType, event: ADEvent, from: AdFrom, msg?: string): void;
90
+ }
@@ -0,0 +1,34 @@
1
+ import { BaseDimension } from "../BaseDimension";
2
+ export declare const AD_METRIC_ORDER_V1: readonly ["AD.show_count", "AD.show_days", "AD.complete_count", "AD.last_show_day", "AD.today_show_count", "AD.first_show_time", "AD.last_show_time", "AD.avg_show_interval", "AD.today_avg_show_interval", "AD.avg_show_per_day", "AD.avg_complete_per_day"];
3
+ /**
4
+ * 广告维度,记录广告展示次数、完成次数、展示天数、展示间隔等信息
5
+ */
6
+ export declare class AdDimension extends BaseDimension {
7
+ private _todayPrevShowTime;
8
+ constructor();
9
+ /**
10
+ * 检测并重置今日数据(仅在新的一天的新启动时)
11
+ */
12
+ private _checkAndResetDailyData;
13
+ recordShow(): void;
14
+ recordComplete(): void;
15
+ /**
16
+ * 获取日均展示次数
17
+ */
18
+ get avgShowPerDay(): number;
19
+ /**
20
+ * 获取日均完成次数
21
+ */
22
+ get avgCompletePerDay(): number;
23
+ /**
24
+ * 获取平均广告展示间隔(秒)
25
+ * 使用增量平均算法计算相邻两次展示的平均间隔
26
+ */
27
+ get avgShowInterval(): number;
28
+ /**
29
+ * 获取今日平均广告展示间隔(秒)
30
+ * 使用增量平均算法计算今日相邻两次展示的平均间隔
31
+ */
32
+ get todayAvgShowInterval(): number;
33
+ getMetrics(order?: string[]): number[];
34
+ }
@@ -0,0 +1,65 @@
1
+ import { ADAnalyticsAble } from "./ad/ADAnalyticsAble";
2
+ import { AnalyticsAble, IAnalyticsSender } from "./AnalyticsAble";
3
+ import { LevelAnalyticsAble } from "./level/LevelAnalyticsAble";
4
+ import { LaunchAnalyticsAble } from "./launch/LaunchAnalyticsAble";
5
+ import { SessionAnalyticsAble } from "./session/SessionAnalyticsAble";
6
+ import { SocialAnalyticsAble } from "./social/SocialAnalyticsAble";
7
+ export * from "./AnalyticsAble";
8
+ export * from "./ALiAnalyticsSender";
9
+ export * from "./KeytopsAnalyticsSender";
10
+ export * from "./launch/LaunchAnalyticsAble";
11
+ declare class AnalyticsManager {
12
+ private hasRelayUrl;
13
+ private hasAliDirectConfig;
14
+ private createBehaviorSenders;
15
+ private _base;
16
+ /**
17
+ * 基础统计能力
18
+ */
19
+ get base(): AnalyticsAble;
20
+ private _level;
21
+ /**
22
+ * 关卡统计能力,用于关卡分析
23
+ */
24
+ get level(): LevelAnalyticsAble;
25
+ private _ad;
26
+ /**
27
+ * 广告统计能力,用于广告分析
28
+ */
29
+ get ad(): ADAnalyticsAble;
30
+ private _session;
31
+ /**
32
+ * 会话统计能力,用于会话分析
33
+ */
34
+ get session(): SessionAnalyticsAble;
35
+ private _launch;
36
+ /**
37
+ * 启动统计能力,用于启动性能分析
38
+ */
39
+ get launch(): LaunchAnalyticsAble;
40
+ private _social;
41
+ /**
42
+ * 社交统计能力
43
+ */
44
+ get social(): SocialAnalyticsAble;
45
+ /**
46
+ * 启用统计(基础统计能力)
47
+ * @param debugMode 调试模式,是否打印日志信息,默认为false
48
+ * @param senders 上报器列表,允许多个 默认为ALiAnalyticsSender
49
+ * @returns
50
+ */
51
+ enable(debugMode?: boolean, senders?: IAnalyticsSender[]): void;
52
+ get version(): string;
53
+ /**
54
+ * 获取所有维度的数据
55
+ * @returns 所有维度的数据
56
+ */
57
+ private getMetrics;
58
+ private _assignmentSender;
59
+ private get assignmentSender();
60
+ private reportAssignments;
61
+ }
62
+ /**
63
+ * 埋点统计能力
64
+ */
65
+ export declare const analytics: AnalyticsManager;
@@ -0,0 +1,11 @@
1
+ import { AnalyticsAble, AnalyticsData } from "../AnalyticsAble";
2
+ export declare class LaunchAnalyticsAble {
3
+ private readonly _baseAble;
4
+ constructor(baseAble: AnalyticsAble);
5
+ /**
6
+ * 上报启动事件
7
+ * @param name 事件名称
8
+ * @param data 事件数据
9
+ */
10
+ report(name: string, data?: AnalyticsData): void;
11
+ }