cloudMonitorHelper.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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, "taSR_YL");
  12. } // 页面pv上报云监控
  13. export function reportCmPV({ pageCode, title, query }, tag) {
  14. const url = "pages/web-view/index";
  15. if (!title) {
  16. // eslint-disable-next-line no-param-reassign
  17. title = url;
  18. }
  19. if (!query) {
  20. // 如果没有query直接跳SYYJS服务到首页
  21. // eslint-disable-next-line no-param-reassign,prefer-destructuring
  22. query = {
  23. serviceCode: "SYYJS",
  24. };
  25. }
  26. const page = pageCode || title;
  27. const newMyAppId = getMyMiniAppId();
  28. let encodedUrl;
  29. if (query && Object.keys(query).length > 0) {
  30. encodedUrl = encodeURIComponent(`${url}?${queryString.stringify(query)}`);
  31. } else {
  32. encodedUrl = encodeURIComponent(`${url}`);
  33. }
  34. const myUrl = `alipays://platformapi/startapp?appId=${newMyAppId}&page=${encodedUrl}`; // console.log(`[YWTB] log: page: ${page}, url: ${url}, myUrl: ${myUrl}}`);
  35. if (tag === null) {
  36. // eslint-disable-next-line no-param-reassign
  37. tag = "h5SE";
  38. }
  39. monitor._lgPV({
  40. page,
  41. url,
  42. c1: tag,
  43. c2: myUrl,
  44. });
  45. }
  46. export const reportApi = (api) => {
  47. monitor.api({
  48. api,
  49. success: true,
  50. c1: "taSR_YL",
  51. time: 2000,
  52. });
  53. };