Rails google analytics measuring customer retention - javascript

I'm running a website made using rails/ angular and I need to measure when a user returns to the site. I want to use this data to set up conversion tracking for the site (if a user returns, it's a conversion).
Any ideas how to set something like this up using rails/ google analytics?

Google have a nice checklist to go through what's needed to set up GA on your site. Click on the links to get details on how to go about it:
http://www.google.com/intl/en_uk/analytics/learn/setupchecklist.html
Alternatively, look into cookies. The scenario would be that a first time visitor gets a cookie saved to their cache. When they return, a JS conditional statement would +=1 to a log, since they already have the cookie saved.
Good luck.

Related

Can I programmatically get the traffic channel for the current page in javascript google analytics?

I want to programmatically know the traffic channel for the current page using javascript google analytics (or reporting) API. Like organic, google search, direct, referral, etc.
I can get referral with
tracker.get('refferer')
but I need to know the traffic channel.
For example channels
Can I get it? And if I can, then how?
no, usually you can not access it since channels are based upon source and medium combinations and these fields are processed on the server side based on referrer, document.location and previous visits information. Google Analytics provides a chart of the processing flow on the help pages
Of course, you can replicate some of the processing on the client side, by parsing utm labels from the location.href or checking the referrer but 1) this would require a ton of scripting 2) this wouldn't necessary match Google Analytics data
Some workaround can be to use classic analytics ga.js snippet alongside your usual analytics code with any dummy property ID. in this case ga.js code would process much of the source data on the client site and these data would be available from the utm* cookies
The source / medium information is available only on the landing page, if you want to have it available on a subsequent page you need to store it in a cookie. Here's an example how to do it: https://www.youtube.com/watch?v=x2pR4bCW7Mg
At list you can get from which URL you were visited:
Javascript -> document.referrer
PHP -> $_SERVER['HTTP_REFERER']
ASP -> Request.ServerVariables("HTTP_REFERER")

Google analytics - difference between analytics data and the data from the core platform

We use Google analytics with Google Tag manager for our ecommerce platform based to track the conversion, etc.,
In the thank you page, its used to track the order value and the revenues.
Consistently we see a difference of about 15 to 20 % difference between GA data and the data from the core platform.
Tried to find a pattern among the missed orders but couldnĀ“t ascertain one easily. The GA recorded orders include devices like Desktop, tablet and mobile and we see different browsers too.
Need inputs to analyze this better.
Note: Thank you page is loaded by a redirect from the payment gateway system
15-20% difference is not good at all. Google says you should expect better than 95% accuracy, and to keep at it if you're not getting those numbers.
Note: The more "techy" crowd that your website has, the more folks you'll run into "Do not track" or with Ad-Blocking tech in their browser. Normally, you'd want to try to baseline that difference using device category filters to see if the gap is bigger for desktop (most phones/tablets don't use ad-blocking).
First, question. If the user lands on the thankyou page, and hits the refresh button, does it send another "conversion" to GA? IF so, you want to make sure that you build in logic that prevents duplicate conversions to be sent if the user was not making duplicate purchases. A browser refresh is not a purchase, don't record it as such.
Second, if the page takes forever to load, or you have users that have bad internet, then that could increase the difference. They might be closing the browser or exiting site before GA client has a chance to send the final conversion to the server. So how is the performance of your thankyou page?
Are you sure you're looking at the correct business data? I've been told GA numbers are off by the business before and it turned out they messed up their own query in the transaction system (and they had been doing so for years!). It is a long shot, but if you feel super confident about your GA measurement setup, then run it by the folks giving you the transaction numbers.
Finally, if you can't get the difference down then move to the Measurement Protocol server-side implementation of GA. You simply need to record the IP address of the user and their GA client id, and then construct an HTTPS GET request using the Measurement Protocol fields for a valid hit. Server side measurement is the most accurate way to do this, but requires code updates in the ecommerce platform itself.

Implementing CPA affiliate purchases in GTM enhanced ecommerce

I'm implementing Enhanced Ecommerce on our (mainly affiliate) website through GTM. We have list views and detail views etc.. so implementing impressions and clicks is easy, but for affiliate purchases there is a problem.
We have two payment models for the shops that are showing their products on our site:
Cost per Click. I can implement a small purchase on the clickout page.
Cost per Acquisition. Here is the problem: The purchases are made on a different website on a different time. Using PHP API's I get the purchases made a few times a day through a cronjob.
How can I create a purchase (preferably using PHP, using javascript is messy on a cronjob) but retain the cookie value so I can link the purchase to the clickout and channel people used to get on our site.
I thought of creating all zero purchases for each clickout and maybe repurchase using the same transaction ID. This might work, but we will end up with thousands of empty purchases.
I ran across a similar problem a while back. Our checkout lives on a different domain. So when Adwords people would checkout after migrating to Universal, I was losing that data at checkout. I think my solution there could help you. This all assumed you're using Universal Analytics and not the old deprecated libraries.
The first thing I do is grab the GA cookie, which is named _ga. Inside it is your GA session. It looks like this (it will be much longer)
GA1.2.3456.7890
The third and fourth number sets (including the period) are the session itself. Parse them out.
Now you want to find some way to store this with the user. I used my PHP session (we pass it in the query string when we jump domains) and stored it there. You'll have to figure something out that works for you here.
On the other site we need to specify the GA session and site within the GA block. Please note that the new site will report these visits as if they belonged to the original site. The UA-XXXX-Y should be from the original site and yourdomain.com should be the new site TLD
ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'yourdomain.com', 'clientId': '3456.7890' });
Now you can pass your purchase metrics in. When a session converts on the new site, the old site will track it, along with any other things that session held (i.e. page impressions, Adwords clicks, etc.). You don't need any messy cron jobs to do this. Just be aware, as I said earlier, that these page visits belong to the original site as far as GA goes. You could try reporting two sets of metrics to get around this, but I have not tried that.
Reading the comment beneath the answer from Machavity, i assume that you are using Universal Analytics, or else Universal Analytics is the way to go!
I have had a case in the past where we had to think of a one way tracking system because we didn't have access to the other site's code.
Give a look at the Google Measurement protocol. This protocol makes it possible to send raw userdata directly to google analytics over HTTP.
Link to Google measurement protocol

