GoogleAnalytics.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const UUID = Editor.require('packages://hot-update-tools/node_modules/uuid/v4');
  2. const {JSONStorage} = Editor.require('packages://hot-update-tools/node_modules/node-localstorage');
  3. const UA = Editor.require('packages://hot-update-tools/node_modules/universal-analytics');
  4. const {app} = require('electron').remote;
  5. const Package = Editor.require('packages://hot-update-tools/package.json');
  6. module.exports = {
  7. nodeStorage: null,
  8. user: null,
  9. init() {
  10. this.nodeStorage = new JSONStorage(app.getPath('userData'));
  11. const userId = this.nodeStorage.getItem('userId') || UUID();
  12. this.nodeStorage.setItem('userId', userId);
  13. this.user = UA('UA-134924925-1', userId);
  14. },
  15. event(event) {
  16. if (this.user) {
  17. this.user.event({
  18. ec: `${Package.name} : V${Package.version}`,// text 用户互动对象(video)
  19. ea: event || '',// text 用户互动类型(paly)
  20. el: '',// text 用于对事件进行分类
  21. ev: 0,// int 与事件相关的数值
  22. }).send();
  23. }
  24. },
  25. eventOpen() {
  26. this.event('open');
  27. },
  28. eventDoc() {
  29. this.event(`${Package.name}-doc`);
  30. },
  31. eventQQ() {
  32. this.event(`${Package.name}-qq`);
  33. },
  34. eventCustom(event) {
  35. this.event(event);
  36. },
  37. };