Mastering Unique Visitors in the API

After launching a massive amount of new data through our Data Export API, our developers gave us a lot of great feedback back and support. Thanks! Now we want to show you how to master this data to make better business decisions, starting with the unique visitors metric.

In this blog post, we ask Analytics team members to give us their favorite ways to request and use unique visitor data. Next, we translate that into an API query along with screen shots of how the data looks. Finally, we give you a deep link to the query explorer tool so you can make that same API request with your own data right now. Let’s Go!

(Note: You can do most of these queries using Custom Reports through the Google Analytics web interface.)

Query example #1: Measuring Total Unique Visitors
Before we start using suggested queries, let’s lay the ground work with a very simple query for unique visitors.

https://www.google.com/analytics/feeds/data
?ids=tableId
metrics=ga:visitors
start-date=2011-01-01
end-date=2011-01-31


Here’s a sample screen shot of the results.
Ok, the query above was easy. So maybe we want to know how many of these users are active users. Hetal Thakkar, the engineer who implemented the processing logic for this metric, says it’s easy with the following query:

See your own data in the Query Explorer
*In this query segment, a visitor that visits the site 5 times will only have his/her 4th and 5th sessions included, but not the 1st to 3rd sessions (More documentation on ga:visitCount).

See your own data in the Query Explorer

Query Example #7: Visitor Based Conversion Rate

Avinash Kaushik is the Analytics Evangelist at Google. He has a best selling book about web analytics, and a great use case. Google Analytics uses session-based metrics for most of its performance calculations. For example, conversion rate = conversions / visits. Most unique visitors will not convert every time they come to your site. So sometimes it might be better to calculate conversion rate as conversions / visitors.

https://www.google.com/analytics/feeds/data
?ids=tableId
dimensions=ga:source
metrics=ga:visitors,ga:goalCompletionsAll
filters=ga:medium==organic
sort=-ga:visitors
start-date=2011-01-01
end-date=2011-01-15
max-results=5

Here we look at the top organic search engines, but now let’s request the goalCompletionsAll metric. Of course, you can easily use any of the 20 individual goals, the number of transactions or events, or the total revenue for this calculation if you prefer.

 


See your own data in the Query Explorer

By now you should see you can get unique visitors for almost any dimension in Google Analytics!

Query Example #8: Visitor Loyalty Per Content Section

Patricia Boswell is the lead of our documentation efforts for Google Analytics. Measuring performance of the content that is produced is very important to her. She likes to use the unique visitors metric to report the number of unique visitors who visit a specific content section of the site. She then compares that to the number of unique pageviews to get a sense of how frequently unique visitors are viewing specific set of pages.

https://www.google.com/analytics/feeds/data
?ids=tableId
metrics=ga:visitors,ga:uniquePageviews
filters=ga:pagePath=~product
start-date=2011-01-01
end-date=2011-01-15

Here we apply a filter which uses a regular expression to match any pages that have the word “product” in their URL. Using the advanced segment returns all sessions, which had at least one pageview that included the word “product.” Google Analytics then returns the number of unique visitors for those sessions.





We see here that the pageviews per visitor ratio for the support section is 2.85 (= 342/120).

So while more unique visitors saw the product pages, unique visitors were more engaged on the support section. This might influence your content development strategy by considering cross selling products and services within the content section vs the product section.

See your own data in the Query Explorer