Reputation: 3829
I am new to GTM and in learning phase. I wanted to implement GTM on one of the websites and requirement is that
Based on URL, Analytics shall be sent to different GA accounts.
Below is the example
URL GAAccount
------------------------------------
http://domain.com/abc UA-xxxxxabc
http://domains.com/def UA-xxxxxdef
http://domain.com/xyx UA-xxxxxxyz
http://domains.com/qwe UA-xxxxxqwe
I tried to make lookuptable in GTM exactly same as mentioned above and that will operate on basis of URL but the problem here is that actual URL contains a long encrypted string as below
http://domain.com/abc/!ut/b/dasdasd654654WEEWEXX879987xxxSSWWo_adasdw_wewqewqe
So my lookuptable can not match URL and i get error in GTM console that Undefined account
I know about Page URL variables provided by GTM but i am not sure how to combine Page Hostname
and Page Path
to one Variable and then strip unwanted string from Page Path
and match the exact URL.
Upvotes: 0
Views: 184
Reputation: 347
you need 50 reps to comment :)
function () {
var value={{Page Path}}.split("/");
return value[1];
}
Hopefully this will return only abc (I'm not sure), if it works a lookup table will do the rest :)
Upvotes: 0
Reputation: 598
Lookup table did not work becuase it matches the entire url with your given input so it would check like http://domain.com/abc equals to http://domain.com/abc/!ut/b/dasdasd654654WEEWEXX879987xxxSSWWo_adasdw_wewqewqe which is obviously false
what you can do here is create a custom javascript variable that returns tracking id if your condition matches here is an example
function(){
if("{{Page URL}}".match("domain.com/abc")!==null){
return("UA-xxxxxabc")
}
else if("{{Page URL}}".match("domain.com/def")!==null){
return("UA-xxxxxdef")
}
else if("{{Page URL}}".match("domain.com/xyx")!==null){
return("UA-xxxxxxyz")
}
else if("{{Page URL}}".match("domain.com/qwe")!==null){
return("UA-xxxxxqwe")
}
}
Hope this helps
Cheers AnalyticsML
Upvotes: 3