【问题标题】:Simplest way to inject google anayltics tags into arbitrary pages?将谷歌分析标签注入任意页面的最简单方法?
【发布时间】:2009-09-11 21:34:08
【问题描述】:

我有一个目录,其中包含数百个(如果不是数千个)我为客户托管的 html 和 PHP 文件。它们目前不包含谷歌分析跟踪标签,但我们想添加它们——理想情况下实际修改文件本身。

最好的方法是什么?

我想我想将对 *.html 文件的所有请求重定向到 PHP 脚本,并让该脚本返回相关文件的内容并添加分析标记。但这对于 PHP 文件来说效果不佳——我需要 apache 来正常渲染文件,然后将输出传递给我的脚本。

mod_actions 会有帮助吗? mod_actions 和 mod_php 兼容吗?

【问题讨论】:

    标签: php apache mod-rewrite google-analytics


    【解决方案1】:

    我不想这么快就回答我自己的问题,但看起来 PHP 的 auto_append_file 指令可能会满足我的要求。

    【讨论】:

    • 我也会使用 auto_prepend_file 来启动输出缓冲,在您附加的文件中,您关闭缓冲并在
    【解决方案2】:

    这是一种在每个页面上获取页脚的方法,html 或 php 或两者都使用...使用 PERL

    http://stein.cshl.org/WWW/docs/handout.html#Adding_a_Canned_Footer_to_Every_

    【讨论】:

      【解决方案3】:

      我最终使用了类似以下的东西:

      <VirtualHost *:80>
          ServerName example.com
          DocumentRoot /var/www/html/example.com
          # Add google analytics to .php pages
          php_value auto_append_file "/var/www/html/x.example.com/myFooter.php"
          # run html pages through php so the same auto_append gets applied
          AddHandler application/x-httpd-php .html
      </VirtualHost>
      

      找到AddHandler ref here。 AddHandler php-handler 不起作用。 最初,我使用重写规则将所有 .html 请求发送到 PHP 脚本,但这破坏了诸如目录请求(实际上是请求 index.html)之类的东西。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-11
        • 1970-01-01
        • 2014-07-15
        • 2010-12-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多