tyq-event-mgr.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { tyqSDK } from "./tyq-sdk";
  2. //事件打点管理
  3. export default class TyqEventMgr {
  4. public static tyqEventMgr: TyqEventMgr = null;
  5. public static getInstance(): TyqEventMgr {
  6. if (this.tyqEventMgr == null) {
  7. this.tyqEventMgr = new this();
  8. }
  9. return this.tyqEventMgr;
  10. }
  11. public static get ins() {
  12. return this.getInstance();
  13. }
  14. //注册事件
  15. public onRegister(id: string) {
  16. console.log("event:注册");
  17. }
  18. //登陆事件
  19. public onLogin(id: string) {
  20. console.log("event:登录");
  21. }
  22. //当用户同意用户协议事件
  23. public onAgreeUseAgree() {
  24. console.log("event:同意用户协议");
  25. }
  26. //当广告加载成功
  27. public onAdLoad() {
  28. tyqSDK.collectAdAction(1);
  29. }
  30. //当广告显示成功
  31. public onAdShow() {
  32. tyqSDK.collectAdAction(2);
  33. }
  34. //当用户完整看完广告
  35. public onAdSuccess() {
  36. tyqSDK.collectAdAction(3);
  37. }
  38. //当用户取消观看广告
  39. public onAdCancel() {
  40. tyqSDK.collectAdAction(4);
  41. }
  42. //发送普通打点事件
  43. public sendEvent(eventType: string, eventName?: string) {
  44. let name = eventName ? eventType + "-" + eventName : eventType;
  45. this.sendEventPoint(name);
  46. }
  47. //发送引导事件
  48. public sendGuidStep(step) {
  49. this.sendEventPoint("引导-" + step);
  50. }
  51. private sendEventPoint(eventName) {
  52. tyqSDK.collectClickEvent(eventName);
  53. console.log("%cevent:" + eventName, "color:#FF0000");
  54. }
  55. //开始游戏
  56. public onStartGame(level: number) {
  57. console.log("event:gamestart:", level);
  58. }
  59. //结束广告
  60. public onEndGame(isWin) {
  61. console.log("event:gameEnd:", isWin);
  62. }
  63. }