How to use url_path in Google Tag Manager to track directories - google-analytics

I want to have content groups in Google Analytics and I'm using Google Tag Manager to implement them. The way to do it, according to their reference, is to create a lookup table that is using the url_path macro to filter URLs. The url_path only gives the path of the URL, stripping the end of it, so for a url http://www.example.com/hello/index.html the result would be /hello/.
I want to group my users' account pages which are like: http://www.example.com/accounts/profile/user1/
The problem with the above macro is that it would return /accounts/profile/user1 which is not what I want. I only want to keep /accounts/profile/.
How could I accomplish that using this macro?

For helping you, in GTM you just have to configure the "Content Grouping" part (and take special care of the index that you put in). All the stuff is on GA Backend, where you declare your content group and which give you an index for each content group (index that you have to keep in GTM).
For some GA account you have to wait around 48 hours till you got some data, if your hit is ok you can see your content grouping information in the variable utmpg (like :" 1:Accueil,2:Page de destination | Actualité | ---,5:www.ouest-france.fr/home" for example).
Hopes it will help you to understand.
Fanny

Related

Setting up Adobe Analytics eCommerce tracking in GTM

I am currently in the process of setting up Adobe Analytics on a website that is currently using GTM & GA (universal analytics). Ideally I want to leverage the existing data layer to pass values to the Adobe evars/props but the one question I have was how to handle the products field? Adobe requires the products field to be in a very specific format (category;product;qty;total).
Can I build this product string in GTM? Or do I need the developers to hard code this string? I might be overthinking this but I have never installed Adobe thru GTM before
You can use a custom javascript variable (GTM "variables" used to be called "macros" which was a lot less confusing) of the type "custom javascript function" to loop through the products array and assemble the product string.
That is you'd first create a dataLayer variable that returns the product array from the dataLayer and then do a loop; a custom javascript variable in GTM is an anonymous function that returns a value. This would look a bit like that (from top of my head, not exact code; the thing in curly brackets is the datalayer products variable you need to create first):
function() {
var products = {{products}};
var productAdobe = [];
for(i=0;i<products.length;i++) {
prod = products[i];
productAdobe.push(prod[i].category + ";" + prod[i].id + ";" + prod[i].quantity + ";" + prod[i].quantity*prod[i].price);
}
return productAdobe.join("\n");
}
Like I said this is not exactly working code, but should be enough to give you an idea.
Having said that having your developers pass on a proper product string is a much better idea. Using GTM for programming tasks is error prone and makes maintenance hard (and tag management should make your life easier, not harder). And if you already have Adobe Analytics you should have free Access to Adobe DTM which might a better choice to deploy Adobe Analytics (for one thing you cannot host s_code within GTM, as the custom HTML tag has a length limit that is exceeded by the Adobe Tracking code).

How to Track Store Locator Search terms in Google Universal Analytics

