Track events of an excluded Page - google-analytics

New to Google Analytics-
I need to exclude a URL for a View but still need to track events from Google Tag Manager.
Situation: I have a page which loads dynamically with different content in the same URL. EX: Start,Step1,Step2,Step3,Finish.
I needed to track all these steps separate and create a goal funnel(without a required start page).
To track these I used Google Tag Manager to create Page Views(virtual) and but I had to exclude the actual URL since it was triggering the goals twice.
Issue is that, when I create a event (say a click) in the page, Tag manager is sending that to Analytics but there it is not getting captured since the url is excluded.
Is there any possible way I can track the events in that page without affecting my goals and using a single actual URL?
Note: I cannot stop sending PageView for that particular page as GA script is added to a global Layout file.

If I understand correctly you want to exclude the "physical" url for a pageview in favour of a virtual url, but still want to retain the events that are sent to this physical url.
From the top of my head I'd say create an "advanced" filter, set field A to request url and match the value of the url you want to exclude, set Field B to "hit type" and use "pageview" (you might have to check if that's the proper name, but it should be), and choose "custom field 1" as output field. Set the value for the output to "exclude", and make sure that the checkmarks for "Field A required" and "Field B required" are both checked. Should look something like:
Then instead of using you current exclude by url filter create a filter that excludes based on the value of custom field 1:
That way you only dismiss the pageviews, but keep the event, even if the url is the same for both. Untested, so may require a bit of tweaking, but the principle is sound.
However I don't think this is actually the way to go (it's just cool that you can do stuff like this). I think instead you should overwrite the page path field in your event tags with the path of your respective virtual pageviews. That way you don't need filters, and it makes for better reports.

Related

Aggregate pageviews on paths with variable parameters

We are using Google Tag Manager and Google Analytics to track page views and user behaviour in a Single Page Application.
The web application has several sections designed to be beneath a specific project URL, so we have this kind of application routing:
/projects/{projectId}/section1
/projects/{projectId}/section2
/projects/{projectId}/section3
So currently our tracking works like this:
/projects/abc/section1: 3 pageviews
/projects/xyz/section1: 7 pageviews
/projects/abc/section2: 10 pageviews
/projects/xyz/section2: 10 pageviews
/projects/abc/section3: 3 pageviews
/projects/xyz/section3: 2 pageviews
We now want to also gather aggregated per-section data, such as:
/section1: 10 page views
/section2: 20 page views
/section3: 5 page views
Is there any suggested way to do so using GTM or any Analytics settings that helps us aggregating these information?
Also we want to do this without having to modify the web application (we can modify the application but we prefer it to be kept as much agnostic as possible in regards of analytics tracking).
Assuming you use Universal Analytics (and not the new Google Analytics for Apps and Web), you could create a hit based custom dimension, which would allow for a custom report with hit based metrics (such as number of pageviews - "hit based" means this is tracked per request, "session based" would store only the last value in a session). This takes some preparations in Google Analytics, but implementation-wise it can be done in the GTM interface without touching the page code (provided that page tracking is already set up correctly for your SPA).
First go the GA admin interface, to the middle column with the property settings (custom dimension are created at property level) and search for "custom definitions". Expand, click "custom dimensions", click new. Enter a name, e.g, "Sections", select "hit-based" for the scope and make sure the "active" checkbox is checked. Click "save". In the overview you will see that custom dimensions have a numeric index, if this your first custom dimension the index will be "1".
Now, go to Google Tag Manager. Enable the built-in "page path" variable. Go to custom variables, click "new", and select "custom Javascript" as type. Write some custom script to return the last segment of your path. Custom Javascript variables take the form of an anonymous function, so this could look like this:
function() {
return {{Page Path}}.split("/").pop();
}
{{Page Path}} is the built-in page (the url without protocol, hostname and parameters), the split("/") splits it along the delimiter and stores the value in an array, and the pop() returns the last element of the array, so this will always give you the bit that contains the section.
Now go to your Google Analytics tag (either the settings tag, if you want this to be send on all hits, or your pageview tags, if you want this only in pageviews; in the latter case you will e.g. be not able to filter your event reports by section). In the "custom dimensions" setting (under "more settings" in the pageview tag) click "add custom dimension". In the index field enter the numeric index for the dimension you have created in GA. In the value field, enter your "section" variable ({{Section}}, GTM variables are denoted by double curly brackets in the interface). Save, publish, wait a few hours, create a custom report with the custom dimension as primary dimension (custom dimensions do not show up in standard reports), add all hit-based metrics you want (e.h. page views) and you should be good to go.

Google Tag Manager: Send first party cookie variable into a parameter

