How to disable Google Analytics pageviews tracking but keep event tracking? - javascript

I have a WordPress plugin which bloggers can opt-in for tracking. The data is used to improve the UX in yhe plugin's management dashboard settings pages.
Since we are only interested to track some button click events and don't really need the "pageviews" tracking, is there any way to tell Google to disable the pageviews tracking? I want to respect the publishers privacy as much as I can, and if there's no reason to track pageviews I would prefer to block it.

Disable pageview tracking
The default behavior of this snippet is to send a pageview hit to Google Analytics. This is the desired behavior in most cases; pageviews are automatically tracked once you add the snippet to each page on your site. However, if you don’t want the snippet to send a pageview hit to Google Analytics, set the send_page_view parameter to false:
gtag('config', 'GA_TRACKING_ID', { 'send_page_view': false });
From :https://developers.google.com/analytics/devguides/collection/gtagjs/#disable_page_view_tracking

You could do this with the Measurement Protocol directly. The Measurement protocol is just some HTTP posts or gets that send the data directly to your Google Analytics account. The JavaScript code that you get from Google basically does just that.
It is a little tricky there are some required fields you have to send or the data wont record correctly. But if all you want to be able to do is track some button clicks sending the events along shouldn't be to hard.
This is untested example:
http://www.google-analytics.com/collect?v=1&tid=UA-XXX-Y&cid=35009a79-1a05-49d7-b876-2b884d0f825b&t=event&ec=file&ea=upload&userclicked&ev=1
CID just needs to be a session id some way of knowing one user session from another.
NOTE: This will not record all of the normal data. you are going to loose things like language, location, pagepath. This is probably only going to store the event nothing else. I would consider putting it in its own web property to keep the data separate from any true Google Analytics recorded data.

Related

Google Tag Manager - Custom HTML Tag that sets/resets cookies - Creating an event to track user navigation

I recently thought of a scenario and a solution for tracking user behavior with Google Tag Manager (GTM) and Google Analytics (GA). I wanted to get some feedback on the idea from other GTM and GA users in the community.
Scenario:
There may be an individual or company, who would like to know when a user completed a specified conversion path on their website; perhaps, they wanted to know which users visited a product description page, education page, and, then visited the store page, in that exact order.
There are many ways to capture that behavior. The solution that seemed best to me was to send a Custom Event (ex: "Path Complete") to GA by doing the following in GTM:
1 - Create a Custom HTML Tag in GTM that uses JavaScript to set/reset a tracking cookie on every PageView. This will read/increment/reset the cookie based on the built-in Page URL variable. The cookie value will increase with each step of the goal.
2 - Create a Custom JavaScript Variable to read the cookie value during every event.
3 - Create a Tag/Trigger in GTM that sends an Event when the user has performed the final step. The condition would be, for example, cookieValue=2 and store page link clicked.
This was shown to work on my own end. I was able to view the "Path Complete" in Google Analytics after testing and publishing the solution above.
Does anyone feel that this a bad way to do things or that there may be a more effective solution to the problem? Is it typically a bad practice to create Custom HTML tags that set/reset cookies?

Cross-domain conversion tracking - Custom vs GA?

Say I'm starting a site, refer.com, where I post items on an 'affiliation' basis. When users click on my links, they're directed to the site shop.com. If the user I redirect to shop.com makes a purchase, I need that conversion tracked.
I see two possibilities:
Creating a custom tracking library (probably JavaScript) where I
request URLs from refer.com to transfer information from shop.com. I guess PHP would work too, but reduces compatibility with clients.
I use Google Analytics cross-domain tracking to do this. I don't
want the refer.com GA account to interfere with the shop.com GA account, but as I understand it you can use several accounts on the
same page, giving them different identifiers.
I feel like I'm stuck with a narrow set of possibilities. Do I do both? Neither? I need it to be as easy to implement as possible for the client, while also providing relatively bullet proof tracking. What's the standard today? Affiliation services are everywhere, and this type of cross-domain tracking has to be a very used technique. Is there another preferred method of achieving this that I'm not aware of?
This question might seem highly theoretical. While that may be true, answers with code are highly appreciated too.
I have a way for this to work but it requires both your domains to have the Universal Analytics code installed. This will not work with the older GA code
https://support.google.com/analytics/answer/1032400?hl=en
You can install multiple instances of the Google Analytics tracking code on your web pages to send data to multiple properties in your account.
You can, for example, install multiple instances of the Universal Analytics tracking code (analytics.js) on your web pages but only one instance of the Classic Analytics code (ga.js).
So (provided they have your GA code installed) when you refer to shop.com what you should do is this
Parse your GA cookie. You can get to it by $_COOKIE['_ga']. The cookie holds a string that has four parts, broken up by periods. (i.e. GA1.3.367110421.1357220305). You want those last 2 numbers (in this example 367110421.1357220305)
Pass the parsed cookie data in your referral to shop.com
shop.com should store the parsed cookie in its session
Last but not least, when shop.com has your referral data it should load your GA code and set your sessions up like this
ga('create', 'UA-YOUR-GA-CODE', {'cookieDomain': 'shop.com', 'clientId': 'USERS-PARSED-SESSION'});
What this does is it passes your GA session to their domain. At this point, GA will keep their session going so you can track what happens on shop.com. Any conversion data they pass to their GA code should be passed to your GA as well.
Is it bulletproof? No. You have to trust shop.com to properly retain and show your referrred GA session ID. But I have to use this methodology to keep my sessions between my primary sites and the centralized checkout we use and it preserves my Adwords conversions, etc.
I feel like if you're looking for ease of use for the client, Google Analytics is a pretty solid option. It is a widely used tool, with lots of documentation and active forums for feedback. Also, from my research on the topicit seems that they've got this type of behaviour in mind already.
An alternate that comes to mind is that, when redirected from site A to site B, they should be forced to authenticate on site B. You could then setup an authentication form that is unique to this referral from site A, and will be filtered into your database separately from regular authentications on site B.

