How to setup visitor variables in Google Analytics - javascript

I don't quite get how to use the visitor level variables. Do I need to put them in some sort of condition to determine if the visitor is a repeat visitor, or do I just use the _SetCustomVar method like I would the page or session variables?

Google Analytics will determine if someone is the same visitor based on the presence of its cookies. So, to the extent that GA is able to differentiate Visitors (ie, same computer, same browser as past visits without having removed cookies), the custom variable will persist.
All you need to do to set a variable as 'visitor' is to set the fourth parameter (scope) to 1.
Just be sure to set the custom variable before your page-view call, otherwise the custom variable data doesn't get sent to Google.

Related

Read all cookies in GTM template without knowing specific cookie names (using sandboxed JS)

My website refers traffic to ecom site's product pages and uses a GTM tag to create a 1st party cookie recording the visit. The cookie name is something like visit_[product sku] e.g. visit_12789723.
I'm creating another GTM template which ecom sites will add as a tag to their sale completion page e.g. when conversion occurs.
At the point of sales conversion I need to read all cookies created when product pages were visited e.g. "visit_*". The sandboxed JS provides an API to read cookies - getCookieValues. The problem is getCookieValues requires that you pass in the name of the cookie and it passes back the value.
Is there a way to get all cookies or to use wildcards with the available GTM js API?
If you are okay with obeying the words of the law rather than the spirit, you can create a Javascript variable "document.cookie" and pass the in via a field to your template. Then you can do some custom parsing to get the individual names and values.

Rails google analytics measuring customer retention

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.

Authenticate websites that are using my service through iframe

I have a service that I provide to different websites. For the website to use the service they implement a javascript that triggers a lightbox with a iframe in it.
The problem is I don't want any website to be able to use the service/iframe. Is there any way I can authenticate the websites using the iframe?
The way I see it, a random website can just take the javascript from a website using the service/iframe and implement it on it's own website.
Authenticating the actual users inside the iframe is no problem, there will be a login form and a register form. It's just the websites using the iframe I want to identify and authenticate.
Any suggestions is appriciated!
You could check document.referrer in JavaScript, and if the referring domain is not within a whitelist you provide (or the referrer is empty), don't display content at all.
But we all know how unreliable the referrer is, and it might exclude users even under wrong conditions.
Another way would only work it the sites embedding your iframe have server-side scripting and so can calculate some kind of hash - f.e. the hash of the current date and a secret keyword - and pass it as a GET parameter in your iframe URL. In your script, you check if the given value is the same as the hash you create with the same data - and display content based on that or not.
Using the current date could be problematic though if time zone settings for your server and the other site are different, and it might also break when a user calls the page around midnight. To prevent such problems, you could have the remote sites include the unix timestamp value used to create the hash as GET parameter as well - then you can check if that timestamp is not to old, and create the hash with that exact value. (Then other sites might try to just copy the parameters and use them on their page as well, but it will only work for a small time window.)

How does Google Analytics tag users in Custom Variables?

We have an page that is shown inside a software tool we have. It's a sort of "starterpage" that shows up when you start it. Our software is available as Free, Pro, and Trial.
I have set up my tracking so that people who visit this page are tagged as a "Free user" or a "Pro user" using custom variables.
I then segment my visitors in GA to show only, for example, "Free users" to see how many of these later go on and purchase the Pro-version (using a regular Goal).
The software leverages a specific browser, called the JXBrowser, and the purchase is done through the regular webpage visited through another browser (like Firefox or Chrome). I want to know how Analytics saves the tag of the user. Does it tag the IP address visiting the software starterpage or does it save it in some sort of cookie.
I'm asking because I want to know how accurate the data I'm seeing is. I am seeing that the tagging is working and that the goal completion for that usergroup is working as well. The goal completions is somewhat low though, which is why I want to make sure that isn't becuase of some technical difficulty.
TL;DR; Is Custom Variables tagging users IP as certain visitor-groups or are they saving the data in a cookie? How does Custom Variables work in cross-browser situations?
Custom variables available in Google Analytics ga.js library have a scope that defines whether they are attached to a pageview, visit or visitor. From your question, I would assume that you are using a visitor-level scope.
_gaq.push(['_setCustomVar',
1, // This custom var is set to slot #1. Required parameter.
'Software Version', // The name acts as a kind of category for the user activity. Required parameter.
'Free', // This value of the custom variable. Required parameter.
3 // Sets the scope to visitor-level. Optional parameter.
]);
Visitor-level custom variables do indeed use a cookie to persist the value (the cookie name is __utmv).
On a side-note, GA also uses cookies for measuring unique visitors and many other things like session start / end, number of visits. This means that a user using multiple browsers will not be seen as one users, but as many users as there are different browsers (based on cookie sets).
It's worth pointing out that Google Analytics offers another collection libary designed to make tracking across browsers and devices easier, the analytics.js library. In your case, if all users are registered or have a unique 'install id' you might be better off disabling cookies storage and using your own id for the cookie - a feature available in the analytics.js library.

Counting page visits with javascript and cookies

I would like to count a users visit to a site within a session and implement certain functionality based on how many pages the user has visited. I would like to perform this solely with the use of JavaScript and cookies (using js).
Essentially I would just like to do create var = 0 and ++ to that same var on each additional visit to another page within that users session.
What is the proper way to implement this?
The only reliable way will be to use AJAX and keep track on the server, associated with the user's session ID.
Each load will need to poll the server, then tell the server to increment the counter.
You could for example, when the user access the page, First check if the cookie exists, if not then set the cookie name and value and also a (token var) as being set so it dosnt increment on page refreshes.
Then one every other page you require the cookie, again check for cookie and then increment it.
I find a easy to use coolkie script Cookies use.

Categories