I am having a hard time finding a way to find an element on page {click_id} and replace it with a value previously captured from a first party cookie.
I have a script on my site that generates a "click_id" value which is stored in the cookie.
I have outbound links on my site which have a placeholder {click_id}.
mylink.foo/?utm_campaign={click_id}&utm_source=hello
On click event, I want the "click_id" value to be injected in the {click_id} placeholder.
GTM doesn't have a built-in feature for modifying URLs, only for reading them, so you'll have to write some custom code. The flow should be as follows:
Create click_id variable which reads click id value from wherever it needs to
Create tag: which parses outbound links on your page and inserts click_id into them:
Get all links from page: get all the href attributes of a web site
If links are outbounds/externals: https://gist.github.com/allybee/5871749
Add click_id to outbound links: Adding a parameter to the URL with JavaScript
Note: you said you "have a script on my site that generates a "click_id" value which is stored in the cookie". So you have to be careful about "race conditions" (ie the GTM tag running before your script). What I advise is to move all your tagging/tracking scripts to GTM, and use GTM tag sequencing to make sure they all run following the necessary order.

Multiple Pages/Views with Same URL, only fire tag on one of them

I have a page that uses a MultiView in ASP.NET to hide and show page elements, rather than going to different pages. The same URL is maintained through all of these pages. If I want a tag to fire on, say, the third view in this process, how can I specify this to Google Tag Manager as a rule without having a URL change to base it on? I know there are other options besides URL, but I haven't seen any that would work in this case...
The solution I went with was to add some sort of variable indicating the page I'm on. For example, if my page was called thirdPage, then I add to the data layer:
dataLayer = [{ 'pageTitle': 'thirdPage' }];
and check for this in my tag triggers in Google Tag Manager.

Google Tag Manager Custom Events Capture Specific Page

I'm tracking multiple domains/subdomains (domain1.com, domain2.com and sub.domain1.com) with Google Tag Manager/universal analytics.
I created a Custom Tag Event (in GTM) that fires on ALL of those pages.
Is there a way to capture the specific page where that event was fired from?
For example, I have an event that fires when a user hovers over a specific <div> element. This occurs on both domain1.com, domain2.com and sub.domain1.com.
When those events fire, can I send the specific domain to GA's event catogory/action/label tags?
some suggestions:
1) You should already be able to break down an event dimension by pages or visa versa (e.g. go to the event report and add pages as 2ndary dimension. Or go to the page you want to see and put event category/action/label as 2ndary dimension). You could also create a segment based on page name. Of course, using the page names may not be useful if you are getting the default relative url (no domain). It is common for people to create a filter that adds domain prefix when spanning multiple domains.
2) Set a custom variable to pop with the domain (or full page name) during the event (or just set it when the visitor goes to the domain and set it as session/visit scope). You can then use this as a breakdown dimension. Or, you can use it to create a segment.
3) Restructure the event hierarchy to incorporate the domain. For example, make the top level (category) be the domain (or full page name). I only suggest this as something you can do but ideally you should go with #1 or #2

Using Google Analytics, if I explicitly log an event using _trackPageview, does that count as a 'real' page view?

For example, if I have a news page that's already being tracked via GA and I add a javascript event to capture clicks on a specific link to the news page (e.g. navigation) am I then 'double counting'?
If a fake pageview is not beneficial in this situation, and from your description that you're looking to track an engagement click on your page, use Event Tracking instead of Pageviews.
Tracking a click/event is easy (especially if you're already using Javascript). The best part is that this event is not considered a page view, keeping those stats safe.
The implementation is simple and allows for quite a bit of customization:
_trackEvent(category, action, opt_label, opt_value)
Below is an example of a link that's been encoded with an event tag:
Play
Here's the Google Analytics resource page on Event Tagging:
http://code.google.com/apis/analytics/docs/tracking/eventTrackerGuide.html
Well it's not a real page view, but Google Analytics thinks that it is--i.e., it shows up in your pageview counts.
Fortunately, it's easy to filter those so they don't contaminate your pageview data.
So for instance,
_gaq.push(['_trackPageview', 'unique_virtual_pagename']);
So in your GA Browser, you'll see the number of clicks actually shown as the number of pageviews of *unique_virtual_pagename*, which is not good.
There are a two ways to fix this (that i am aware of): (i) set a temporary filter at the bottom of the pageview table; or (ii) set a persistent (c*ustom*) filter in your Admin Panel (which i think is best) to remove pageviews having only the name *unique_virtual_pagename*, or whatever name you've chosen. This will of course take up to 24 hours to set, so the best plan is to set the filter first, then add the javascript to your page. so the filter is active when you begin collecting clicks.
But that just solves the problem of disaggregating these virtual pageviews from your real pageviews, you still need a way to count/record them.
I prefer to create a separate profile in these cases. So first, i filter the virtual pageviews from my actual pageviews using a custom filter, then i create a new profile which has another filter excluding everything but these virtual pageviews. I usually give that profile a name based on the event.
What you're doing is registering what's called a 'virtual page view'. To GA it's seen as a real page view and shows up in your content report's and page view counts etc. This is often useful if you want to show a page view for media that GA can't track. It's also commonly used to count an event, such as a button click, as a goal conversion.
If you just want to record the event and not count a page view you should look at using GA event tracking instead.

Resources