Google Analytics not tracking clientside redirects

I'm trying to solve a problem with tracking traffic to individual blog posts on a system that uses a javascript redirect system where something somehow break tracking.
The way the system works is as follows:
Permalinks are in the format of domain.com/ab_XXXXXX where ab_XXXXXX is a unique code. That code is parsed by a piece of javascript, which tells the browser to load the individual blog post page. This page has a URL format of blog.html/?cd_XXXXXX_ef=YYYYYY. Here too, XXXXXX and YYYYYY are unique codes which, combined, identify the particular page.
When I load the blog.html/?cd_XXXXXX_ef=YYYYYY URL directly, Google Analytics does seem to track the page and the user shows up in the real-time dashboard as visiting that particular page.
However, when I load the domain.com/ab_XXXXXX URL, the user does not show up in Analytics' real time dashboard, even though the analytics tracking gif gets loaded.
Since the ab_XXXXXX URL is the permalink, Analytics appears to contain no data on individual blog post visits at all.
I'm not the programmer on this system, and at this point I'm not sure what to test or to suggest as changes to the programmers.
My question is: why would Analytics track the user in the one occasion, but not in the other? And what could be done to remedy this?
Does the page ab_XXXXXX actually redirect the user to cd_XXXXXX_ef=YYYYYY or does it simply load the contents of that blog post into the same page? In either case, but particularly the latter, you can simply choose to manually track the page view in your existing Javascript snipped by adding something along the lines of _gaq.push(['_trackPageview', 'blog.html/?cd_XXXXXX_ef=YYYYYY']);

What does Google Analytics use to keep track of user activity?

just wondering if anyone knows what technologies are used by the tracking software?
Edit: I meant client-side. How is data sent to the Google API? Long polling? Streaming? =)
Thanks guys!
The tracking is at function-calling time. No long polling or streaming.
Every time a Google Analytics function is triggered (whether upon page load, or when a page event like onClick is triggered), it executes a function within the ga.js file. Commonly, that could be trackPageView, but there are many others, as you can see here: http://code.google.com/apis/analytics/docs/tracking/asyncUsageGuide.html .
That function mainly does two things:
It also places numerous first-party
cookies on the end-users computer, if
allowed, in order to enable tracking
beyond a single page.
It requests a blank image file called
_utm.gif from google-analytics.com, with a long query string attached it. That query string contains all of the details that Google Analytics tracks.
Google's servers record that gif request on their logs, which are then processed on Google's side; the lag for the data appearing in GA can be anywhere between 3 and 24 hours, depending on what is being tracked or computed.
That query string contains various parameters that together are put together by Google to create an accurate picture of the visitor's journey
Here's a reference as to what parameters Google Analytics collects:
http://code.google.com/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters
The _utm.gif call for loading talkingpointsmemo.com, for example, looks like this:
http://www.google-analytics.com/__utm.gif?utmwv=4.7.2&utmn=1687340155&utmhn=www.talkingpointsmemo.com&utmcs=UTF-8&utmsr=1920x1080&utmsc=24-bit&utmul=en-us&utmje=1&utmfl=10.1%20r53&utmdt=Talking%20Points%20Memo%20%7C%20Breaking%20News%20and%20Analysis&utmhid=1157392983&utmr=-&utmp=%2F&utmac=UA-927537-1&utmcc=__utma%3D147706162.633472310.1273842954.1279564084.1279662542.44%3B%2B__utmz%3D147706162.1279564457.43.23.utmcsr%3Dgoogle%7Cutmccn%3D(organic)%7Cutmcmd%3Dorganic%7Cutmctr%3Degypt%2520IGLHRC%3B
On any given page load, there could be multiple _utm.gif requests made, 1 for each type of request made.
On client side: JavaScript and a tracking image.
On server side: I don't know.
Well, they have this honking big database called DataStore, of their own design. It's not just there for Google App Engine, they use it internally too. They even store their Web crawling results in it.
Essentially, most Google data ends up in (an internal partition of) DataStore.
EDIT: Oops, I just realized this doesn't answer the question. I thought I'd read "where to they store the data?" I'll leave it up, though, in case anyone is interested.

Categories