使用Google跟踪代码管理器提取部分URL [英] Extract part of URL with Google tag manager

查看:83
本文介绍了使用Google跟踪代码管理器提取部分URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个网址" https://www.site.be/pand/titel-van-het-pand-t8500-17082-4 ",我必须在网址的背面提取参考号.在此示例中,将带有GTM的"t8500-17082-4"放入了这样的自定义维度:

So i have this url "https://www.site.be/pand/titel-van-het-pand-t8500-17082-4" and i have to extract the reference number at the back of the url. In this example "t8500-17082-4" with GTM to put into a custom dimension like this:

var dimensionValue = 'REFERENCE_CODE_HERE';
ga('set', 'dimension1', dimensionValue);

URL开头的参考代码可以以-t8 ...或t9 ...开头

The reference codes at the eind of the url could start with either -t8... or t9...

推荐答案

在GTM中,转到变量"->新建"->自定义JavaScript",然后输入:

In GTM go to "Variables" -> "NEW" -> "Custom JavaScript" and type:

function(){

  var myRegexp = /(-t8|-t9)(.*)/g; //assuming you only ever have one "-t8"/"-t9" in the URL
  var result = document.URL.match(myRegexp);
  if(result !== null){
    return result[0];
  }else{
    return null; //or whatever you want to return if the ID is not in the URL
  }

}

这篇关于使用Google跟踪代码管理器提取部分URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