@thinkingai/ae-cli 6.1.37 → 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 (191) hide show
  1. package/README.md +3 -1
  2. package/README.zh.md +3 -1
  3. package/cli-installation-guide.md +1 -2
  4. package/dist/{ai-monitor-YKNYBHN2.js → ai-monitor-DST4NDOK.js} +5 -5
  5. package/dist/ai-monitor.js +7 -7
  6. package/dist/{auth-FXRGFG37.js → auth-BD3NIY3T.js} +3 -3
  7. package/dist/{automation-OQ647CSW.js → automation-IMDCJUML.js} +85 -9
  8. package/dist/{capability-GM7CH2LZ.js → capability-3NJOQHZQ.js} +3 -3
  9. package/dist/{chunk-46V4ZF7E.js → chunk-24DCOJBJ.js} +2 -2
  10. package/dist/{chunk-SHB7A2JE.js → chunk-2RORKIF6.js} +2 -2
  11. package/dist/{chunk-HBI7IQH3.js → chunk-6NJZSWUT.js} +3 -28
  12. package/dist/{chunk-QPUPWGZ3.js → chunk-DTODOQ6T.js} +1 -1
  13. package/dist/{chunk-EFGZFFSO.js → chunk-FRJUB66C.js} +1 -1
  14. package/dist/{chunk-OFOPYKYM.js → chunk-IY5G42YY.js} +2 -2
  15. package/dist/{chunk-NBXQSPXL.js → chunk-KBJHBVO7.js} +1 -1
  16. package/dist/{chunk-CYZV5AXW.js → chunk-KE5WGBXS.js} +2 -1
  17. package/dist/chunk-N2MAYIRU.js +32 -0
  18. package/dist/{chunk-IL2O4KDP.js → chunk-SQEK6S4X.js} +20 -21
  19. package/dist/{chunk-VPLRZSMY.js → chunk-STHIGWWC.js} +10 -1
  20. package/dist/{chunk-OTV5EBR5.js → chunk-TVSGS5QB.js} +5 -5
  21. package/dist/{chunk-LXRALNNA.js → chunk-UK7HQ4IL.js} +1 -1
  22. package/dist/{chunk-JFXDUX6U.js → chunk-VXKKTUU2.js} +2 -2
  23. package/dist/{chunk-E5CJI7L3.js → chunk-WRYXVIJP.js} +1 -1
  24. package/dist/{compat-check-ZMJWF6QG.js → compat-check-7VBBE7KO.js} +1 -1
  25. package/dist/{config-6G2LAH5D.js → config-LFRZBPH5.js} +4 -7
  26. package/dist/{context-Y2A6QIS3.js → context-WJQGJD6F.js} +1 -1
  27. package/dist/{data-integration-EIF5QHYF.js → data-integration-KMJWYAKK.js} +2 -1
  28. package/dist/index.js +34 -32
  29. package/dist/{memory-6QMZS4HF.js → memory-VPOPSU52.js} +3 -3
  30. package/dist/{metadata-6S3Z67JC.js → metadata-AR64J76Z.js} +5 -5
  31. package/dist/{model-LEYRQKOS.js → model-2F2354QP.js} +1 -1
  32. package/dist/{personal-semantic-preference-PKYS73D6.js → personal-semantic-preference-BCOSI4DO.js} +4 -4
  33. package/dist/{project-semantic-B5PG4JJB.js → project-semantic-DJLXAXLD.js} +4 -4
  34. package/dist/{sync-GB3IKG2D.js → sync-4TUIQ2PZ.js} +3 -3
  35. package/dist/{te-agent-S7UH657Z.js → te-agent-EMDWA3M6.js} +4 -4
  36. package/dist/{te-analysis-ZYL4AF34.js → te-analysis-XHAMRMTQ.js} +6 -6
  37. package/dist/{te-community-R63WXF6D.js → te-community-JSUSZEYH.js} +4 -4
  38. package/dist/{te-dataops-VHTPW433.js → te-dataops-I264BUTI.js} +2 -2
  39. package/dist/{te-engage-ZE7ROR3Z.js → te-engage-XNMQYO5N.js} +68 -16
  40. package/dist/{te-experiment-ZDR2JZTN.js → te-experiment-5SCHMYVO.js} +4 -4
  41. package/dist/{te-kb-6NXLBHE3.js → te-kb-QQ53TNRZ.js} +44 -13
  42. package/dist/{te-system-DB5Z3LLF.js → te-system-Z4VEB6PL.js} +1 -1
  43. package/dist/{te-team-KOSX43ZP.js → te-team-V6BBI52R.js} +87 -6
  44. package/dist/{things-G2QFXDK7.js → things-THHGDSEC.js} +4 -4
  45. package/dist/{update-XPNNE7UF.js → update-53ZUXWV5.js} +2 -2
  46. package/dist/{web-runtime-7DPC4HYJ.js → web-runtime-ZJHOIPKX.js} +4 -4
  47. package/dist/{workspace-RZESYB6T.js → workspace-W5ZPVWJS.js} +3 -3
  48. package/package.json +3 -3
  49. package/skills/ae-automation/SKILL.md +6 -2
  50. package/skills/ae-automation/references/cli.md +9 -3
  51. package/skills/ae-engage/SKILL.md +6 -1
  52. package/skills/ae-engage/references/common-metric.md +47 -1
  53. package/skills/ae-engage/references/flow-metric-update.md +1 -1
  54. package/skills/ae-engage/references/task-metric-update.md +1 -1
  55. package/skills/ae-experiment/SKILL.md +1 -1
  56. package/skills/ae-experiment/references/save_experiment.md +1 -1
  57. package/skills/ae-kb/SKILL.md +8 -6
  58. package/skills/ae-kb/references/query-workflow.md +5 -1
  59. package/skills/ae-onboarding/SKILL.md +2 -2
  60. package/skills/ae-onboarding/references/onboarding_run.md +1 -1
  61. package/skills/ae-team/SKILL.md +7 -3
  62. package/skills/ae-team/references/copy-to-personal.md +7 -0
  63. package/skills/ae-team/references/promote.md +7 -0
  64. package/skills/ae-team/references/update.md +3 -3
  65. package/skills/ae-tracking-matrix/SKILL.md +0 -170
  66. package/skills/ae-tracking-matrix/assets//345/237/213/347/202/271/346/250/241/347/211/210.xlsx +0 -0
  67. package/skills/ae-tracking-matrix/i18n.yaml +0 -12
  68. package/skills/ae-tracking-matrix/references/ae-capabilities.md +0 -93
  69. package/skills/ae-tracking-matrix/references/business-semantic-checks.md +0 -30
  70. package/skills/ae-tracking-matrix/references/categories/acquaintance_social_tracking_plan_template.md +0 -256
  71. package/skills/ae-tracking-matrix/references/categories/blockchain_game_tracking_plan_template.md +0 -213
  72. package/skills/ae-tracking-matrix/references/categories/card_game_tracking_plan_template.md +0 -407
  73. package/skills/ae-tracking-matrix/references/categories/casual_game_tracking_plan_template.md +0 -218
  74. package/skills/ae-tracking-matrix/references/categories/casual_music.md +0 -112
  75. package/skills/ae-tracking-matrix/references/categories/chess_cards_tracking_plan_template.md +0 -301
  76. package/skills/ae-tracking-matrix/references/categories/ecommerce_tracking_plan_template.md +0 -356
  77. package/skills/ae-tracking-matrix/references/categories/fishing.md +0 -775
  78. package/skills/ae-tracking-matrix/references/categories/game_basic_module_tracking_plan.md +0 -89
  79. package/skills/ae-tracking-matrix/references/categories/idle_card.md +0 -27
  80. package/skills/ae-tracking-matrix/references/categories/idle_game_tracking_plan_template.md +0 -415
  81. package/skills/ae-tracking-matrix/references/categories/interactive_video.md +0 -133
  82. package/skills/ae-tracking-matrix/references/categories/merge.md +0 -639
  83. package/skills/ae-tracking-matrix/references/categories/mmo_mobile_tracking_plan_template.md +0 -406
  84. package/skills/ae-tracking-matrix/references/categories/mmo_web.md +0 -230
  85. package/skills/ae-tracking-matrix/references/categories/music.md +0 -137
  86. package/skills/ae-tracking-matrix/references/categories/online_education_tracking_plan_template.md +0 -414
  87. package/skills/ae-tracking-matrix/references/categories/qipai_mj.md +0 -199
  88. package/skills/ae-tracking-matrix/references/categories/reading_tracking_plan_template.md +0 -158
  89. package/skills/ae-tracking-matrix/references/categories/roguelike_tracking_plan_template.md +0 -546
  90. package/skills/ae-tracking-matrix/references/categories/rpg.md +0 -195
  91. package/skills/ae-tracking-matrix/references/categories/short_drama_tracking_plan_template.md +0 -115
  92. package/skills/ae-tracking-matrix/references/categories/simulation_business_tracking_plan_template.md +0 -151
  93. package/skills/ae-tracking-matrix/references/categories/slg_tracking_plan_template.md +0 -260
  94. package/skills/ae-tracking-matrix/references/categories/slots_tracking_plan_template.md +0 -232
  95. package/skills/ae-tracking-matrix/references/categories/stranger_social_tracking_plan_template.md +0 -359
  96. package/skills/ae-tracking-matrix/references/categories/tower_defense.md +0 -365
  97. package/skills/ae-tracking-matrix/references/categories/video_editor_tracking_plan_template.md +0 -211
  98. package/skills/ae-tracking-matrix/references/categories/wechat_minigame.md +0 -132
  99. package/skills/ae-tracking-matrix/references/category-registry.md +0 -77
  100. package/skills/ae-tracking-matrix/references/data-verification/diagnosis_kb.md +0 -230
  101. package/skills/ae-tracking-matrix/references/data-verification/sql_checks.md +0 -406
  102. package/skills/ae-tracking-matrix/references/data-verification/tracking_plan_comparison.md +0 -128
  103. package/skills/ae-tracking-matrix/references/eval-cases.md +0 -74
  104. package/skills/ae-tracking-matrix/references/naming-dict.md +0 -238
  105. package/skills/ae-tracking-matrix/references/optimization-checklist.md +0 -85
  106. package/skills/ae-tracking-matrix/references/plan-generation/export-schema.md +0 -142
  107. package/skills/ae-tracking-matrix/references/plan-generation/module-baseline.md +0 -47
  108. package/skills/ae-tracking-matrix/references/plan-generation/reference.md +0 -794
  109. package/skills/ae-tracking-matrix/references/plan-generation/template-catalog.md +0 -94
  110. package/skills/ae-tracking-matrix/references/scene-routing.md +0 -80
  111. package/skills/ae-tracking-matrix/references/sdk/client-sdk/android.md +0 -3787
  112. package/skills/ae-tracking-matrix/references/sdk/client-sdk/c.md +0 -827
  113. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-lua.md +0 -655
  114. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocos2d-x.md +0 -953
  115. package/skills/ae-tracking-matrix/references/sdk/client-sdk/cocoscreator.md +0 -1128
  116. package/skills/ae-tracking-matrix/references/sdk/client-sdk/corona.md +0 -714
  117. package/skills/ae-tracking-matrix/references/sdk/client-sdk/egret.md +0 -1268
  118. package/skills/ae-tracking-matrix/references/sdk/client-sdk/flutter.md +0 -776
  119. package/skills/ae-tracking-matrix/references/sdk/client-sdk/h5-and-app-sdk-integration.md +0 -182
  120. package/skills/ae-tracking-matrix/references/sdk/client-sdk/ios.md +0 -2755
  121. package/skills/ae-tracking-matrix/references/sdk/client-sdk/javascript.md +0 -1182
  122. package/skills/ae-tracking-matrix/references/sdk/client-sdk/layaair.md +0 -1300
  123. package/skills/ae-tracking-matrix/references/sdk/client-sdk/macos.md +0 -1369
  124. package/skills/ae-tracking-matrix/references/sdk/client-sdk/mini-program-mini-game.md +0 -1692
  125. package/skills/ae-tracking-matrix/references/sdk/client-sdk/openharmony.md +0 -902
  126. package/skills/ae-tracking-matrix/references/sdk/client-sdk/react-native.md +0 -763
  127. package/skills/ae-tracking-matrix/references/sdk/client-sdk/uni-app.md +0 -1107
  128. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unity.md +0 -1532
  129. package/skills/ae-tracking-matrix/references/sdk/client-sdk/unreal.md +0 -845
  130. package/skills/ae-tracking-matrix/references/sdk/faq/android_sdk_faq.md +0 -228
  131. package/skills/ae-tracking-matrix/references/sdk/faq/ios_sdk_faq.md +0 -149
  132. package/skills/ae-tracking-matrix/references/sdk/faq/java_sdk_faq.md +0 -407
  133. package/skills/ae-tracking-matrix/references/sdk/faq/javascript_sdk_faq.md +0 -163
  134. package/skills/ae-tracking-matrix/references/sdk/faq/minigame_sdk_faq.md +0 -149
  135. package/skills/ae-tracking-matrix/references/sdk/faq/miniprogram_sdk_faq.md +0 -153
  136. package/skills/ae-tracking-matrix/references/sdk/faq/python_sdk_faq.md +0 -232
  137. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_log_guide.md +0 -314
  138. package/skills/ae-tracking-matrix/references/sdk/faq/sdk_usage_notes.md +0 -117
  139. package/skills/ae-tracking-matrix/references/sdk/faq/unity_sdk_faq.md +0 -148
  140. package/skills/ae-tracking-matrix/references/sdk/integration-tools/filebeat-logstash-guide.md +0 -645
  141. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_guide.md +0 -307
  142. package/skills/ae-tracking-matrix/references/sdk/integration-tools/logbus2_parser_plugin.md +0 -347
  143. package/skills/ae-tracking-matrix/references/sdk/integration-tools/restful_api_notes.md +0 -72
  144. package/skills/ae-tracking-matrix/references/sdk/integration-tools/ta-datax-writer-guide.md +0 -264
  145. package/skills/ae-tracking-matrix/references/sdk/server-sdk/c.md +0 -566
  146. package/skills/ae-tracking-matrix/references/sdk/server-sdk/erlang.md +0 -409
  147. package/skills/ae-tracking-matrix/references/sdk/server-sdk/golang.md +0 -446
  148. package/skills/ae-tracking-matrix/references/sdk/server-sdk/java.md +0 -557
  149. package/skills/ae-tracking-matrix/references/sdk/server-sdk/lua.md +0 -457
  150. package/skills/ae-tracking-matrix/references/sdk/server-sdk/nodejs.md +0 -490
  151. package/skills/ae-tracking-matrix/references/sdk/server-sdk/php.md +0 -523
  152. package/skills/ae-tracking-matrix/references/sdk/server-sdk/python.md +0 -484
  153. package/skills/ae-tracking-matrix/references/sdk/server-sdk/ruby.md +0 -442
  154. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/data-rules.md +0 -391
  155. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/first-event-validation.md +0 -91
  156. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/preset-properties-system-fields.md +0 -635
  157. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/updatable-events.md +0 -113
  158. package/skills/ae-tracking-matrix/references/sdk/te-data-rules/user-identification-rules.md +0 -466
  159. package/skills/ae-tracking-matrix/references/standard-base/README.md +0 -22
  160. package/skills/ae-tracking-matrix/references/standard-base/basic_event_data.md +0 -174
  161. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties.md +0 -20
  162. package/skills/ae-tracking-matrix/references/standard-base/common_event_properties_setup.md +0 -7
  163. package/skills/ae-tracking-matrix/references/standard-base/data_type_design_principles.md +0 -14
  164. package/skills/ae-tracking-matrix/references/standard-base/gameplay_event_data.md +0 -370
  165. package/skills/ae-tracking-matrix/references/standard-base/id_system_faq.md +0 -47
  166. package/skills/ae-tracking-matrix/references/standard-base/integration_must_know.md +0 -37
  167. package/skills/ae-tracking-matrix/references/standard-base/multi_platform_integration_notes.md +0 -27
  168. package/skills/ae-tracking-matrix/references/standard-base/multi_user_id_system_recommendations.md +0 -23
  169. package/skills/ae-tracking-matrix/references/standard-base/tracking_notes.md +0 -14
  170. package/skills/ae-tracking-matrix/references/standard-base/user_data.md +0 -46
  171. package/skills/ae-tracking-matrix/references/standard-base/user_id_system.md +0 -13
  172. package/skills/ae-tracking-matrix/references/system-fields.md +0 -297
  173. package/skills/ae-tracking-matrix/references/te-field-translations.md +0 -1791
  174. package/skills/ae-tracking-matrix/references/workflows/data-verification.md +0 -232
  175. package/skills/ae-tracking-matrix/references/workflows/feasibility-analysis.md +0 -829
  176. package/skills/ae-tracking-matrix/references/workflows/integration-qna.md +0 -355
  177. package/skills/ae-tracking-matrix/references/workflows/plan-generation.md +0 -283
  178. package/skills/ae-tracking-matrix/references/workflows/plan-lint.md +0 -168
  179. package/skills/ae-tracking-matrix/references/workflows/plan-review-optimize.md +0 -205
  180. package/skills/ae-tracking-matrix/references/workflows/prd-to-suggestions.md +0 -75
  181. package/skills/ae-tracking-matrix/references/workflows/troubleshooting.md +0 -36
  182. package/skills/ae-tracking-matrix/references/workflows/validated-upload.md +0 -107
  183. package/skills/ae-tracking-matrix/scripts/build_template_catalog.py +0 -114
  184. package/skills/ae-tracking-matrix/scripts/export_tracking_plan.py +0 -53
  185. package/skills/ae-tracking-matrix/scripts/finalize_plan.py +0 -166
  186. package/skills/ae-tracking-matrix/scripts/lint_tracking_plan.py +0 -674
  187. package/skills/ae-tracking-matrix/scripts/plan_contract.py +0 -200
  188. package/skills/ae-tracking-matrix/scripts/plan_types.py +0 -60
  189. package/skills/ae-tracking-matrix/scripts/prepare_delivery.py +0 -169
  190. package/skills/ae-tracking-matrix/scripts/sync_plan.py +0 -296
  191. package/skills/ae-tracking-matrix/scripts/upload_plan.py +0 -340
