@thinkingai/ae-cli 6.1.38 → 6.1.39

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 (188) hide show
  1. package/README.md +2 -0
  2. package/README.zh.md +2 -0
  3. package/dist/{ai-monitor-UL2O7J4X.js → ai-monitor-DST4NDOK.js} +5 -5
  4. package/dist/ai-monitor.js +7 -7
  5. package/dist/{auth-ERWVKQDG.js → auth-BD3NIY3T.js} +3 -3
  6. package/dist/{automation-OQ647CSW.js → automation-IMDCJUML.js} +85 -9
  7. package/dist/{capability-HPP6E3ZX.js → capability-3NJOQHZQ.js} +3 -3
  8. package/dist/{chunk-DKOGWIYQ.js → chunk-24DCOJBJ.js} +2 -2
  9. package/dist/{chunk-SHB7A2JE.js → chunk-2RORKIF6.js} +2 -2
  10. package/dist/{chunk-HBI7IQH3.js → chunk-6NJZSWUT.js} +3 -28
  11. package/dist/{chunk-QPUPWGZ3.js → chunk-DTODOQ6T.js} +1 -1
  12. package/dist/{chunk-PCQTBRPT.js → chunk-FRJUB66C.js} +1 -1
  13. package/dist/{chunk-ZLJZPPPV.js → chunk-IY5G42YY.js} +2 -2
  14. package/dist/{chunk-JRXSLFCA.js → chunk-KBJHBVO7.js} +1 -1
  15. package/dist/{chunk-CYZV5AXW.js → chunk-KE5WGBXS.js} +2 -1
  16. package/dist/chunk-N2MAYIRU.js +32 -0
  17. package/dist/{chunk-DULCIC67.js → chunk-SQEK6S4X.js} +2 -3
  18. package/dist/{chunk-VPLRZSMY.js → chunk-STHIGWWC.js} +10 -1
  19. package/dist/{chunk-BWEQIKA3.js → chunk-TVSGS5QB.js} +5 -5
  20. package/dist/{chunk-LXRALNNA.js → chunk-UK7HQ4IL.js} +1 -1
  21. package/dist/{chunk-NDX4VJO7.js → chunk-VXKKTUU2.js} +2 -2
  22. package/dist/{chunk-E5CJI7L3.js → chunk-WRYXVIJP.js} +1 -1
  23. package/dist/{compat-check-WRPEFB5N.js → compat-check-7VBBE7KO.js} +1 -1
  24. package/dist/{config-IS33K45R.js → config-LFRZBPH5.js} +3 -3
  25. package/dist/{context-Y2A6QIS3.js → context-WJQGJD6F.js} +1 -1
  26. package/dist/{data-integration-EIF5QHYF.js → data-integration-KMJWYAKK.js} +2 -1
  27. package/dist/index.js +34 -32
  28. package/dist/{memory-6QMZS4HF.js → memory-VPOPSU52.js} +3 -3
  29. package/dist/{metadata-TMAXVLOL.js → metadata-AR64J76Z.js} +5 -5
  30. package/dist/{model-LEYRQKOS.js → model-2F2354QP.js} +1 -1
  31. package/dist/{personal-semantic-preference-RMZEDRCJ.js → personal-semantic-preference-BCOSI4DO.js} +4 -4
  32. package/dist/{project-semantic-UD3OAZ6K.js → project-semantic-DJLXAXLD.js} +4 -4
  33. package/dist/{sync-GVF3OI2U.js → sync-4TUIQ2PZ.js} +3 -3
  34. package/dist/{te-agent-S7UH657Z.js → te-agent-EMDWA3M6.js} +4 -4
  35. package/dist/{te-analysis-SJIE5OZY.js → te-analysis-XHAMRMTQ.js} +5 -5
  36. package/dist/{te-community-VNHJDEID.js → te-community-JSUSZEYH.js} +4 -4
  37. package/dist/{te-dataops-AO4OQBQV.js → te-dataops-I264BUTI.js} +2 -2
  38. package/dist/{te-engage-EZJRFG3Q.js → te-engage-XNMQYO5N.js} +68 -16
  39. package/dist/{te-experiment-R2MNSAKV.js → te-experiment-5SCHMYVO.js} +4 -4
  40. package/dist/{te-kb-C44A4BHM.js → te-kb-QQ53TNRZ.js} +44 -13
  41. package/dist/{te-system-DB5Z3LLF.js → te-system-Z4VEB6PL.js} +1 -1
  42. package/dist/{te-team-J52STTEZ.js → te-team-V6BBI52R.js} +87 -6
  43. package/dist/{things-G2QFXDK7.js → things-THHGDSEC.js} +4 -4
  44. package/dist/{update-GEKOZMHU.js → update-53ZUXWV5.js} +2 -2
  45. package/dist/{web-runtime-5M7PRY7R.js → web-runtime-ZJHOIPKX.js} +4 -4
  46. package/dist/{workspace-RZESYB6T.js → workspace-W5ZPVWJS.js} +3 -3
  47. package/package.json +3 -3
  48. package/skills/ae-automation/SKILL.md +6 -2
  49. package/skills/ae-automation/references/cli.md +9 -3
  50. package/skills/ae-engage/SKILL.md +6 -1
  51. package/skills/ae-engage/references/common-metric.md +47 -1
  52. package/skills/ae-engage/references/flow-metric-update.md +1 -1
  53. package/skills/ae-engage/references/task-metric-update.md +1 -1
  54. package/skills/ae-experiment/SKILL.md +1 -1
  55. package/skills/ae-experiment/references/save_experiment.md +1 -1
  56. package/skills/ae-kb/SKILL.md +8 -6
  57. package/skills/ae-kb/references/query-workflow.md +5 -1
  58. package/skills/ae-team/SKILL.md +7 -3
  59. package/skills/ae-team/references/copy-to-personal.md +7 -0
  60. package/skills/ae-team/references/promote.md +7 -0
  61. package/skills/ae-team/references/update.md +3 -3
  62. package/skills/ae-tracking-matrix/SKILL.md +0 -170
  63. package/skills/ae-tracking-matrix/assets//345/237/213/347/202/271/346/250/241/347/211/210.xlsx +0 -0
  64. package/skills/ae-tracking-matrix/i18n.yaml +0 -12
  65. package/skills/ae-tracking-matrix/references/ae-capabilities.md +0 -93
  66. package/skills/ae-tracking-matrix/references/business-semantic-checks.md +0 -30
  67. package/skills/ae-tracking-matrix/references/categories/acquaintance_social_tracking_plan_template.md +0 -256
  68. package/skills/ae-tracking-matrix/references/categories/blockchain_game_tracking_plan_template.md +0 -213
  69. package/skills/ae-tracking-matrix/references/categories/card_game_tracking_plan_template.md +0 -407
  70. package/skills/ae-tracking-matrix/references/categories/casual_game_tracking_plan_template.md +0 -218
  71. package/skills/ae-tracking-matrix/references/categories/casual_music.md +0 -112
  72. package/skills/ae-tracking-matrix/references/categories/chess_cards_tracking_plan_template.md +0 -301
  73. package/skills/ae-tracking-matrix/references/categories/ecommerce_tracking_plan_template.md +0 -356
  74. package/skills/ae-tracking-matrix/references/categories/fishing.md +0 -775
  75. package/skills/ae-tracking-matrix/references/categories/game_basic_module_tracking_plan.md +0 -89
  76. package/skills/ae-tracking-matrix/references/categories/idle_card.md +0 -27
  77. package/skills/ae-tracking-matrix/references/categories/idle_game_tracking_plan_template.md +0 -415
  78. package/skills/ae-tracking-matrix/references/categories/interactive_video.md +0 -133
  79. package/skills/ae-tracking-matrix/references/categories/merge.md +0 -639
  80. package/skills/ae-tracking-matrix/references/categories/mmo_mobile_tracking_plan_template.md +0 -406
  81. package/skills/ae-tracking-matrix/references/categories/mmo_web.md +0 -230
  82. package/skills/ae-tracking-matrix/references/categories/music.md +0 -137
  83. package/skills/ae-tracking-matrix/references/categories/online_education_tracking_plan_template.md +0 -414
  84. package/skills/ae-tracking-matrix/references/categories/qipai_mj.md +0 -199
  85. package/skills/ae-tracking-matrix/references/categories/reading_tracking_plan_template.md +0 -158
  86. package/skills/ae-tracking-matrix/references/categories/roguelike_tracking_plan_template.md +0 -546
  87. package/skills/ae-tracking-matrix/references/categories/rpg.md +0 -195
  88. package/skills/ae-tracking-matrix/references/categories/short_drama_tracking_plan_template.md +0 -115
  89. package/skills/ae-tracking-matrix/references/categories/simulation_business_tracking_plan_template.md +0 -151
  90. package/skills/ae-tracking-matrix/references/categories/slg_tracking_plan_template.md +0 -260
  91. package/skills/ae-tracking-matrix/references/categories/slots_tracking_plan_template.md +0 -232
  92. package/skills/ae-tracking-matrix/references/categories/stranger_social_tracking_plan_template.md +0 -359
  93. package/skills/ae-tracking-matrix/references/categories/tower_defense.md +0 -365
  94. package/skills/ae-tracking-matrix/references/categories/video_editor_tracking_plan_template.md +0 -211
  95. package/skills/ae-tracking-matrix/references/categories/wechat_minigame.md +0 -132
  96. package/skills/ae-tracking-matrix/references/category-registry.md +0 -77
  97. package/skills/ae-tracking-matrix/references/data-verification/diagnosis_kb.md +0 -230
  98. package/skills/ae-tracking-matrix/references/data-verification/sql_checks.md +0 -406
  99. package/skills/ae-tracking-matrix/references/data-verification/tracking_plan_comparison.md +0 -128
  100. package/skills/ae-tracking-matrix/references/eval-cases.md +0 -74
  101. package/skills/ae-tracking-matrix/references/naming-dict.md +0 -238
  102. package/skills/ae-tracking-matrix/references/optimization-checklist.md +0 -85
  103. package/skills/ae-tracking-matrix/references/plan-generation/export-schema.md +0 -142
  104. package/skills/ae-tracking-matrix/references/plan-generation/module-baseline.md +0 -47
  105. package/skills/ae-tracking-matrix/references/plan-generation/reference.md +0 -794
  106. package/skills/ae-tracking-matrix/references/plan-generation/template-catalog.md +0 -94
  107. package/skills/ae-tracking-matrix/references/scene-routing.md +0 -80
  108. package/skills/ae-tracking-matrix/references/sdk/client-sdk/android.md +0 -3787
  109. package/skills/ae-tracking-matrix/references/sdk/client-sdk/c.md +0 -827
  110. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-lua.md +0 -655
  111. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-x.md +0 -953
  112. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocoscreator.md +0 -1128
  113. package/skills/ae-tracking-matrix/references/sdk/client-sdk/corona.md +0 -714
  114. package/skills/ae-tracking-matrix/references/sdk/client-sdk/egret.md +0 -1268
  115. package/skills/ae-tracking-matrix/references/sdk/client-sdk/flutter.md +0 -776
  116. package/skills/ae-tracking-matrix/references/sdk/client-sdk/h5-and-app-sdk-integration.md +0 -182
  117. package/skills/ae-tracking-matrix/references/sdk/client-sdk/ios.md +0 -2755
  118. package/skills/ae-tracking-matrix/references/sdk/client-sdk/javascript.md +0 -1182
  119. package/skills/ae-tracking-matrix/references/sdk/client-sdk/layaair.md +0 -1300
  120. package/skills/ae-tracking-matrix/references/sdk/client-sdk/macos.md +0 -1369
  121. package/skills/ae-tracking-matrix/references/sdk/client-sdk/mini-program-mini-game.md +0 -1692
  122. package/skills/ae-tracking-matrix/references/sdk/client-sdk/openharmony.md +0 -902
  123. package/skills/ae-tracking-matrix/references/sdk/client-sdk/react-native.md +0 -763
  124. package/skills/ae-tracking-matrix/references/sdk/client-sdk/uni-app.md +0 -1107
  125. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unity.md +0 -1532
  126. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unreal.md +0 -845
  127. package/skills/ae-tracking-matrix/references/sdk/faq/android_sdk_faq.md +0 -228
  128. package/skills/ae-tracking-matrix/references/sdk/faq/ios_sdk_faq.md +0 -149
  129. package/skills/ae-tracking-matrix/references/sdk/faq/java_sdk_faq.md +0 -407
  130. package/skills/ae-tracking-matrix/references/sdk/faq/javascript_sdk_faq.md +0 -163
  131. package/skills/ae-tracking-matrix/references/sdk/faq/minigame_sdk_faq.md +0 -149
  132. package/skills/ae-tracking-matrix/references/sdk/faq/miniprogram_sdk_faq.md +0 -153
  133. package/skills/ae-tracking-matrix/references/sdk/faq/python_sdk_faq.md +0 -232
  134. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_log_guide.md +0 -314
  135. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_usage_notes.md +0 -117
  136. package/skills/ae-tracking-matrix/references/sdk/faq/unity_sdk_faq.md +0 -148
  137. package/skills/ae-tracking-matrix/references/sdk/integration-tools/filebeat-logstash-guide.md +0 -645
  138. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_guide.md +0 -307
  139. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_parser_plugin.md +0 -347
  140. package/skills/ae-tracking-matrix/references/sdk/integration-tools/restful_api_notes.md +0 -72
  141. package/skills/ae-tracking-matrix/references/sdk/integration-tools/ta-datax-writer-guide.md +0 -264
  142. package/skills/ae-tracking-matrix/references/sdk/server-sdk/c.md +0 -566
  143. package/skills/ae-tracking-matrix/references/sdk/server-sdk/erlang.md +0 -409
  144. package/skills/ae-tracking-matrix/references/sdk/server-sdk/golang.md +0 -446
  145. package/skills/ae-tracking-matrix/references/sdk/server-sdk/java.md +0 -557
  146. package/skills/ae-tracking-matrix/references/sdk/server-sdk/lua.md +0 -457
  147. package/skills/ae-tracking-matrix/references/sdk/server-sdk/nodejs.md +0 -490
  148. package/skills/ae-tracking-matrix/references/sdk/server-sdk/php.md +0 -523
  149. package/skills/ae-tracking-matrix/references/sdk/server-sdk/python.md +0 -484
  150. package/skills/ae-tracking-matrix/references/sdk/server-sdk/ruby.md +0 -442
  151. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/data-rules.md +0 -391
  152. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/first-event-validation.md +0 -91
  153. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/preset-properties-system-fields.md +0 -635
  154. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/updatable-events.md +0 -113
  155. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/user-identification-rules.md +0 -466
  156. package/skills/ae-tracking-matrix/references/standard-base/README.md +0 -22
  157. package/skills/ae-tracking-matrix/references/standard-base/basic_event_data.md +0 -174
  158. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties.md +0 -20
  159. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties_setup.md +0 -7
  160. package/skills/ae-tracking-matrix/references/standard-base/data_type_design_principles.md +0 -14
  161. package/skills/ae-tracking-matrix/references/standard-base/gameplay_event_data.md +0 -370
  162. package/skills/ae-tracking-matrix/references/standard-base/id_system_faq.md +0 -47
  163. package/skills/ae-tracking-matrix/references/standard-base/integration_must_know.md +0 -37
  164. package/skills/ae-tracking-matrix/references/standard-base/multi_platform_integration_notes.md +0 -27
  165. package/skills/ae-tracking-matrix/references/standard-base/multi_user_id_system_recommendations.md +0 -23
  166. package/skills/ae-tracking-matrix/references/standard-base/tracking_notes.md +0 -14
  167. package/skills/ae-tracking-matrix/references/standard-base/user_data.md +0 -46
  168. package/skills/ae-tracking-matrix/references/standard-base/user_id_system.md +0 -13
  169. package/skills/ae-tracking-matrix/references/system-fields.md +0 -297
  170. package/skills/ae-tracking-matrix/references/te-field-translations.md +0 -1791
  171. package/skills/ae-tracking-matrix/references/workflows/data-verification.md +0 -232
  172. package/skills/ae-tracking-matrix/references/workflows/feasibility-analysis.md +0 -829
  173. package/skills/ae-tracking-matrix/references/workflows/integration-qna.md +0 -355
  174. package/skills/ae-tracking-matrix/references/workflows/plan-generation.md +0 -283
  175. package/skills/ae-tracking-matrix/references/workflows/plan-lint.md +0 -168
  176. package/skills/ae-tracking-matrix/references/workflows/plan-review-optimize.md +0 -205
  177. package/skills/ae-tracking-matrix/references/workflows/prd-to-suggestions.md +0 -75
  178. package/skills/ae-tracking-matrix/references/workflows/troubleshooting.md +0 -36
  179. package/skills/ae-tracking-matrix/references/workflows/validated-upload.md +0 -107
  180. package/skills/ae-tracking-matrix/scripts/build_template_catalog.py +0 -114
  181. package/skills/ae-tracking-matrix/scripts/export_tracking_plan.py +0 -53
  182. package/skills/ae-tracking-matrix/scripts/finalize_plan.py +0 -166
  183. package/skills/ae-tracking-matrix/scripts/lint_tracking_plan.py +0 -674
  184. package/skills/ae-tracking-matrix/scripts/plan_contract.py +0 -200
  185. package/skills/ae-tracking-matrix/scripts/plan_types.py +0 -60
  186. package/skills/ae-tracking-matrix/scripts/prepare_delivery.py +0 -169
  187. package/skills/ae-tracking-matrix/scripts/sync_plan.py +0 -296
  188. package/skills/ae-tracking-matrix/scripts/upload_plan.py +0 -340
