google-analytics - HIT 成功后 Varnish 返回 MISS

标签 google-analytics google-tag-manager varnish

我的应用程序使用 Varnish 3.0.2。我在这里面临一个奇怪的问题。有时页面是从带有 HIT 的 Varnish 提供的。但是在它返回 MISS 之后立即。

我的印象是,一旦它从缓存中得到服务,它将继续这样做,直到 TTL 过期。我的理解有误吗?

这是两种情况下的两个响应 header :

命中

HTTP/1.1 200 OK
Server: Apache/2.4.16 (Unix) mod_auth_kerb/5.4 PHP/5.3.29
X-Powered-By: PHP/5.3.29
X-Drupal-Cache: MISS
Content-Language: en
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
cache-control: max-age=86400, public
X-Cookie-Debug: Request cookie: 
X-Request-URL: /org/31633421?unit=31633421
Content-Length: 11986
Accept-Ranges: bytes
Date: Wed, 24 Apr 2019 14:26:43 GMT
X-Varnish: 330015711 330015651
Via: 1.1 varnish
Connection: keep-alive
X-Varnish-Cache: HIT
X-Varnish-Cache-Hits: 1
X-Varnish-Age: 188
X-Varnish-Leg: 128.87.225.172
X-Varnish-Cache-Version: 3.0.2

小姐

HTTP/1.1 200 OK
Server: Apache/2.4.16 (Unix) mod_auth_kerb/5.4 PHP/5.3.29
X-Powered-By: PHP/5.3.29
X-Drupal-Cache: MISS
Expires: Sun, 19 Nov 1978 05:00:00 GMT
Cache-Control: public, max-age=300
Content-Language: en
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
X-Cookie-Debug: Request cookie: _gat_UA-15166137-36=1
X-Request-URL: /org/31633421?unit=31633421
Content-Length: 11978
Accept-Ranges: bytes
Date: Wed, 24 Apr 2019 14:23:52 GMT
X-Varnish: 1900997574
Via: 1.1 varnish
Connection: keep-alive
X-Varnish-Cache: MISS
X-Varnish-Age: 0
X-Varnish-Leg: 128.87.225.158
X-Varnish-Cache-Version: 3.0.2

我已经尝试增加 TTL 值,删除所有 cookie(包括 Google Analytics),但它仍然表现得很突然。

知道为什么吗?

更新

在我的 View 模板中包含以下 Google 标签管理器 JS 代码似乎会发生这种情况。

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
      new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
      j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
      'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
      })(window,document,'script','dataLayer','GTM-XXX');</script>

最佳答案

事实证明,这实际上是我使用的正则表达式的 VCL 配置中的一个问题。我没有考虑过 Google Analytics cookie 的非字母字符。将正则表达式修改为 _[_\-\.\=a-zA-Z0-9] 一切又变得有趣了!

希望这对某人有帮助。

关于google-analytics - HIT 成功后 Varnish 返回 MISS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55833212/

相关文章:

html - 如何在 Angular (点击)方法中包含数据层函数

google-analytics - Google Analytic的自定义域

javascript - 如何结合 UA 和 AW 跟踪标签?

Varnish 缓存v4 : Incorrect Backend Health Check Response

caching - 是否可以根据 Varnish 中后端响应的大小来阻止缓存?

Varnish 3 - 如何在http header 中设置最大年龄

asp.net - 使用 Oauth token 获取 Google 分析数据?

wordpress - 使用Google Analytics(分析)和dataLayer(GTM)跟踪WP Post标签

javascript - 如何禁用谷歌分析调试js?

javascript - 谷歌标签管理器单页应用获取历史变化元素