cloudMonitorHelper.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import queryString from 'query-string';
  2. import monitor from "../../../core/utils/alipayLogger";
  3. let myAppId = null; // 获取当前小程序appId
  4. export function getMyMiniAppId() {
  5. if (myAppId === null) {
  6. myAppId = my.getAppIdSync().appId;
  7. }
  8. return myAppId;
  9. }
  10. export function reportCmPV_YL(params) {
  11. return reportCmPV(params, 'h5SE_YL');
  12. } // 页面pv上报云监控
  13. export function reportCmPV({
  14. pageCode,
  15. title,
  16. query
  17. }, tag) {
  18. const url = 'pages/web-view/index';
  19. if (!title) {
  20. // eslint-disable-next-line no-param-reassign
  21. title = url;
  22. }
  23. if (!query) {
  24. // 如果没有query直接跳SYYJS服务到首页
  25. // eslint-disable-next-line no-param-reassign,prefer-destructuring
  26. query = {
  27. serviceCode: 'SYYJS'
  28. };
  29. }
  30. const page = pageCode || title;
  31. const newMyAppId = getMyMiniAppId();
  32. let encodedUrl;
  33. if (query && Object.keys(query).length > 0) {
  34. encodedUrl = encodeURIComponent(`${url}?${queryString.stringify(query)}`);
  35. } else {
  36. encodedUrl = encodeURIComponent(`${url}`);
  37. }
  38. const myUrl = `alipays://platformapi/startapp?appId=${newMyAppId}&page=${encodedUrl}`; // console.log(`[YWTB] log: page: ${page}, url: ${url}, myUrl: ${myUrl}}`);
  39. if (tag === null) {
  40. // eslint-disable-next-line no-param-reassign
  41. tag = 'h5SE';
  42. }
  43. monitor._lgPV({
  44. page,
  45. url,
  46. c1: tag,
  47. c2: myUrl
  48. });
  49. }
  50. export const reportApi = api => {
  51. monitor.api({
  52. api,
  53. success: true,
  54. c1: 'taSR_YL',
  55. time: 2000
  56. });
  57. };