浏览器监控接入

    1. nginx.conf 中添加 /ta 请求处理,以返回 TA.js 的配置。环境变量在 Erda 中将默认注入。

      ```bash

      1. set $taEnabled ${TERMINUS_TA_ENABLE};
      2. set $taUrl ${TERMINUS_TA_URL};
      3. set $collectorUrl ${TERMINUS_TA_COLLECTOR_URL};
      4. set $terminusKey ${TERMINUS_KEY};
      5. location /ta {
      6. default_type application/javascript;
      7. return 200 'window._taConfig={enabled:$taEnabled,ak:"$terminusKey",url:"$taUrl",collectorUrl:"$collectorUrl"}';
      8. }
      1. if (typeof window.$ta !== 'undefined') window.$ta('setUser', [userId])
    2. 添加 Config 类读取 TA.js 环境变量,环境变量在 Erda 中将默认注入。

    3. 添加 Controller 返回 TA.js 的配置

      1. @Slf4j
      2. @RestController
      3. @RequestMapping("/api/ta")
      4. private TaConfig config;
      5. @RequestMapping(produces = "application/javascript")
      6. @ResponseBody
      7. public String ta() {
      8. return String.format("window._taConfig={enabled:%b,ak:\"%s\",url:\"%s\",collectorUrl:\"%s\"}", config.isTerminusTaEnable(), config.getTerminusKey(), config.getTerminusTaURL(), config.getTerminusTaCollectorURL());
      9. }
      10. }
      1. <head>
      2. <script src="/api/ta"></script>
      3. <script>
      4. var _taConfig = window._taConfig;
      5. if (_taConfig && _taConfig.enabled) {
      6. !function (e, n, r, t, a, o, c) {
      7. e[a] = e[a] || function () {
      8. (e[a].q = e[a].q || []).push(arguments)
      9. }, e.onerror = function (n, r, t, o, c) {
      10. e[a]("sendError", n)
      11. }, !0), o = n.createElement(r), c = n.getElementsByTagName(r)[0], o.async = 1, o.src = t, c.parentNode.insertBefore(o, c)
      12. }(window, document, "script", _taConfig.url, "$ta");
      13. $ta('start', {udata: {uid: 0}, ak: _taConfig.ak, url: _taConfig.collectorUrl});
      14. }
      15. </script>
      16. </head>
    4. 添加 terminus-key.js 中间件。

    5. layout.hbshead 中添加 TA.js Script。

      1. <head>
      2. <script>
      3. {{#if _TA_ENABLE_}}
      4. !function(e,t,n,s,a,c,i){e[a]=e[a]||function(){(e[a].q=e[a].q||[]).push(arguments)},c=t.createElement(n),i=t.getElementsByTagName(n)[0],c.async=1,c.src=s,i.parentNode.insertBefore(c,i)}(window,document,"script","{{_TA_URL_}}","$ta");
      5. $ta('start',{ udata: { uid: {{#if _USER_}}{{_USER_.id}}{{else}}0{{/if}} }{{#if _TERMINUS_KEY_}}, ak: '{{_TERMINUS_KEY_}}'{{/if}} , url: '{{_TA_COLLECT_URL_}}' })
      6. {{/if}}
      7. </script>
      8. </head>