DataTrackingHelper.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. using Microsoft.AppCenter.Analytics;
  2. using PDF_Master.CustomControl;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Security.Policy;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace PDFReader_WPF.Helper
  10. {
  11. /// <summary>
  12. /// 埋点辅助类
  13. /// TODO:路径追踪埋点
  14. /// </summary>
  15. public static class DataTrackingHelper
  16. {
  17. /// <summary>
  18. /// 功能入口路径类型
  19. /// </summary>
  20. public static EventType EntryPathEventType;
  21. /// <summary>
  22. /// 功能入口路径关键字
  23. /// </summary>
  24. public static EntryPathKeyType EntryPathKey;
  25. /// <summary>
  26. /// 功能入口路径
  27. /// </summary>
  28. public static string EntryPath = "";
  29. /// <summary>
  30. /// 是否需要点击后BUYNOW之后清除路径
  31. /// </summary>
  32. public static bool IsClearEntryPath = false;
  33. /// <summary>
  34. /// 触发埋点事件
  35. /// </summary>
  36. /// <param name="name"></param>
  37. /// <param name="properties"></param>
  38. public static void SendEvent(string name, IDictionary<string, string> properties = null)
  39. {
  40. try
  41. {
  42. #if !DEBUG
  43. Analytics.TrackEvent(name, properties);
  44. #endif
  45. }
  46. catch { }
  47. }
  48. public static void SendEvent(EventType type, IDictionary<string, string> properties = null)
  49. {
  50. try
  51. {
  52. #if !DEBUG
  53. Analytics.TrackEvent(type.ToString(), properties);
  54. #endif
  55. }
  56. catch { }
  57. }
  58. /// <summary>
  59. /// 适用于只上传单个键值的情况
  60. /// </summary>
  61. /// <param name="type"></param>
  62. /// <param name="key"></param>
  63. /// <param name="value"></param>
  64. public static void SendEvent(EventType type, string key, string value)
  65. {
  66. try
  67. {
  68. #if !DEBUG
  69. Analytics.TrackEvent(type.ToString(), new Dictionary<string, string>() { [key] = value });
  70. #else
  71. ////测试埋点路径使用
  72. // AlertsMessage alertsMessage = new AlertsMessage();
  73. //alertsMessage.ShowDialog("", type.ToString() + " " + key.ToString() + " " + value, "ok");
  74. #endif
  75. }
  76. catch { }
  77. }
  78. public static void SetSendInformation(EventType type, EntryPathKeyType key)
  79. {
  80. IsClearEntryPath = false;
  81. EntryPathEventType = type;
  82. EntryPathKey = key;
  83. }
  84. public static void SendPurchaseEvent()
  85. {
  86. if (!string.IsNullOrEmpty(EntryPath) && !EntryPath.Contains("None"))
  87. {
  88. try
  89. {
  90. #if !DEBUG
  91. Analytics.TrackEvent(EntryPathEventType.ToString(), new Dictionary<string, string>() { [EntryPathKey.ToString()] = EntryPath });
  92. #else
  93. //测试付费路径使用
  94. // AlertsMessage alertsMessage = new AlertsMessage();
  95. //alertsMessage.ShowDialog("", EntryPathEventType.ToString()+" " + EntryPathKey.ToString() + " " + EntryPath, "ok");
  96. #endif
  97. if (IsClearEntryPath) { EntryPath = ""; }
  98. }
  99. catch { }
  100. }
  101. }
  102. /// <summary>
  103. /// 添加最后路径
  104. /// </summary>
  105. /// <param name="thirdPath"></param>
  106. public static void AddThirdPath(ThirdPath thirdPath = ThirdPath.Subscribe)
  107. {
  108. if (!string.IsNullOrEmpty(EntryPath) && !EntryPath.Contains("None"))
  109. {
  110. if (!EntryPath.Contains("_" + thirdPath.ToString()))
  111. {
  112. EntryPath = EntryPath + "_" + thirdPath.ToString();
  113. }
  114. }
  115. }
  116. /// <summary>
  117. /// 更新第二个路径
  118. /// </summary>
  119. public static void UpdateSecondaryPath(SecondaryPath secondaryPath)
  120. {
  121. if (!string.IsNullOrEmpty(EntryPath)) { EntryPath = EntryPath.Replace(EntryPath.Substring(EntryPath.IndexOf("_") + 1), secondaryPath.ToString()); }
  122. }
  123. /// <summary>
  124. /// 添加第一个路径和第二个路径
  125. /// </summary>
  126. public static void AddFirstAndSecondaryPath(FirstPath firstPath, SecondaryPath secondaryPath)
  127. {
  128. EntryPath = firstPath.ToString() + "_" + secondaryPath.ToString();
  129. }
  130. public enum EventType
  131. {
  132. /// <summary>
  133. /// LeftSideBar
  134. /// </summary>
  135. LeftSideBar,
  136. /// <summary>
  137. /// Home
  138. /// </summary>
  139. Home,
  140. /// <summary>
  141. /// ToolBar
  142. /// </summary>
  143. Tbr,
  144. /// <summary>
  145. /// SubToolBar
  146. /// </summary>
  147. SubTbr,
  148. /// <summary>
  149. /// TopToolBar
  150. /// </summary>
  151. TopTbr,
  152. App,
  153. ActiveDialog,
  154. OnBrd,
  155. PDFView,
  156. /// <summary>
  157. /// Pop Up Window
  158. /// </summary>
  159. PUW,
  160. /// <summary>
  161. /// 编辑模块二级菜单埋点
  162. /// </summary>
  163. SubTbr_Editor,
  164. /// <summary>
  165. /// 页面编辑子功能埋点
  166. /// </summary>
  167. SubTbr_PageEdit,
  168. /// <summary>
  169. /// 工具子功能埋点
  170. /// </summary>
  171. SubTbr_Tools,
  172. /// <summary>
  173. /// 注释工具条
  174. /// </summary>
  175. SubTbr_Annotation,
  176. /// <summary>
  177. /// 编辑PDF
  178. /// </summary>
  179. SubTbr_EditPDF,
  180. /// <summary>
  181. /// 转档工具条
  182. /// </summary>
  183. SubTbr_Converter,
  184. /// <summary>
  185. /// 编辑子工具点击采购埋点
  186. /// </summary>
  187. Purchase_Editor,
  188. /// <summary>
  189. /// 编辑工具子工具点击采购埋点
  190. /// </summary>
  191. Purchase_Converter,
  192. /// <summary>
  193. /// 页面编辑子工具点击采购埋点
  194. /// </summary>
  195. Purchase_PageEdit,
  196. /// <summary>
  197. /// 编辑PDF子工具点击采购埋点
  198. /// </summary>
  199. Purchase_EditPDF,
  200. /// <summary>
  201. /// 标记密文点击采购埋点
  202. /// </summary>
  203. Purchase_Redact,
  204. /// <summary>
  205. /// 注释子工具点击采购埋点
  206. /// </summary>
  207. Purchase_Tools,
  208. /// <summary>
  209. /// AI
  210. /// </summary>
  211. Purchase_AI,
  212. Purchase_Annotation
  213. }
  214. public enum EntryPathKeyType
  215. {
  216. SubTbr_Editor,
  217. Onbrd_Converter,
  218. SubTbr_Converter,
  219. SubTbr_PageEdit,
  220. Tbr_EditPDF,
  221. Tbr_Redact,
  222. Tbr_OCR,
  223. SubTbr_Tools,
  224. Home_Tools,
  225. SubTbr_Annotation
  226. }
  227. public enum FirstPath
  228. {
  229. /// <summary>
  230. /// 阅读页
  231. /// </summary>
  232. Reading,
  233. /// <summary>
  234. /// 主页
  235. /// </summary>
  236. Home
  237. }
  238. public enum SecondaryPath
  239. {
  240. None,
  241. Compress,
  242. Merge,
  243. BatchEncypy,
  244. RemovePassword,
  245. AddWatermark,
  246. BachAddWatermark,
  247. RemoveWatermark,
  248. AddBackground,
  249. RemoveBackground,
  250. AddHeaderFooter,
  251. AddBates,
  252. toWord,
  253. toExcel,
  254. toPPT,
  255. toText,
  256. toRTF,
  257. toCSV,
  258. toHTML,
  259. toImage,
  260. ConvertPDF,
  261. ImagetoPDF,
  262. BatchToWord,
  263. BatchToExcel,
  264. BatchToPPT,
  265. BatchToText,
  266. BatchToRTF,
  267. BatchToCSV,
  268. BatchToHtml,
  269. BatchToImage,
  270. Insert,
  271. Rotate,
  272. Delete,
  273. Extract,
  274. EditPDF,
  275. Redact,
  276. OCR,
  277. WebsiteLink,
  278. EmailLink,
  279. DynamicStamp,
  280. CustomStamp,
  281. Signature,
  282. AddImage,
  283. AITranslate,
  284. AIRewrite,
  285. AICorrect,
  286. SetPassword,
  287. Crop,
  288. EditText,
  289. EditImage,
  290. Reverse,
  291. Replace,
  292. Copy,
  293. Split,
  294. Link,
  295. Sign,
  296. Stamp
  297. }
  298. public enum ThirdPath
  299. {
  300. /// <summary>
  301. /// 点击BuyNow按钮
  302. /// </summary>
  303. Subscribe
  304. }
  305. }
  306. }