You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Apache Superset中安装Posthog-js并实现跨域Iframe录制

问题:在Apache Superset中配置Posthog-js录制Iframe内仪表盘活动

我想在Apache Superset中安装Posthog-js分析工具,核心需求是使用它的界面录制功能。当前我的主站(示例:vikash.google.com)通过Iframe(Embedded SDK)加载Superset仪表盘,主站已安装Posthog-js且运行正常,但无法录制Iframe内的仪表盘用户活动。

我研究Superset项目结构后,找到tail_js_custom_extra.html文件(该文件可添加自定义前端代码,如Google Analytics),于是在其中添加了两段Posthog初始化代码,但均未生效:

第一段尝试代码

function posthogInit() {
    if (window.posthog && typeof window.posthog.init === 'function') {
      window.posthog.init('phc_JWxHyM9Pjm7j73pz9N5JQ7KW6WA0AoC2hbwbDmk1AgT', { 
        api_host: 'https://app.posthog.com',
        enable_recording_console_log: true, 
        session_recording: {
          maskAllInputs: false,
          recordCrossOriginIframes: true,
        }
      });
    } else {
      setTimeout(posthogInit, 1000); // Try again after 100ms if PostHog is not loaded
    }
  }
  posthogInit();

添加后执行了以下操作:

  • cd superset-frontend
  • rm -rf node_modules
  • npm install
  • npm run build

重启Docker后,网络日志中未出现任何Posthog相关请求。

第二段尝试代码

<script>
    console.log('tail_js_custom_extra.html is included'); // Add this line
    !function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
    posthog.init('phc_JWxHyM9Pjm7j73pz9N5JQ7KW6WA0AoC2hbwbDmk1AgT', {api_host: "https://us.i.posthog.com"})
</script>

两段代码均未生效,希望得到解决方案。


内容的提问来源于stack exchange,提问作者vikash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 21:08:17