How to track distinct pageviews on ASP.NET postbacks in Google Analytics - asp.net

The typical situation I'm dealing with is an ASP.NET form page (generally an opt-in or sign-up form) that posts back to itself when the user hits submit. By default, Google Analytics will track both of these views as the same page, so it's not possible to detect which visits are the initial view vs. which are the "success" view.
In the past, I've dealt with this in one of two ways:
Using Event Tracking to track form submission as an event. This works fine, but in GA you don't see this metric in the same place as you see the initial page views.
Dynamically adding a querystring to the form's action attribute so the resulting pageview actually shows up as a different page in GA. This feels like a hack, but I like the way the data shows up in GA.
Is either of these approaches preferable, or is there a better way to do it that I haven't thought of?

Have a look at virtual pageviews, using them you can make GA think of any event like it was a pageview with the URL you specify.

Related

Firing a trigger group multiple times on a page

I need some help with Google Tag Manager and Google Analytics.
I want to send a pageview to Google Analytics if a user is viewing an image in a gallery on an article. The user is staying on the same URL, when he is viewing an image.
I created a trigger group which consists of two events
• Consent given by the user to use Google Analytics
• Event which is fired when an image in a gallery is being viewed
This works so far so good. Unfortunately, the trigger group is only being fired once on a page. When a user open the gallery and views the image and scrolls to next image, he is staying on the same URL. In that case, the trigger group is only being fired once.
How can I achieve that the trigger group is being fired multiple times on the same page without removing the second trigger (consent)?
I found out that I can create a second trigger group and add two image views and the consent as a trigger. But this solution means that I have to create 100 new tags, which is kind of crazy. Is there any workaround?
Thanks in advance
Once consent has been given by the user in a way that each pageview can pick up (e.g. you're setting it in some persisted state: data layer, cookie, etc.), you're ultimately just looking at triggering when the event happens.
Since you describe a scenario where it happens only once, I'd urge you to take a look at the other triggers on your tag and remove the page-specific trigger your description suggests you have in place. Replace it with only your event and consent triggers and it should work every time an event is observed.

Fire a page view tag but only if it was from a specific referral URL. Google tag manager

I have a form that when submitted it goes to a different "success page" and I want to use that landing page to track conversions or count how many times people hit the "submit". I could use a page view tag but then that will fire every time someone goes to that page. So perhaps if someone hits the back button and reloads the page then that will count as a form submit.
So I would like to make a page view Tag in google tag manager that only fires if the page view is coming from a specific URL or referred from a specific URL. Is this possible?
Thanks in advance.
It is possible. Enable the built-in "referrer" variable, and on your target page create a trigger "pageview", with an added condition "referrer equals <your referrer>".
Some browsers might not send a referrer header, so this is not 100% reliable. If the page that sends the traffic is under your control, you might consider using a tracking parameter instead.

Google tag manager resetting events list on page load

We put the GTM code snippet in the site.
However the sequence of events resets every time I switch from one page to another.
For example - if a user comes on the login page, enters the login details and clicks the login button to go to the home page, the list of events reset and I lose all data about previous events.
How can i ensure that I dont lose the event data from previous pages?
There's nothing you can do about the browser resetting window-level variables, that's just how they work.
You might want to reconsider the way you think about GTM and the dataLayer. Instead of thinking of the dataLayer as a list of all past events, think of it as just a way to send data to Google Analytics (or whatever too you're using). Google Analytics is what stores the events, the dataLayer is just an interface for sending them there.
Having said that, here are some potential solutions for remembering values across pages:
You could try using something like window.sessionStorage, which will allow the browser to remember certain values across pages. This isn't a solution for remembering the entire dataLayer, but if you have one or two bits of data you want on multiple pages, this might work.
Alternatively, if you have data that's stored on the server (like the user's ID) that you want to have client-side, you could have your server generate some code to push that data when the page loads, like this:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'userId': '123'
});
Edit: I just learned that Simo Ahava found a way to do this. It is very complicated and I still recommend changing the way you think about the dataLayer, but it is possible.

Analytics User-ID view not tracking events

I've created a new view in Google Analytics with everything set up the same as a currently functioning one, only with the addition of User ID tracking turned ON. It's using the same property so the UA code has not changed.
I've copied over everything that I can think of from the current view to the new view. At first glance everything was working fine, page views were coming through via Real-Time correctly and matched up with the values seen in the current view.
For some reason though, the new view is not listing ANY actual events in Real-Time, however the events graph is being populated.
The current view IS tracking all the events correctly.
We use Tag Manager to handle all our events among other things, and using the debug mode, all events were also being triggered correctly. Finally, I've also used the GA Debugger chrome extension, which again is not showing any issues. The new User ID property is being passed through to analytics as I'd expect.
I've tried searching for any issues related to User ID views and tracking events, but came up blank, presumably because there is no inherent issue with this set up.
Any suggestions?
I found out that the reason that the events were not tracking is because the user id was not being sent along with every event.
I believed that once it was set on page load every analytics interaction after that would use that user id. This was not the case. In Tag manager I added a 'Field to set' property for all relevant tags like so;

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