@@ -1,1182 +0,0 @@
1
- ---
2
- code: javascript_sdk_installation
3
- name: "JavaScript"
4
- wikiToken: Ian8wU157i7or8kW1ORccuT8nWe
5
- parentWikiToken: FTcTwinIOi3OiRkK4MPc2Ex7neg
6
- updateTime: 1767751459000
7
- sourceUrl: https://docs-v2.thinkingdata.cn/?version=6.0&lan=zh-CN&code=javascript_sdk_installation
8
- ---
9
-
10
- # JavaScript
11
-
12
- ::: tip Tip
13
-
14
- Before integration, please read the pre-installation preparation.
15
-
16
- JavaScript SDK runs in browser environment and is not compatible with IE 8 and below.
17
-
18
- JavaScript SDK size is approximately 58 KB
19
-
20
- :::
21
-
22
- **Latest Version: ** v2.3.1 Download
23
-
24
- **Update Time: ** 2026-01-07
25
-
26
- **Resource Download:** Source code
27
-
28
- ::: warning Note
29
-
30
- This document applies to v2.0.0 and later versions. For historical versions, please refer to JS Integration Guide (V1), SDK Download (V1)
31
-
32
- :::
33
-
34
- ### 1. Integrate SDK
35
-
36
- SDK Support Scope:
37
-
38
- Client Frameworks: Vue2, Vue3, React, Angular
39
-
40
- Desktop Frameworks: Electron
41
-
42
- #### 1.1 Automatic Integration
43
-
44
- ```
45
- npm install thinkingdata-browser --save
46
-
47
- "dependencies": {
48
- "thinkingdata-browser": "2.3.1",
49
- },
50
- ```
51
-
52
- Next, initialize the SDK. For specific configuration parameters, please refer to Step 2.
53
-
54
- ```
55
- import ta from "thinkingdata-browser";
56
- var config = {
57
- appId: "APP_ID",
58
- serverUrl: "https://YOUR_SERVER_URL",
59
- autoTrack: {
60
- pageShow: true, // Enable page show event, event name ta_page_show
61
- pageHide: true, // Enable page hide event, event name ta_page_hide
62
- }
63
- };
64
- ta.init(config);
65
- ```
66
-
67
- #### 1.2 Manual Integration
68
-
69
- Step 1: Download JavaScript SDK
70
-
71
- The compressed package provides two types of scripts. You can choose the required script according to your needs. The asynchronous loading described below requires the `thinkingdata.min.js` file; synchronous loading requires the `thinkingdata.umd.min.js`.
72
-
73
- Step 2: Load JavaScript SDK
74
-
75
- You can choose asynchronous loading or synchronous loading to use the SDK. Both methods are similar in actual use, you can choose either.
76
-
77
- When initializing the SDK, you need to pass in some configuration parameters:
78
-
79
- - `appId`: Your project's APP_ID, must be configured. It will be given when you apply for the project, please fill it in here
80
- - `serverUrl`: URL for uploading data, must be configured
81
- <!-- unsupported block: 34 -->
82
-
83
- If you are using cloud service, please enter the following URL: https://global-receiver-ta.thinkingdata.cn
84
-
85
- If you are using a privately deployed version, please enter the following URL: https://DATA_COLLECTION_ADDRESS
86
-
87
- :::: el-tabs
88
-
89
- ::: el-tab-pane label=Asynchronous Loading
90
-
91
- For asynchronous loading, please use `thinkingdata.min.js`. Place the following code into the html `<script>` and configure the corresponding parameters:
92
-
93
- ```
94
- <!--Thinking Analytics SDK BEGIN-->
95
- <script>
96
- !function (e) { if (!window.ThinkingDataAnalyticalTool) { var n = e.sdkUrl, t = e.name, r = window, a = document, i = "script", l = null, s = null; r.ThinkingDataAnalyticalTool = t; var o = ["track", "quick", "login", "identify", "logout", "trackLink", "userSet", "userSetOnce", "userAdd", "userDel", "setPageProperty", "setSuperProperties", "setDynamicSuperProperties", "clearSuperProperties", "timeEvent", "unsetSuperProperties", "initInstance", "trackFirstEvent", "trackUpdate", "trackOverwrite"]; r[t] = function (e) { return function () { if (this.name) (r[t]._q = r[t]._q || []).push([e, arguments, this.name]); else if ("initInstance" === e) { var n = arguments[0]; r[t][n] = { name: n }; for (var a = 0; a < o.length; a++)r[t][n][o[a]] = r[t].call(r[t][n], o[a]); (r[t]._q1 = r[t]._q1 || []).push([e, arguments]) } else (r[t]._q = r[t]._q || []).push([e, arguments]) } }; for (var u = 0; u < o.length; u++)r[t][o[u]] = r[t].call(null, o[u]); r[t].param = e, r[t].__SV = 1.1, l = a.createElement(i), s = a.getElementsByTagName(i)[0], l.async = 1, l.src = n, s.parentNode.insertBefore(l, s) } }(
97
- {
98
- appId:'APP_ID', // APP_ID assigned by the system
99
- name: 'ta', // Global variable name, can be set arbitrarily, subsequent calls use this name
100
- sdkUrl:'./thinkingdata.min.js', // Analytics script URL
101
- serverUrl:'https://YOUR_SERVER_URL', // Data upload URL
102
- autoTrack: {
103
- pageShow: true, // Enable page show event, event name ta_page_show
104
- pageHide: true, // Enable page hide event, event name ta_page_hide
105
- },
106
- loaded: function(ta) {
107
- // var currentId = ta.getDistinctId();
108
- // ta.identify(currentId);
109
- // ta.quick('autoTrack');
110
- }
111
- });
112
- </script>
113
- <!--Thinking Analytics SDK END-->
114
- ```
115
-
116
- Asynchronous loading specific parameter description:
117
-
118
- - `name` is the global variable name
119
- - `sdkUrl` is the SDK URL, must be configured
120
- - `loaded`, initialization callback function. Since code snippet loading is asynchronous, methods with return values may not be called successfully, or track triggered before SDK loading completes may have exceptions. We provide the loaded property in parameters. The callback function in loaded will be called after initialization completes and before data reporting starts. For example, if you set user ID here, the data generated before SDK loading will have the user ID set.
121
- :::
122
-
123
- ::: el-tab-pane label=Synchronous Loading
124
-
125
- For synchronous loading, please use `thinkingdata.umd.min.js`. Place the following code into the initialization code and configure the corresponding parameters:
126
-
127
- ```
128
- <!--Thinking Analytics SDK BEGIN-->
129
- <script src="./thinkingdata.umd.min.js"></script>
130
- <script>
131
- // Create SDK configuration object
132
- var config = {
133
- appId: 'APP_ID',
134
- serverUrl: 'https://YOUR_SERVER_URL',
135
- autoTrack: {
136
- pageShow: true, // Enable page show event, event name ta_page_show
137
- pageHide: true, // Enable page hide event, event name ta_page_hide
138
- }
139
- };
140
- // Assign SDK instance to global variable ta, or other variable you specify
141
- window.ta = thinkingdata;
142
- // Initialize SDK with configuration object
143
- ta.init(config);
144
- </script>
145
- <!--Thinking Analytics SDK END-->
146
- ```
147
-
148
- :::
149
-
150
- ::::
151
-
152
- ### 2. Common Features
153
-
154
- Before using common features, we recommend you first understand the user identification rules. SDK uses random number as visitor ID by default and persists visitor ID locally. Before user logs in, visitor ID is used as identification ID. Note: Visitor ID will change when local cache is cleared.
155
-
156
- #### 2.1 Set Account ID
157
-
158
- When user performs login behavior, you can call `login` to set user's account ID. TE platform prefers account ID as identity identifier. The set account ID will be saved. Multiple calls to `login` will override previous account ID:
159
-
160
- ```
161
- // User's unique login identifier, this data corresponds to #account_id in reported data, at this time #account_id value is TA
162
- ta.login("TA");
163
- ```
164
-
165
- <!-- unsupported block: 34 -->
166
-
167
- This method will not upload login event
168
-
169
- #### 2.2 Set Common Event Properties
170
-
171
- Common event properties refer to properties that every event will have. You can call `setSuperProperties` to set common event properties. We recommend you set common event properties before sending events. For some important properties, such as user's membership level, source channel, etc., these properties need to be set in every event. You can set these properties as common event properties.
172
-
173
- ```
174
- var superProperties = {};
175
- superProperties["channel"] = "ta";// String
176
- superProperties["age"] = 1;// Number
177
- superProperties["isSuccess"] = true;// Boolean
178
- superProperties["birthday"] = new Date();// Date
179
- superProperties["object"] = {key:"value"};// Object
180
- superProperties["object_arr"] = [{key:"value"}];// Object array
181
- superProperties["arr"] = ["value"];// Array
182
- ta.setSuperProperties(superProperties);// Set common event properties
183
- ```
184
-
185
- Common event properties will be saved to cache, no need to call every time you open the webpage. If you call `setSuperProperties` to upload a previously set common event property, it will override the previous property.
186
-
187
- - Key is the property name, string type, must start with letter, contains numbers, letters and underscore "\_", maximum length is 50 characters, case insensitive, TE will convert to lowercase letters
188
- - Value is the property value, supports string, number, boolean, date, object, object array, array
189
- <!-- unsupported block: 34 -->
190
-
191
- Event properties and user properties requirements are the same as common event properties
192
-
193
- #### 2.3 Send Event
194
-
195
- You can directly call `track` to upload custom event. We recommend you set event properties and send event conditions based on previously documented tracking plan. Here is an example of user purchasing a product:
196
-
197
- ```
198
- ta.track("product_buy",{product_name:"product name"});
199
- ```
200
-
201
- Event name is string type, must start with letter, can contain numbers, letters and underscore "\_", maximum length is 50 characters.
202
-
203
- <!-- unsupported block: 34 -->
204
-
205
- Array type is supported after v1.3.0, requires TE platform 2.5 or above.
206
-
207
- Object type requires TE platform 3.5 or above.
208
-
209
- #### 2.4 Set User Properties
210
-
211
- For general user properties, you can call `userSet` to set. Properties uploaded using this interface will override original property values. If the user property did not exist before, it will create a new user property with the same type as the uploaded property. Here is an example of setting username:
212
-
213
- ```
214
- // username is TA
215
- ta.userSet({ username: "TA" });
216
- // username is TE
217
- ta.userSet({ username: "TE" });
218
- ```
219
-
220
- ### 3. Best Practices
221
-
222
- The following example code includes all operations above. We recommend using it as follows:
223
-
224
- ```
225
- import ta from "thinkingdata-browser";
226
- var config = {
227
- appId: "APP_ID",
228
- serverUrl: "https://YOUR_SERVER_URL/sync_js",
229
- autoTrack: {
230
- pageShow: true, // Enable page show event, event name ta_page_show
231
- pageHide: true, // Enable page hide event, event name ta_page_hide
232
- }
233
- };
234
- // Initialize SDK
235
- ta.init(config);
236
-
237
- // If user is logged in, you can set user's account ID as unique identifier
238
- ta.login("TA");
239
-
240
- // Set common event properties
241
- var superProperties = {};
242
- superProperties["channel"] = "ta";// String
243
- superProperties["age"] = 1;// Number
244
- superProperties["isSuccess"] = true;// Boolean
245
- superProperties["birthday"] = new Date();// Date
246
- superProperties["object"] = {key:"value"};// Object
247
- superProperties["object_arr"] = [{key:"value"}];// Object array
248
- superProperties["arr"] = ["value"];// Array
249
- ta.setSuperProperties(superProperties);// Set common event properties
250
-
251
- // Send event
252
- ta.track("product_buy", // Event name
253
- // Event properties
254
- {product_name:"product name"});
255
-
256
- // Set user properties
257
- ta.userSet({username: "TA" });
258
- ```
259
-
260
- ---
261
-
262
- # Advanced Guide
263
-
264
- ### 1. Set User ID
265
-
266
- SDK instance uses random number as default visitor ID for each user by default. This ID will be used as identification ID when user is not logged in. Note that visitor ID will change when user clears cache or changes device.
267
-
268
- #### 1.1 Set Visitor ID
269
-
270
- ::: tip Tip
271
-
272
- Generally, you don't need to customize visitor ID. Please ensure you understand user identification rules before setting visitor ID.
273
-
274
- :::
275
-
276
- ```
277
- ta.setDistinctId("Thinker");
278
- ```
279
-
280
- If you need to get visitor ID, you can call `getDistinctId`:
281
-
282
- ```
283
- // Return visitor ID
284
- var distinctId = ta.getDistinctId();
285
- ```
286
-
287
- #### 1.2 Set Account ID
288
-
289
- When user logs in, you can call `login` to set user's account ID. TE platform will use account ID as identification ID. The set account ID will be kept until `logout` is called. Multiple calls to `login` will override previous account ID.
290
-
291
- ```
292
- // User's unique login identifier, this data corresponds to #account_id in reported data, at this time #account_id value is TA
293
- ta.login("TA");
294
- ```
295
-
296
- <!-- unsupported block: 34 -->
297
-
298
- **This method will not upload login event**
299
-
300
- #### 1.3 Clear Account ID
301
-
302
- After user performs logout behavior, you can call `logout` to clear account ID. Before next call to `login`, visitor ID will be used as identification ID.
303
-
304
- ```
305
- ta.logout();
306
- ```
307
-
308
- We recommend you call `logout` during logout operation, such as when user performs account deregistration, rather than when closing the application.
309
-
310
- <!-- unsupported block: 34 -->
311
-
312
- **This method will not upload logout event**
313
-
314
- ### 2. Send Event
315
-
316
- After SDK initialization is complete, you can perform data tracking to collect user behavior information. Generally, normal events can meet business scenario requirements. You can also use first-time, updatable events according to your actual business scenarios.
317
-
318
- #### 2.1 Normal Event
319
-
320
- You can call `track` to upload event. We recommend you set event properties and send event conditions based on previously documented tracking plan. Here is an example of user purchasing a product:
321
-
322
- ```
323
- ta.track(
324
- "product_buy", // Event name
325
- { product_name: "product"} // Event properties
326
- );
327
- ```
328
-
329
- #### 2.2 First-time Event
330
-
331
- First-time event refers to event that will only be recorded once for a certain device or other dimension ID. For example, in some scenarios, you may want to record activation event on a certain device, then you can use first-time event to report data.
332
-
333
- ```
334
- ta.trackFirst({
335
- eventName: "device_activation",
336
- properties: { key:"value" }
337
- });
338
- ```
339
-
340
- If you want to judge whether it's first time based on other dimensions besides device, you can customize first_check_id for first-time event:
341
-
342
- ```
343
- // Set user ID as FIRST_CHECK_ID for first-time event, to implement user first activation event collection
344
- ta.trackFirst({
345
- eventName: "account_activation",
346
- firstCheckId: "TA",
347
- properties: { key: "value"}
348
- });
349
- ```
350
-
351
- <!-- unsupported block: 34 -->
352
-
353
- Note: Since validation of whether it's first time is done on server side, first-time events are delayed by 1 hour before being stored in database by default.
354
-
355
- #### 2.3 Updatable Event
356
-
357
- You can use updatable event to implement requirements for modifying event data in specific scenarios. Updatable event needs to specify the ID that identifies the event and pass it when creating updatable event object. TE backend will determine the data to be updated based on event name and event ID.
358
-
359
- ```
360
- // Example: Report updatable event, assuming event name is UPDATABLE_EVENT
361
- // After reporting, event property status is 3, price is 100
362
- ta.trackUpdate({
363
- eventName: "UPDATABLE_EVENT",
364
- properties: { status: 3, price: 100 },
365
- eventId: "test_event_id"
366
- });
367
-
368
- // After reporting, event property status is updated to 5, price unchanged
369
- ta.trackUpdate({
370
- eventName: "UPDATABLE_EVENT",
371
- properties: { status: 5 },
372
- eventId: "test_event_id"
373
- });
374
- ```
375
-
376
- #### 2.4 Overwritable Event
377
-
378
- Overwritable event is similar to updatable event, the difference is that overwritable event will completely overwrite historical data with latest data. From the effect, it's equivalent to deleting previous data and storing latest data. TE backend will determine the data to be updated based on event name and event ID.
379
-
380
- ```
381
- // Example: Report overwritable event, assuming event name is OVERWRITE_EVENT
382
- // After reporting, event property status is 3, price is 100
383
- ta.trackOverwrite({
384
- eventName: "OVERWRITE_EVENT",
385
- properties: { status: 3, price: 100 },
386
- eventId: "test_event_id"
387
- });
388
-
389
- // After reporting, event property status is updated to 5, price property is deleted
390
- ta.trackOverwrite({
391
- eventName: "OVERWRITE_EVENT",
392
- properties: { status: 5 },
393
- eventId: "test_event_id"
394
- });
395
- ```
396
-
397
- #### 2.5 Set Common Event Properties
398
-
399
- During data collection, some fields will be shared by multiple events. For example, all events occurring on the same page should have this page's page properties. User account information should be included in all data. When calling `track` to report events, these properties need to be set every time. For such properties, you can use common property setting interface to set them uniformly.
400
-
401
- Before introducing how to set common properties, you need to understand the characteristics of three types of common properties and choose the appropriate type according to actual needs:
402
-
403
- - Static common properties: Effective for all pages. Lowest priority. When cache is enabled, it will be cached in localStorage or cookie. Can only set fixed values.
404
- - Page common properties: Effective for current page, highest priority. If SDK is re-initialized, page common properties will be cleared. Can only set fixed values.
405
- - Dynamic common properties: Priority lower than page common properties. After SDK re-initialization, dynamic common properties need to be set again. Can set dynamic variables.
406
-
407
- ##### 2.5.1 Set Static Common Properties
408
-
409
- For some important properties, such as user's channel, nickname, ID, etc., these properties need to be set in every event. You can call `setSuperProperties` to set static common event properties. Static common event properties will be effective globally. When cache is enabled (default on), static common properties will be cached in `localStorage` or `cookie`.
410
-
411
- The parameter for static common properties is a JSON object, and its format requirements are the same as event properties.
412
-
413
- ```
414
- // Set common event properties, all data events will have these properties
415
- ta.setSuperProperties({ channel: "channel name", user_name: "username" });
416
- ```
417
-
418
- Besides property setting, we also provide other APIs to manipulate static common event properties to meet daily business needs.
419
-
420
- ```
421
- // Get static common event properties
422
- var superProperties = ta.getSuperProperties();
423
- // Clear a static common event property, for example clear previously set 'channel' property, subsequent data will not have this property
424
- ta.unsetSuperProperty("channel");
425
- // Clear all static common event properties
426
- ta.clearSuperProperties();
427
- ```
428
-
429
- ##### 2.5.2 Set Page Common Properties
430
-
431
- For some static properties in a page, such as page name or address, you may want to add this property to all events triggered on this page. For such static properties that need to apply to all events in the page, you can use `setPageProperty` to set. Please note that common properties set using `setPageProperty` are only effective for the current page.
432
-
433
- ```
434
- // Set page ID as page common property, all events triggered in this page will have the following property
435
- ta.setPageProperty({ page_id: "page10001" });
436
- ```
437
-
438
- If you want to get current page's page common properties, you can call `getPageProperty`:
439
-
440
- ```
441
- // Get current page's page common properties
442
- var pageProperty = ta.getPageProperty();
443
- ```
444
-
445
- ##### 2.5.3 Set Dynamic Common Properties
446
-
447
- Through `setDynamicSuperProperties` to set callback function for dynamic common properties. SDK will trigger callback function when event is reported and add returned JSON object to event properties. `setDynamicSuperProperties` parameter is a function that needs to return a JSON object.
448
-
449
- ```
450
- // Set dynamic common properties, trigger callback function when event is reported, and add returned JSON object to event properties
451
- ta.setDynamicSuperProperties(function() {
452
- var d = new Date();
453
- d.setHours(10);
454
- return { date: d };
455
- });
456
- ```
457
-
458
- #### 2.6 Record Event Duration
459
-
460
- If you need to record the duration of an event, you can call `timeEvent` to start timing. Configure the event name you want to time. When you upload the event, `#duration` property will be automatically added to your event properties to represent the recorded duration, in seconds. Note that the same event name can only have one timing task.
461
-
462
- ```
463
- // The following example completes statistics of user's stay time on a product page
464
- ta.timeEvent("stay_shop");
465
- /**do someting
466
- .......
467
- **/
468
- // User leaves product page, timing ends, "stay_shop" event will have #duration property representing event duration
469
- ta.track("stay_shop",{product_name:"product name"});
470
- ```
471
-
472
- #### 2.7 Batch Sending
473
-
474
- SDK version 1.6.1 and above supports batch sending of data
475
-
476
- ```
477
- var config = {
478
- appId: '2f2d8810817c4cbfb7c38aeb8466615a',
479
- serverUrl: 'https://receiver-ta-preview.thinkingdata.cn',
480
- send_method: 'ajax',
481
- // Enable batch sending, default is false
482
- batch:true
483
- // or
484
- batch: {
485
- size: 6,// Automatically trigger reporting when reaching size records, default is 6
486
- interval: 6000,// Send immediately after interval milliseconds, default 6S
487
- maxLimit:500// Maximum cached data records locally, default 500
488
- },
489
- };
490
- ```
491
-
492
- - batch: Whether to enable data batch sending, optional, default value is false
493
- - size: Automatically trigger reporting when reaching size records, default is 6, minimum value is 1, maximum value is 30
494
- - interval: Send time interval, default is 6000
495
- - maxLimit: Maximum cached data records locally, default is 500
496
- Note:
497
-
498
- 1. Batch sending function and callback function cannot be used together. For example, if track has callback, using batch sending will not execute callback.
499
- 2. Batch sending uses ajax method to send data by default.
500
- 3. If localStorage already has more than 200 records, batch sending function will fail. Only these 200 records will be saved in localStorage. New generated data will use configured method to send data. When localStorage exceeds maximum value, 20 records will be removed each time according to FIFO strategy, and these 20 records will be sent once.
501
- 4. app_js_bridge and batch_send can only choose one. If cross-domain integration is enabled, batch sending cannot be used.
502
- 5. Uses localStorage storage.
503
- 6. debug or debugOnly will send data directly, not cache locally then batch report.
504
- 7. After enabling, data will only be reported when specified count or time interval is met. For pages with frequent transitions, data may not be reported before page closes, causing some data loss. Please enable with caution.
505
-
506
- ### 3. User Properties
507
-
508
- TE platform supported user property setting APIs are: `userSet`, `userSetOnce`, `userAdd`, `userUnset`, `userDelete`, `userAppend`, `userUniqAppend`.
509
-
510
- #### 3.1 userSet
511
-
512
- For general user properties, you can call `userSet` to set. Properties uploaded using this interface will override original property values. If the user property did not exist before, it will create a new user property with the same type as the uploaded property. Here is an example of setting username:
513
-
514
- ```
515
- // username is TA
516
- ta.userSet({ username: "TA" });
517
- // username is TE
518
- ta.userSet({ username: "TE" });
519
- ```
520
-
521
- #### 3.2 userSetOnce
522
-
523
- If the user property you want to upload only needs to be set once, you can call `userSetOnce` to set. When the property already has a value, this information will be ignored. Here is an example of setting first payment time:
524
-
525
- ```
526
- // first_payment_time is 2018-01-01 01:23:45.678
527
- ta.userSetOnce({first_payment_time: "2018-01-01 01:23:45.678" });
528
- // first_payment_time is still 2018-01-01 01:23:45.678
529
- ta.userSetOnce({first_payment_time: "2018-12-31 01:23:45.678" });
530
- ```
531
-
532
- #### 3.3 userAdd
533
-
534
- When you want to upload numeric properties, you can call `userAdd` to perform accumulation operation on that property. If the property has not been set, it will assign 0 then perform calculation. If negative value is passed, it's equivalent to subtraction operation.
535
-
536
- ```
537
- // At this time total_revenue is 30
538
- ta.userAdd({ total_revenue: 30 });
539
- // At this time total_revenue is 678
540
- ta.userAdd({ total_revenue: 648 });
541
- ```
542
-
543
- #### 3.4 userUnset
544
-
545
- When you want to clear user's user property value, you can call `userUnset` to clear specified property. If the property has not been created in the cluster, `userUnset` **will not** create that property.
546
-
547
- ```
548
- // Clear the user property value named userPropertykey, set to NULL
549
- ta.userUnset("userPropertykey");
550
- ```
551
-
552
- #### 3.5 userDelete
553
-
554
- If you want to delete a user, you can call `userDelete` to delete that user. You will no longer be able to query that user's user properties, but events generated by that user can still be queried.
555
-
556
- ```
557
- ta.userDelete();
558
- ```
559
-
560
- #### 3.6 userAppend
561
-
562
- You can call `userAppend` to append elements to array type user data.
563
-
564
- ```
565
- ta.userAppend({ user_list: ["apple", "ball"] });
566
- ```
567
-
568
- #### 3.7 userUniqAppend
569
-
570
- Since v1.6.0, you can call `userUniqAppend` to append unique elements to Array (List) type user data. Calling `userUniqAppend` interface will deduplicate appended user properties. `userAppend` interface does not deduplicate, user properties may have duplicates.
571
-
572
- ```
573
- // At this time user_list property value is ["apple", "ball"]
574
- ta.userAppend({ user_list: ["apple", "ball"] });
575
- // At this time user_list property value is ["apple", "apple", "ball", "cube"]
576
- ta.userAppend({ user_list: ["apple", "cube"] });
577
- // At this time user_list property value is ["apple", "ball", "cube"]
578
- ta.userUniqAppend({ user_list: ["apple", "cube"] });
579
- ```
580
-
581
- ### 4. Support Data Transfer Encryption
582
-
583
- Since v1.6.0, data reporting via ajax supports data transfer encryption. You can configure encryption related information in SDK initialization config.
584
-
585
- ```
586
- var config = {
587
- appId: "xxx",
588
- serverUrl: "xxx",
589
- secretKey: {
590
- // Encryption public key, can be obtained from TE management backend
591
- publicKey: 'public key',
592
- // Public key version number
593
- version: 1
594
- },
595
- };
596
- ```
597
-
598
- <!-- unsupported block: 34 -->
599
-
600
- To support data encryption, you need to additionally import crypto-js and jsencrypt.
601
-
602
- ```
603
- <script src="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/crypto-js.js"></script>
604
- <script src="https://cdn.bootcss.com/jsencrypt/3.2.1/jsencrypt.js"></script>
605
- ```
606
-
607
- ### 5. Multi-domain Cross-domain Integration
608
-
609
- SDK version 1.6.1 and above supports multi-domain cross-domain integration, which can unify user behavior across two different domain websites. It allows you to more effectively observe the conversion journey of related website users.
610
-
611
- ```
612
- ta.quick('siteLinker', {
613
- linker: [
614
- { part_url: 'thinkingdata.cn', after_hash: true },
615
- { part_url: 'example.com', after_hash: true }
616
- ]
617
- })
618
- ```
619
-
620
- part_url : The configured part_url string must be a substring of the URL to be integrated.
621
-
622
- Target domain to integrate
623
-
624
- Configuration
625
-
626
- a tag href address
627
-
628
- a tag integration result
629
-
630
- thinkingdata.cn
631
-
632
- { part_url: 'thinkingdata.cn', after_hash: false }
633
-
634
- https://thinkingdata.cn/
635
-
636
- https://thinkingdata.cn/?_tasdk='d'+distinctID
637
-
638
- after_hash: Required attribute, and attribute value must be boolean type, i.e. true or false. Configure whether \_tasdk parameter is in URL hash part (after #) or URL search part (before #, the ? part)
639
-
640
- url
641
-
642
- after_hash
643
-
644
- result
645
-
646
- https://thinkingdata.cn
647
-
648
- false
649
-
650
- https://thinkingdata.cn?_tasdk=distinctID
651
-
652
- true
653
-
654
- https://thinkingdata.cn#?_tasdk=distinctID
655
-
656
- https://thinkingdata.cn#index
657
-
658
- false
659
-
660
- https://thinkingdata.cn?_tasdk=distinctID#index
661
-
662
- true
663
-
664
- https://thinkingdata.cn#index?_tasdk=distinctID
665
-
666
- https://thinkingdata.cn?a=1#index
667
-
668
- false
669
-
670
- https://thinkingdata.cn?a=1&_tasdk=distinctID#index
671
-
672
- true
673
-
674
- https://thinkingdata.cn?a=1#index?_tasdk=distinctID
675
-
676
- https://thinkingdata.cn?a=1#index?b=2
677
-
678
- false
679
-
680
- https://thinkingdata.cn?a=1&_tasdk=distinctID#index?b=2
681
-
682
- true
683
-
684
- https://thinkingdata.cn?a=1#index?b=2&_tasdk=distinctID
685
-
686
- ### 6. Other Features
687
-
688
- #### 6.1 Get Device ID
689
-
690
- You can get device ID by calling `getDeviceId`:
691
-
692
- ```
693
- var deviceId = ta.getDeviceId();
694
- ```
695
-
696
- #### 6.2 Set Default Timezone
697
-
698
- By default, SDK uses local time at interface call time as event occurrence time for reporting. You can also set default timezone during initialization, so all events will align event time according to the timezone you set:
699
-
700
- ```
701
- var config = {
702
- appId: "xxx",
703
- serverUrl: "xxx",
704
- zoneOffset:8
705
- };
706
- ```
707
-
708
- <!-- unsupported block: 34 -->
709
-
710
- Note: Aligning event time with specified timezone will lose device local timezone information. If you need to preserve device local timezone information, you currently need to add related properties to events yourself.
711
-
712
- ---
713
-
714
- # Multi Instance
715
-
716
- You can create sub-instance objects by calling `initInstance` method. Its parameter is sub-instance name. After that, you can call sub-instance interfaces through that name.
717
-
718
- ```
719
- // Create an instance named newInstance
720
- ta.initInstance("newInstance");
721
- // Set distinct_id for sub-instance and send test_event event
722
- ta.newInstance.setDistinctId("new_distinct_id");
723
- ta.newInstance.track("test_event");
724
- ```
725
-
726
- By default, sub-instance uses the same configuration as main instance (`appId`, `serverUrl` etc.). And by default, sub-instance does not enable local cache.
727
-
728
- If you need to configure parameters separately for sub-instance, you can pass configuration information during initialization. By passing different `appId` values in configuration information, you can achieve reporting data to different projects:
729
-
730
- ```
731
- // Define sub-instance configuration parameters
732
- var param = {
733
- appId: "debug-appid",
734
- serverUrl: "ANOTHER_SERVER_URL",
735
- persistenceEnabled: true, // Enable sub-instance local cache, sub-instance local cache is distinguished by sub-instance name
736
- send_method: "image",
737
- showLog: true
738
- };
739
-
740
- // Initialize sub-instance
741
- ta.initInstance("anotherInstance", param);
742
-
743
- // Report data to main instance project
744
- ta.track("Event");
745
-
746
- // Report data to sub-instance project
747
- ta.anotherInstance.track("Event");
748
- ```
749
-
750
- Main instance and sub-instance ID systems are not shared, common properties are not shared. You can set user ID for each instance separately. The following example uses this feature to report invite success and be invited events for the inviter and invited person in the invite friend event:
751
-
752
- ```
753
- // Main instance is the newly invited user, sub-instance is the inviter
754
- ta.login("invitee");
755
- ta.anotherInstance.login("inviter");
756
- // New user triggers be invited event
757
- ta.track("be_invited");
758
- // Inviter triggers invite new user event
759
- ta.anotherInstance.track("invite_new_user");
760
- ```
761
-
762
- ---
763
-
764
- # Real-time Debugging
765
-
766
- During SDK integration, you can perform real-time debugging by viewing SDK logs in console or using TE's Debug function.
767
-
768
- ### 1. Print SDK Logs
769
-
770
- You can set showLog to true during SDK initialization to enable SDK log switch. After enabling, reported data will be printed in browser console.
771
-
772
- ```
773
- var config = {
774
- appId: "xxx",
775
- serverUrl: "xxx",
776
- showLog:true
777
- };
778
- ```
779
-
780
- ### 2. Debug Mode
781
-
782
- Enabling Debug mode requires the following two steps:
783
-
784
- 1. Client enables Debug mode
785
- You can enable Debug mode during SDK initialization:
786
-
787
- ```
788
- var config = {
789
- appId: "xxx",
790
- serverUrl: "xxx",
791
- /*normal mode: Data will be cached and reported according to certain cache strategy, default is NORMAL mode; recommended for production environment
792
- debug mode: Data is reported one by one. When problems occur, logs and exceptions will be displayed to users; not recommended for production environment
793
- debug_only mode: Only validates data, will not be stored in database; not recommended for production environment
794
- */
795
- mode:"debug"
796
- };
797
- ```
798
-
799
- 1. TE backend adds Debug device
800
- To avoid Debug mode going live in production environment, only specified devices can enable Debug mode. Only when Debug mode is enabled on client and the device ID is configured in TE backend's "Tracking Management" page's "Debug Data" section can Debug mode be enabled.
801
-
802
- Device ID can be obtained through the following three ways:
803
-
804
- - #device_id property in event data in TE platform
805
- - Client log: Device DeviceId will be printed after SDK initialization completes
806
- - Through instance interface call: Get device ID
807
- <!-- unsupported block: 34 -->
808
-
809
- Debug mode may affect data collection quality and application stability, only use for integration phase data validation, do not use in production environment.
810
-
811
- ---
812
-
813
- # Auto Tracking
814
-
815
- ### 1. Monitor HTML Element Click Events
816
-
817
- If you want to track click events on page elements, you can use `trackLink` to batch monitor HTML elements:
818
-
819
- ```
820
- ta.trackLink(
821
- {
822
- tag: ["a", "button"], // HTML tags
823
- class: ["class1", "class2"], // Custom Class names
824
- id: ["id1", "id2"] // Custom ID names
825
- }, // Element monitoring rules
826
- "click", // Track event name
827
- {
828
- production: "product name",
829
- name: "element identifier name"
830
- } // Event properties
831
- );
832
- ```
833
-
834
- - The first parameter is the elements you need to monitor, type is JSON object, supports tracking page elements based on HTML tags, Class and id. For elements satisfying rules, click events will be monitored through event listener. When monitored element is clicked, an event will be reported. Event name and event properties take the values of the following two parameters.
835
- - The second parameter is event name, string type, must be filled.
836
- - The third parameter is event properties, type is JSON object. If no properties need to be reported, empty JSON can be passed.
837
- - Event property `'name'` is element identifier. If event property `'name'` is not set in parameter three, we will use monitored element's attribute value as element identifier. Priority order:
838
-
839
- 1. Element's custom attribute `'td-name'`
840
-
841
- 2. Element's `innerHTML`
842
-
843
- 3. Element's value
844
-
845
- 4. If none is obtained, `'not obtained'` will be passed.
846
-
847
- <!-- unsupported block: 34 -->
848
-
849
- trackLink will set event listener for elements matching rules when called. If element identifier changes after calling interface, or new elements matching rules are generated, the event reported by listener will not change accordingly. If you need to monitor newly generated elements, you can call trackLink after element generation.
850
-
851
- ### 2. Page Show and Hide Events
852
-
853
- - Enable method
854
- - Since v1.6.0, `ta_page_show` and `ta_page_hide` events are added.
855
- - SDK does not collect these events by default, you can configure through SDK initialization config.
856
-
857
- ```
858
- var config = {
859
- appId: 'xxx',
860
- serverUrl: 'xxx',
861
- autoTrack: {
862
- // Enable ta_page_show event
863
- pageShow: true,
864
- // Enable ta_page_hide event
865
- pageHide: true,
866
- properties: { // Auto tracking custom properties
867
- staticKey: 'staticValue'
868
- },
869
- callback: (eventType) => { // Auto tracking callback
870
- if (eventType === 'pageShow') {
871
- return { appShowKey: 'appShowValue' };
872
- } else if (eventType === 'pageHide') {
873
- return { appHideKey: 'appHideValue' };
874
- } else {
875
- return {};
876
- }
877
- }
878
- }
879
- };
880
- ```
881
-
882
- - Since v2.1.2, page show and hide events support auto tracking custom properties and auto tracking callback.
883
- - `ta_page_hide` event will put the duration from this page show to close in property `#duration`.
884
- - If the first ta_page_show needs to carry user related information, you can pass it during initialization.
885
-
886
- ```
887
- var config = {
888
- appId: 'appId',
889
- serverUrl: 'serverUrl',
890
- send_method: 'ajax',
891
- accountId: 'xx',// Set account ID
892
- distinctId: 'xx',// Set visitor ID
893
- superProperties: {// Set static common properties
894
- super1: 'xx',
895
- super2: 'xx'
896
- }
897
- };
898
- ```
899
-
900
- ### 3. Page View Event
901
-
902
- TE provides interface for auto collecting page view events. You just need to use the following code, JS SDK will automatically upload user page view events, event name is ta_pageview:
903
-
904
- ```
905
- ta.quick("autoTrack");
906
- ```
907
-
908
- Since v1.6.0, custom properties are supported.
909
-
910
- ```
911
- ta.quick('autoTrack', {
912
- name: 'test_name',
913
- time: new Date(),
914
- pro: [1, 2, 3, 4],
915
- })
916
- ```
917
-
918
- <!-- unsupported block: 34 -->
919
-
920
- This interface will report a page view event immediately when called.
921
-
922
- ---
923
-
924
- # Preset Properties
925
-
926
- ### 1. Preset Properties for All Events
927
-
928
- The following preset properties are preset properties that all events (including auto tracking events) will have in JavaScript SDK
929
-
930
- **Property Name**
931
-
932
- **English Name**
933
-
934
- **Property Type**
935
-
936
- **Description**
937
-
938
- #ip
939
-
940
- IP Address
941
-
942
- Text
943
-
944
- User's IP address, TE will use this to obtain user's geographic location information
945
-
946
- #country
947
-
948
- Country
949
-
950
- Text
951
-
952
- User's country, generated based on IP address
953
-
954
- #country_code
955
-
956
- Country Code
957
-
958
- Text
959
-
960
- User's country code (ISO 3166-1 alpha-2, i.e. two uppercase English letters), generated based on IP address
961
-
962
- #province
963
-
964
- Province
965
-
966
- Text
967
-
968
- User's province, generated based on IP address
969
-
970
- #city
971
-
972
- City
973
-
974
- Text
975
-
976
- User's city, generated based on IP address
977
-
978
- #device_id
979
-
980
- Device ID
981
-
982
- Text
983
-
984
- User's device ID
985
-
986
- #screen_height
987
-
988
- Screen Height
989
-
990
- Numeric
991
-
992
- User device's screen height, such as 1920 etc.
993
-
994
- #screen_width
995
-
996
- Screen Width
997
-
998
- Numeric
999
-
1000
- User device's screen width, such as 1080 etc.
1001
-
1002
- #lib
1003
-
1004
- SDK Type
1005
-
1006
- Text
1007
-
1008
- The type of SDK you integrated, such as JavaScript etc.
1009
-
1010
- #lib_version
1011
-
1012
- SDK Version
1013
-
1014
- Text
1015
-
1016
- The version of SDK you integrated
1017
-
1018
- #os
1019
-
1020
- Operating System
1021
-
1022
- Text
1023
-
1024
- Such as Android, iOS etc.
1025
-
1026
- #browser
1027
-
1028
- Browser Type
1029
-
1030
- Text
1031
-
1032
- Browser type used by user, such as Chrome, Firefox etc.
1033
-
1034
- #browser_version
1035
-
1036
- Browser Version
1037
-
1038
- Text
1039
-
1040
- Browser version used by user, such as Chrome 61.0, Firefox 57.0 etc.
1041
-
1042
- #zone_offset
1043
-
1044
- Timezone Offset
1045
-
1046
- Numeric
1047
-
1048
- Data time offset hours relative to UTC time
1049
-
1050
- #system_language
1051
-
1052
- System Language
1053
-
1054
- Text
1055
-
1056
- User's system language setting
1057
-
1058
- #ua
1059
-
1060
- User Agent
1061
-
1062
- Text
1063
-
1064
- User's current agent information, can identify client's operating system and version, CPU type, browser and version, browser rendering engine, browser language, browser plugins etc.
1065
-
1066
- #utm
1067
-
1068
- UTM Parameters
1069
-
1070
- Text
1071
-
1072
- User's advertising source information, including advertising source, advertising medium etc.
1073
-
1074
- ### 2. Preset Properties for Auto Tracking Events
1075
-
1076
- **Property Name**
1077
-
1078
- **English name**
1079
-
1080
- **Property Type**
1081
-
1082
- **Description**
1083
-
1084
- #url
1085
-
1086
- Page URL
1087
-
1088
- Text
1089
-
1090
- Current page's URL
1091
-
1092
- #url_path
1093
-
1094
- Page Path
1095
-
1096
- Text
1097
-
1098
- Current page's path
1099
-
1100
- #referrer
1101
-
1102
- Referrer URL
1103
-
1104
- Text
1105
-
1106
- Previous page's URL before redirect
1107
-
1108
- #referrer_host
1109
-
1110
- Referrer Path
1111
-
1112
- Text
1113
-
1114
- Previous page's path before redirect
1115
-
1116
- #title
1117
-
1118
- Page Title
1119
-
1120
- Text
1121
-
1122
- Current page's title
1123
-
1124
- ### 3. Get Preset Properties
1125
-
1126
- When server-side tracking needs some preset properties from App client side, you can get client-side preset properties through this method, then pass to server side.
1127
-
1128
- ```
1129
- // Get property object
1130
- var presetProperties = ta.getPresetProperties();
1131
-
1132
- // Generate event preset properties
1133
- var properties = presetProperties.toEventPresetProperties();
1134
- /*
1135
- {
1136
- "#os":"Mac OS X",
1137
- "#screen_width":1920,
1138
- "#screen_height":1080,
1139
- "#browser":"chrome",
1140
- "#browser_version":"91.0.4472.114",
1141
- "#device_id":"17a3858fafd9b4-0693d07132e2d1-34657600-2073600-17a3858fafea9b",
1142
- "#zone_offset":8
1143
- }
1144
- */
1145
-
1146
- // Get a specific preset property
1147
- var os = presetProperties.os;// OS type, such as Android
1148
- var screenWidth = presetProperties.screenWidth;// Screen width
1149
- var screenHeight = presetProperties.screenHeight;// Screen height
1150
- var browser = presetProperties.browser;// Browser type
1151
- var browserVersion = presetProperties.browserVersion;// Browser version number
1152
- var deviceId = presetProperties.deviceId;// Device ID
1153
- var zoneOffset = presetProperties.zoneOffset;// Timezone offset value
1154
- ```
1155
-
1156
- <!-- unsupported block: 34 -->
1157
-
1158
- IP, country and city information are parsed and generated by server side, client side does not provide interface to get these properties
1159
-
1160
- ### 4. Disable Preset Property Collection
1161
-
1162
- In some scenarios, due to compliance or actual business requirements, you may want to disable collection of certain preset properties. You can pass `disablePresetProperties` field during initialization, type is Array. Added field's corresponding preset property will not be uploaded. For example, blocking "#os", "#lib", "#lib_version", @"#url", @"#url_path" etc. preset properties, configuration as below:
1163
-
1164
- ```
1165
- var config = {
1166
- appId: "APP_ID",
1167
- serverUrl: "https://YOUR_SERVER_URL/sync_js",
1168
- batch:true,
1169
- autoTrack: {
1170
- pageShow: true,
1171
- pageHide: true,
1172
- },
1173
- disablePresetProperties:['#os','#lib_version','#lib','#screen_height','#screen_width','#browser','#browser_version',
1174
- '#system_language','#ua','#utm','#referrer','#referrer_host','#url','#url_path','#title','#element_type']
1175
- };
1176
- window.ta = thinkingdata;
1177
- ta.init(config);
1178
- ```
1179
-
1180
- <!-- unsupported block: 34 -->
1181
-
1182
- If you block device ID and need to use first-time event, please fill in first_check_id property