本文介绍了正则表达式替代谷歌分析的负前瞻匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Google Analytics(分析)上设置一些转化渠道.一种是分析从主站点到在虚拟目录上运行的辅助促销站点的流量(尽管在同一域中)

我应该补充一点,这是 Google Analytics 中的设置表单,我不能使用其他代码(PHP、JS、C# 等),必须一步完成

例如:

  • /default.aspx/directory/default.aspx/somedirname/default.aspx
  • [到>]
  • /promotion/default.aspx

在正则表达式领域,这将是:

  • ^/(?!promotion)(.*).aspx
  • [到>]
  • ^/promotion/(.*).aspx

问题是 Google Analytics 不再支持否定前瞻,因此正则表达式 ^/(?!promotion)(.*).aspx 失败.(参考这里,第一次回复)>

还有其他方法可以做到这一点吗?

非常感谢.

解决方案

您可以采取两步走的方法(但我不知道在 Analytics 中是否可行):

  1. 无条件替换:
    /(.*.aspx) -->/promotion/$1
  2. 再次更换:
    /promotion/promotion/(.*) -->/promotion/$1

如果一切都失败了:

^/(?:[^p]|p[^r]|pr[^o]|pro[^m]|prom[^o]|promo[^t]|promot[^i]|promoti[^o]]|促销[^n])/(.*).aspx

I'm setting up some conversion funnels on Google Analytics. One is to analyse traffic going from the main site to a secondary promotional site running on a virtual directory (on the same domain though)

I should add, this is a setup form in Google Analytics, I can't using another other code (PHP, JS, C# etc) and it has to be done in one step

So for example something like:

  • /default.aspx or /directory/default.aspx or /somedirname/default.aspx
  • [to >]
  • /promotion/default.aspx

In regular expression land, this would be:

  • ^/(?!promotion)(.*).aspx
  • [to >]
  • ^/promotion/(.*).aspx

The problem is Google Analytics no longer supports negative lookaheads, so the regexp ^/(?!promotion)(.*).aspx fails. (Reference here, first reply)

Is there another way I can do this?

Many thanks.

解决方案

You could do a two-step approach (whether that's possible in Analytics, I have no idea, though):

  1. Replace unconditionally:
    /(.*.aspx) --> /promotion/$1
  2. Replace again:
    /promotion/promotion/(.*) --> /promotion/$1

If all else fails:

^/(?:[^p]|p[^r]|pr[^o]|pro[^m]|prom[^o]|promo[^t]|promot[^i]|promoti[^o]|promotio[^n])/(.*).aspx

这篇关于正则表达式替代谷歌分析的负前瞻匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:07