Button clicks count as pageviews

My client has a single page website and want each click on the main menu for a site area count as a pageview in Google Analytics. Is this possible? I advised him to use events.
Yes, call _trackPageview in JavaScript.
_trackPageview()
_trackPageview(opt_pageURL)
Main logic for GATC (Google Analytic Tracker Code). If linker functionalities are enabled, it attempts to extract cookie values from the URL. Otherwise, it tries to extract cookie values from document.cookie. It also updates or creates cookies as necessary, then writes them back to the document object. Gathers all the appropriate metrics to send to the UCFE (Urchin Collector Front-end).
Async Snippet (recommended)
https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiBasicConfiguration#_gat.GA_Tracker_._trackPageview

Will Google Analytics track traffic if cookies are disabled in my browser?

I want to know whether Google Analytics will track traffic on my website, if my browser has cookies disabled?
I tried to search on Google but couldn't find much information about this question.
I would appreciate if you can also provide me with a source link.
Thanks
No, if you disable cookies, Google Analytics will not track you.
Google Analytics tracks you by creating cookies (or using existing cookies it finds). Then it uses that cookie information in the request it sends to http://google-analytics.com/__utm.gif. That "request" to get the __utm.gif is how the data is transmitted to Google Analytics.
Googling this is a bit difficult, since it mostly just turned up information on the cookies themselves, not what happens when they're disabled.
So, I did an experiment to prove it. I loaded StackOverflow in a fresh FireFox install with cookies disabled.
Below is the list of HTTP requests. Note that it loads ga.js, the Google Analytics script that attempts to track you. But, no request for __utm.gif is made. ga.js merely runs, realizes its unable to create cookies, and as a result has no way to create "state" from pageview to pageview.
Without cookies, Google Analytics would view every single "hit" as its own visit, and each of those visits would be a bounce. This data would be useless. As a result, GA makes the logical choice to just not track those people.
The answer appears to be YES, below is what google has to say.
The "measurement protocol" can even work withOUT cookies or js, it seems to be in beta so you have to request access.
Universal Analytics supports data collection without browser cookies.
The Universal Analytics collection methods (analytics.js and the Measurement Protocol) can be implemented and used to collect visitor usage data without cookies. These methods also work if cookies are cleared or disabled. Website visitors that don’t want their visit data reported by Google Analytics can install the Google Analytics opt-out browser add-on to opt-out.
Source: http://support.google.com/analytics/bin/answer.py?hl=en&answer=2838718
Thanks for the explanation however I thougfht cookies or no cookies Analytics will still record a vist but just can't track it. So when you say "Google Analytics would view every single "hit" as its own visit, and each of those visits would be a bounce." are you implying this is still recorded as say a 0 second or 100% Bounce visit? Or Analytics records no visit at all?
It can, but only if the site owner sets it up that way, which is difficult. The problem is tracking a user across different URLs while maintaining a UUID.
The short answer is yes - but only if the site owner found his way around the pitfalls.
I did it on my website.

Use Google Analytics custom events for feedback form

I was thinking of having a simple feedback form in my website.
It would be something like:
Your Feedback will help us improve.
[ ]
and then a textfield/textarea where the user can type (let's say) up to 100 characters of feedback.
Rather than handling it all myself on the server-side I was thinking to use Google Analytics (since my site is already wireup) and every time a user writes a comment, send a custom event to google analytics.
I think it might work.
Can people suggest a better approach or point out any problem with this idea?
There are a few problems with this.
First of all, it's against the Google Analytics Terms of Service to pass personally identifiable information to Google Analytics (#7). So, if you were to want to collect their feedback, you legally could not collect their name or email address without risking your account getting shutdown by Google.
Second, this is not at all what Google Analytics is for; its for collecting aggregate traffic and site interaction data. There's no easy-to-use interface for viewing long-form text information; I'm not even sure how you'd view event information thats longer than a few words.
Finally, Google Analytics sends its information in URLs, and there are size limitations to URLs (in Internet Explorer), and so Google Analytics will be default truncate any request with more than 2048 characters, meaning that your data will not collect accurately for longer feedback forms. (EDIT: Google Analytics recently raised this cap to 8096, by configuring the requests to use POST when >2048 characters.)
There are lots of free and easy to use data and form collection tools. Google Docs, for example, connected with Google Forms, can collect this data for you with ease. Then there's Wufoo, SurveyMonkey, UserVoice...I could go on forever.
Don't use Google Analytics for this. It's a bad idea with no upside.
Google Analytics events weren't made for gathering user feedback. Aside from the impracticalities of using the analytics console to view feedback, GA uses JSON to pass event information (which has size restrictions).
Why not try out uservoice.com or suggestionbox.com?

Categories

Resources