I am in the process of setting up enhanced Ecommerce for GA and have had a few requests of additional of what else the client would like to see in their reports. Once of which is
"Where can i see a report if the locations that a use types in when they use the store locator"
There is already an internal search functionality thats been set up and is tracking the search terms people are typing when looking for products, but i'm not sure if i would need to set this up as a second search terms report or if it's something different?
The URL of the page is different to the internal search results and is www.domain.com/store-locator#wales|GB|0|0|0
Any insight into this would be really helpful.
Thanks,
Roxi
As to me knowledge, you are not able to use bookmarks (#something) in GA for internal site search setup. Only GET and POST parameters are allowed. In your situation I think the best solution is to use GA events to send the data about used location each time the user is using this functionality. You need to include addition ga() function call to track those events. Info about how to set it up you could find here: event tracking. After setting things up, you will see all the info about number and type of called events in Behavior -> Events reports section in GA.
Example code:
<button onlick="var hash_location=window.location.hash;ga('send','event','Locator',has_location)">Click me</button>
With such function new event will be send to GA with Event Category=Locator and Event Action=hash in the url. You have some complicated hash, so most probably you need to extract first some info from this using regular expression. Example to get first item from |-separated list in the hash:
var pattern = new RegExp('[^#|]+');
var hash_location = pattern.exec(window.location.hash)[0];

pagePath and nextPagePath in analytics api not working

I try to get a list of pages people go after visiting the selected page. pagePath is a starting page, nextPagePath is the result list of pages I'm interested in. I included a filter to show only one starting page. But the result I get is confusing:
What am I doing wrong?!
Use ga:previousPagePath instead of ga:pagePath. For the reason to me unknown, ga:pagePath and ga:nexPagePath refers in GA API to the same thing.

youtube channel new ID and iframe list user_uploads

It seems that youtube are now using ID's for their channels instead of names (part of the V3 api)
However it seems that the embedded iframe playlist player cannot handle these channel ID's
example channel https://www.youtube.com/channel/UCpAOGs57EWRvOPXQhnYHpow
then ID is UCpAOGs57EWRvOPXQhnYHpow
Now try to load this
http://www.youtube.com/embed/?listType=user_uploads&list=UCpAOGs57EWRvOPXQhnYHpow
Can anyone shine a light on this issue ? Or is there some hidden username ?
I also placed this question at the gdata-issues website http://code.google.com/p/gdata-issues/issues/detail?id=6463
The issue here is that a channel is not a playlist; channels can have multiple playlists, yet the listType parameter is designed to look for an actual playlist info object. The documented way around this is to use the data API and call the channel endpoint, looking at the contentDetails part:
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UCuo5NTU3pmtPejmlzjCgwdw&key={YOUR_API_KEY}
The result will give you all of the feeds associated with that channel that you can choose from:
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUuo5NTU3pmtPejmlzjCgwdw"
}
}
If available (sometimes with oAuth), there could also be "watch later" lists, "likes" lists, etc.
This may seem like a lot of overhead. In the short term, though, it can be noted that the different feeds are programmatically named; so, for example, if my user channel begins with UC and then a long string, that UC stands for 'user channel' -- and the uploads feed would begin with 'UU' (user uploads) and then have the rest of the same long string. (you'd also have 'LL' for the likes list, 'WL' for the watch later list, 'HL' for the history list, 'FL' for the favorites list, etc. This is NOT documented, and so there's no guarantee that such a naming convention will perpetuate. But at least for now, you could change your ID string from beginning with UC to beginning with UU, like this:
http://www.youtube.com/embed/?listType=user_uploads&list=UUpAOGs57EWRvOPXQhnYHpow
And it embeds nicely.
Just to inform on current state of things -- the change suggested by jlmcdonald doesn't work anymore, but you can still get a proper embed link via videoseries (with the same UC to UU change). I.o.w. link like
http://www.youtube.com/embed/videoseries?list=UUpAOGs57EWRvOPXQhnYHpow
works as of at the moment of writing this.

How to modify page URL in Google Analytics

How can you modify the URL for the current page that gets passed to Google Analytics?
(I need to strip the extensions from certain pages because for different cases a page can be requested with or without it and GA sees this as two different pages.)
For example, if the page URL is http://mysite/cake/ilikecake.html, how can I pass to google analytics http://mysite/cake/ilikecake instead?
I can strip the extension fine, I just can't figure out how to pass the URL I want to Google Analytics. I've tried this, but the stats in the Google Analytics console don't show any page views:
pageTracker._trackPageview('cake/ilikecake');
Thanks,
Mike
You could edit the GA profile and add custom filters ...
Create a 'Search and Replace' custom filter, setting the filter field to 'Request URI' and using something like:
Search String: (.*ilikecake\.)html$
Replace String: $1
(was \1)
Two possibilities come to mind:
it can take a while, up to about 24 hours, for visits to be reflected in the Analytics statistics. How long ago did you make your change?
try beginning the pathname with a "/", so
pageTracker._trackPageview('/cake/ilikecake');
and then wait a bit, as per the first item.
Usually you have the ga script code at the end of your file, while special _trackPageviews() calls are often used somewhere else.
Have you made sure you have your call to pageTracker._trackPageview() after you have defined the pagetracker?
Like this:
var pageTracker = _gat._getTracker("UA-XXXXXXX-X");
pageTracker._trackPageview();
otherwise you just get a JavaScript error I suppose.

Resources