Extract part of URL with Google tag manager

不羁的心 提交于 2019-12-02 10:49:42

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
  }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!