@@ -1,523 +0,0 @@
1
- ---
2
- code: php_sdk_installation
3
- name: "PHP"
4
- wikiToken: XjWfwdvmliurf5k9Tr7cevp3nhc
5
- parentWikiToken: O3YxwgHGiiEnvYkHCcIcX51inkf
6
- updateTime: 1745310928000
7
- sourceUrl: https://docs-v2.thinkingdata.cn/?version=6.0&lan=zh-CN&code=php_sdk_installation
8
- ---
9
-
10
- # PHP
11
-
12
- ::: tip Note
13
-
14
- Before integration, please read the Pre-Integration Guide first.
15
-
16
- You can get PHP SDK source code from GitHub.
17
-
18
- :::
19
-
20
- **Latest Version**: v3.1.1
21
-
22
- **Update Date**: 2024-07-24
23
-
24
- **Download**: Source Code
25
-
26
- ::: warning Note
27
-
28
- This document applies to v3.0.0 and later versions. For historical versions, please refer to PHP SDK Integration Guide (V2).
29
-
30
- :::
31
-
32
- ### 1. SDK Integration
33
-
34
- 1. Use composer integration
35
-
36
- ```
37
- {
38
- "require": {
39
- "thinkinggame/ta-php-sdk": "v3.1.1"
40
- }
41
- }
42
- ```
43
-
44
- 2. You can also get SDK source code from GitHub and integrate it into your project. Just put TaPhpSdk.php in your project directory. This SDK is compatible with PHP >5.5, and some features depend on curl extension.
45
-
46
- 3. Install LogBus
47
- We recommend using SDK + LogBus for server-side data collection and reporting. You can refer to the following documentation for LogBus installation: LogBus User Guide.
48
-
49
- ### 2. Initialization
50
-
51
- Here is sample code for SDK initialization:
52
-
53
- ```
54
- require_once "vendor/autoload.php";
55
-
56
- use Exception;
57
- use ThinkingData\TDLog;
58
- use ThinkingData\TDAnalytics;
59
- use ThinkingData\TDFileConsumer;
60
- use ThinkingData\TDDebugConsumer;
61
- use ThinkingData\TDBatchConsumer;
62
- use ThinkingData\ThinkingDataException;
63
-
64
- TDLog::$enable = true;
65
-
66
- $consumer = new TDFileConsumer("LOG_DIRECTORY", 200, true, "LOG_FILE_PREFIX");
67
- $teSDK = new TDAnalytics($consumer, true);
68
- ```
69
-
70
- `LOG_DIRECTORY` is the local folder address for writing. You just need to set LogBus's monitoring folder address to this address to use LogBus for data monitoring and uploading.
71
-
72
- `LOG_FILE_PREFIX` is the prefix for log file names.
73
-
74
- ### 3. Common Features
75
-
76
- To ensure successful binding of visitor ID and account ID, if your game uses both visitor ID and account ID, we strongly recommend uploading both IDs. Otherwise, account matching issues may occur, leading to duplicate user counts. For specific ID binding rules, please refer to the User Identification Rules chapter.
77
-
78
- #### 3.1 Track Events
79
-
80
- You can call `track` to upload events. We recommend setting event properties and sending conditions based on your previously documented requirements. Here is sample code for tracking events:
81
-
82
- ```
83
- $account_id = 2121;
84
- $distinct_id = 'SJ232d233243';
85
- $properties = array();
86
- $properties['age'] = 20;
87
- $properties['Product_Name'] = 'c';
88
- $properties['update_time'] = date('Y-m-d H:i:s', time());
89
- $json = array();
90
- $json['a'] = "a";
91
- $json['b'] = "b";
92
- $jsonArray = array();
93
- $jsonArray[0] = $json;
94
- $jsonArray[1] = $json;
95
- $properties['json'] = $json;
96
- $properties['jsonArray'] = $jsonArray;
97
-
98
- try {
99
- $teSDK->track($distinct_id, $account_id, "viewPage", $properties);
100
- } catch (Exception $e) {
101
- echo $e;
102
- }
103
- ```
104
-
105
- - Event name must be a string type, starting with a letter, containing numbers, letters, and underscores "\_", with maximum length of 50 characters.
106
- - Key is the property name, must be a string type, starting with a letter, containing numbers, letters, and underscores "\_", with maximum length of 50 characters. Case-insensitive, TE will convert to lowercase.
107
- - Value is the property value, supporting strings, numbers, booleans, dates, objects, object arrays, and arrays.
108
-
109
- **User property requirements are consistent with event property requirements**
110
-
111
- #### 3.2 Set User Properties
112
-
113
- For general user properties, you can call `user_set` to set them. Properties uploaded via this interface will overwrite existing property values. If the user property does not exist previously, a new user property will be created with the same type as the uploaded property. Here is an example of setting a username:
114
-
115
- ```
116
- $properties = array();
117
- $properties['once_key'] = 'twice';
118
- $properties['age'] = 10;
119
- $properties['money'] = 300;
120
- $properties['array1'] = ['str1', 'str2'];
121
- try {
122
- $teSDK->user_set('distinct_id', 'account_id', $properties);
123
- } catch (Exception $e) {
124
- //handle except
125
- echo $e;
126
- }
127
- ```
128
-
129
- #### 3.3 Data Reporting
130
-
131
- When using `TDFileConsumer`, collected events are first converted to JSON strings and added to a cache array. Data is written to disk only when the array element count exceeds the set capacity. Default capacity limit is 100 data items.
132
-
133
- In certain business scenarios, if you want data to be reported to the TE server immediately, you can call the `flush()` interface. Note that frequent calls to `flush()` will cause service performance degradation.
134
-
135
- ```
136
- $te->flush();
137
- ```
138
-
139
- #### 3.4 Close SDK
140
-
141
- ```
142
- try{
143
- $te->close();
144
- } catch (Exception $e){
145
- // Exception handling
146
- echo $e;
147
- }
148
- ```
149
-
150
- Close and exit the SDK. Please call this interface before shutting down the server to avoid data loss in the cache.
151
-
152
- ### 4. Best Practices
153
-
154
- The following sample code includes all the above operations. We recommend using it as follows:
155
-
156
- ```
157
- require_once "vendor/autoload.php";
158
-
159
- use Exception;
160
- use ThinkingData\TDLog;
161
- use ThinkingData\TDAnalytics;
162
- use ThinkingData\TDFileConsumer;
163
- use ThinkingData\TDDebugConsumer;
164
- use ThinkingData\TDBatchConsumer;
165
- use ThinkingData\ThinkingDataException;
166
-
167
- TDLog::$enable = true;
168
-
169
- $consumer = new TDFileConsumer("LOG_DIRECTORY", 200, true, "te");
170
- $teSDK = new TDAnalytics($consumer, true);
171
-
172
- $account_id = 2121;
173
- $distinct_id = 'SJ232d233243';
174
- $properties = array();
175
- $properties['age'] = 20;
176
- $properties['Product_Name'] = 'c';
177
- $properties['update_time'] = date('Y-m-d H:i:s', time());
178
- $json = array();
179
- $json['a'] = "a";
180
- $json['b'] = "b";
181
- $jsonArray = array();
182
- $jsonArray[0] = $json;
183
- $jsonArray[1] = $json;
184
- $properties['json'] = $json;
185
- $properties['jsonArray'] = $jsonArray;
186
-
187
- try {
188
- $teSDK->track($distinct_id, $account_id, "viewPage", $properties);
189
- } catch (Exception $e) {
190
- echo $e;
191
- }
192
-
193
- $properties = array();
194
- $properties['once_key'] = 'twice';
195
- $properties['age'] = 10;
196
- $properties['money'] = 300;
197
- $properties['array1'] = ['str1', 'str2'];
198
- try {
199
- $teSDK->user_set($distinct_id, $account_id, $properties);
200
- } catch (Exception $e) {
201
- //handle except
202
- echo $e;
203
- }
204
- ```
205
-
206
- ---
207
-
208
- # Advanced Guide
209
-
210
- ### 1. Track Events
211
-
212
- After SDK initialization, you can perform data tracking to collect user behavior information. Generally, regular events can meet business scenario requirements. You can also use first-time events, updateable events, etc. based on your actual business scenarios.
213
-
214
- #### 1.1 Regular Events
215
-
216
- You can call `track` to upload events. We recommend setting event properties and sending conditions based on your previously documented requirements. Here is an example of a user purchasing a product:
217
-
218
- ```
219
- // Set event properties
220
- $properties = array();
221
- $properties["product_name"] = "book";
222
- try {
223
- $te->track("distinctId", "accountId", "productBuy", $properties);
224
- } catch (Exception $e) {
225
- echo $e;
226
- }
227
- ```
228
-
229
- #### 1.2 First-Time Events
230
-
231
- First-time events are events that are recorded only once for a specific device or other dimensional ID. For example, in some scenarios, you may want to record an activation event on a specific device, which can be reported using a first-time event.
232
-
233
- ```
234
- // Example: Report first-time event, assuming event name is device_activation
235
- $properties = array();
236
- $properties["price"] = 100;
237
- $properties["status"] = 3;
238
- $firstCheckId = "first_flag_id";
239
- try {
240
- $te->track_first("distinctId", "accountId", "device_activation", $firstCheckId, $properties);
241
- } catch (Exception $e) {
242
- echo $e;
243
- }
244
- ```
245
-
246
- Note: Since first-time verification is completed on the server side, first-time events will be delayed by 1 hour before entering the database.
247
-
248
- #### 1.3 Updateable Events
249
-
250
- You can implement the need to modify event data in specific scenarios through updateable events. Updateable events need to specify an ID that identifies the event and pass it when creating the updateable event object. TE backend will determine the data to be updated based on the event name and event ID.
251
-
252
- ```
253
- // Example: Report updateable event, assuming event name is eventName
254
- // After reporting, event property status is 3, price is 100
255
- $properties = array();
256
- $properties["price"] = 100;
257
- $properties["status"] = 3;
258
- $eventId = "eventId";
259
- try {
260
- $te->track_update("distinctId", "accountId", "eventName", $eventId, $properties);
261
- } catch (Exception $e) {
262
- echo $e;
263
- }
264
-
265
- // After reporting, event with id eventId and name eventName has property status updated to 5, price unchanged
266
- $properties1 = array();
267
- $properties1["status"] = 5;
268
- try {
269
- $te->track_update("distinctId", "accountId", "eventName", $eventId, $properties1);
270
- } catch (Exception $e) {
271
- echo $e;
272
- }
273
- ```
274
-
275
- #### 1.4 Overwriteable Events
276
-
277
- Overwriteable events are similar to updateable events, except that overwriteable events will completely overwrite historical data with the latest data. Effectively, this is equivalent to deleting the previous data and inserting the latest data. TE backend will determine the data to be updated based on the event name and event ID.
278
-
279
- ```
280
- // Example: Report overwriteable event, assuming event name is eventName
281
- // After reporting, event property status is 3, price is 100
282
- $properties = array();
283
- $properties["price"] = 100;
284
- $properties["status"] = 3;
285
- $eventId = "eventId";
286
- try {
287
- $te->track_overwrite("distinctId", "accountId", "eventName", $eventId, $properties);
288
- } catch (Exception $e) {
289
- echo $e;
290
- }
291
-
292
- // After reporting, event with id eventId and name eventName has property status updated to 5, price property is deleted
293
- $properties1 = array();
294
- $properties1["status"] = 5;
295
- try {
296
- $te->track_overwrite("distinctId", "accountId", "eventName", $eventId, $properties1);
297
- } catch (Exception $e) {
298
- echo $e;
299
- }
300
- ```
301
-
302
- ### 2. User Properties
303
-
304
- TE platform supports the following user property setting APIs: `user_set`, `user_setOnce`, `user_add`, `user_unset`, `user_del`, `user_append`, `user_uniqAppend`.
305
-
306
- #### 2.1 user_set
307
-
308
- For general user properties, you can call `user_set` to set them. Properties uploaded via this interface will overwrite existing property values. If the user property does not exist previously, a new user property will be created with the same type as the uploaded property. Here is an example of setting a username:
309
-
310
- ```
311
- $properties = array();
312
-
313
- // Upload user property, create new property "user_name", value is "ABC"
314
- $properties["user_name"] = "ABC";
315
- try{
316
- $te->user_set('distinct_id', 'account_id', $properties);
317
- }catch (Exception $e){
318
- // Exception handling
319
- echo $e;
320
- }
321
- // Upload user property again, at this point "user_name" value is overwritten to "XYZ"
322
- $properties["user_name"] = "XYZ";
323
- try{
324
- $te->user_set('distinct_id', 'account_id', $properties);
325
- }catch (Exception $e){
326
- // Exception handling
327
- echo $e;
328
- }
329
- ```
330
-
331
- #### 2.2 user_setOnce
332
-
333
- If you want to set a user property only once, you can call `user_setOnce`. When the property already has a value, this information will be ignored. Here is another example of setting a username:
334
-
335
- ```
336
- $properties = array();
337
-
338
- // Same as above, upload user property, create new property "user_name", value is "ABC"
339
- $properties["user_name"] = "ABC";
340
- try{
341
- $te->user_setOnce('distinct_id', 'account_id', $properties);
342
- } catch (Exception $e){
343
- // Exception handling
344
- echo $e;
345
- }
346
-
347
- // Upload user property again, at this point "user_name" already has value, so no modification, still "ABC"; "user_age" value is 18
348
- $properties["user_name"] = "XYZ";
349
- $properties["user_age"] = 18;
350
- try{
351
- $te->user_setOnce('distinct_id', 'account_id', $properties);
352
- } catch (Exception $e){
353
- // Exception handling
354
- echo $e;
355
- }
356
- ```
357
-
358
- #### 2.3 user_add
359
-
360
- When you want to upload numeric properties, you can call `user_add` to accumulate the property. If the property has not been set, it will be assigned 0 before calculation. Negative values can be passed, equivalent to subtraction. Here is an example of accumulating total payment amount:
361
-
362
- ```
363
- try{
364
- $properties = array();
365
- $properties['level'] = 2;
366
- $te->user_add($distinct_id, $account_id, $properties);
367
- }catch (Exception $e){
368
- //handle except
369
- echo $e;
370
- }
371
- ```
372
-
373
- The property key must be a string, and Value only allows numeric values.
374
-
375
- #### 2.4 user_append
376
-
377
- You can call `user_append` to append array-type user properties.
378
-
379
- ```
380
- // user_append append one or more sets for a user
381
- try{
382
- $properties = array();
383
- $properties['arr'] = ['str3','str4'];// Append multiple values for array type, key-array format, array contains string types
384
- $te->user_append('distinct_id', 'account_id', $properties);
385
- }catch (Exception $e){
386
- //handle except
387
- echo $e;
388
- }
389
- ```
390
-
391
- #### 2.5 user_uniq_append
392
-
393
- You can call `user_uniq_append` to append array-type user properties. The `user_uniq_append` interface will deduplicate appended user properties, while `user_append` interface does not deduplicate, allowing duplicate user properties.
394
-
395
- ```
396
- // user_uniq_append append one or more sets for a user (deduplicate duplicate elements)
397
- try{
398
- $properties = array();
399
- $properties['arr'] = ['str3','str4'];// Append multiple values for array type, key-array format, array contains string types
400
- $te->user_uniq_append('distinct_id', 'account_id', $properties);
401
- }catch (Exception $e){
402
- //handle except
403
- echo $e;
404
- }
405
- ```
406
-
407
- #### 2.6 user_unset
408
-
409
- When you want to clear user property values, you can call `user_unset` to clear specified properties. If the property has not been created in the cluster, `user_unset` will not create the property.
410
-
411
- ```
412
- $properties1 = array(
413
- 'age', "update_time"
414
- );
415
- try {
416
- $te->user_unset(null, 'account_id', $properties1);
417
- } catch (Exception $e) {
418
- //handle except
419
- echo $e;
420
- }
421
- ```
422
-
423
- user_unset: The parameter is the Key value of the property to be cleared.
424
-
425
- #### 2.7 user_del
426
-
427
- If you want to delete a user, you can call `user_del` to delete the user. You will no longer be able to query the user's properties, but events generated by the user can still be queried. This operation may have irreversible consequences, please use with caution.
428
-
429
- ```
430
- try{
431
- $te->user_del('distinct_id', 'account_id');
432
- } catch (Exception $e){
433
- // Exception handling
434
- echo $e;
435
- }
436
- ```
437
-
438
- ### 3. Other Features
439
-
440
- #### 3.1 TDBatchConsumer
441
-
442
- ::: warning Note
443
-
444
- When data volume is large or network is abnormal, there is a risk of data loss. Not recommended for production environments.
445
-
446
- :::
447
-
448
- Batch real-time data transmission to TE server without requiring transmission tools.
449
-
450
- ```
451
- require "TaPhpSdk.php";
452
- $te = new TDAnalytics(new TDBatchConsumer("SERVER_URL","APP_ID"));
453
- ```
454
-
455
- Parameter Description:
456
-
457
- - `APP_ID`: Your project's APP ID, can be obtained from TE backend project management page
458
- - `SERVER_URL`: Data upload URL
459
- - If you are connecting to cloud service, enter: https://global-receiver-ta.thinkingdata.cn
460
- - If you use private deployment version, please bind domain for data collection address and configure HTTPS certificate: https://YOUR_DATA_COLLECTION_DOMAIN
461
-
462
- ---
463
-
464
- # Real-time Debugging
465
-
466
- ::: warning Note
467
-
468
- SDK Debug mode is only for integration debugging. Do not use in production environment.
469
-
470
- :::
471
-
472
- ### Print Logs
473
-
474
- ```
475
- TDLog::$enable = true;
476
- ```
477
-
478
- ### Real-time Debugging
479
-
480
- During SDK integration, you can use TE's Debug feature for real-time debugging. Enabling Debug feature requires two steps:
481
-
482
- 1. Use TDDebugConsumer
483
- Here is sample code using TDDebugConsumer:
484
-
485
- ```
486
- try {
487
- // Same as test device ID configured in TE backend
488
- $deviceId = "123";
489
- $debugConsumer = new TDDebugConsumer("SERVER_URL", "APP_ID", 1000, $deviceId);
490
- // Whether to write test data to TE, true-write, false-no write. Default value is true
491
- $debugConsumer->setDebugOnly(false);
492
- $te = new TDAnalytics($debugConsumer);
493
- } catch (Exception $e) {
494
- echo $e;
495
- }
496
- ```
497
-
498
- 2. Add Debug Device in TE Backend
499
- To prevent Debug mode from going live in production environment, only specified devices can enable Debug mode. Debug mode can only be enabled when Debug mode is turned on in the client and the device ID is configured in TE backend's "Tracking Management" page under "Debug Data" section.
500
-
501
- Debug mode may affect data collection quality and App stability. Only use for integration stage data verification, not for online environment.
502
-
503
- ---
504
-
505
- # Preset Properties
506
-
507
- The following preset properties are included in all events for PHP SDK.
508
-
509
- **Property Name** | **Chinese Name** | **Property Type** | **Description**
510
-
511
- #ip | IP Address | Text | User's IP address, needs to be set manually. TE will use this to obtain user's geographic location information.
512
-
513
- #country | Country | Text | User's country, generated based on IP address.
514
-
515
- #country_code | Country Code | Text | User's country code (ISO 3166-1 alpha-2, i.e., two uppercase English letters), generated based on IP address.
516
-
517
- #province | Province | Text | User's province, generated based on IP address.
518
-
519
- #city | City | Text | User's city, generated based on IP address.
520
-
521
- #lib | SDK Type | Text | Type of SDK you integrated, such as Java, etc.
522
-
523
- #lib_version | SDK Version | Text | Version of SDK you integrated.