How can I pull data from Google Analytics to see the top pages visited from the current page? - google-analytics

I would like to create a small sidebar on each page of my website that contains related/popular pages with perhaps the top five pages users visit after reading the current page.
I could track and record user movements across the site myself and build the list that way, but as my site already uses Google Analytics and I know the data is there I'd rather access that if all possible.
The trouble is that I don't have the faintest idea whether it is possible or not.

Remember that the Google Analytics Reporting API is not real-time it can take between 24 - 48 hours for the data to finish processing and be in the API for you to request.
The Realtime Google Analytics api is real time but the data is only about 5 minutes old and its very limited to the dimensions and metrics you can request.
Quota, with either of those APIs you are limited to 10,000 requests per day per profile / view. I have no idea how many pages there are on your site or how may users are on your site but this could quickly blow out this NON extendable quota.
Options: Except that its not realtime data and use the reporting api every night run a request against the api get everything for two days ago then show your users on your site data that's two days old. Store the data in the database then you are showing them data on in your DB and wont have an issue with the quota as you only requested it once.
But this isn't exactly what you want as its not showing a users activity over the site. TBH I am not sure you can exactly use Google Analytics to track a user as the data is user non specific.

If you don't want to get involved with learning the API and develop this from the ground up, check out EmbeddedAnalytics (disclaimer: I created the service). We could provide such a widget.
You may find This Article useful. It provides the necessary query to find the "next page visited" using the page of interest as a filter. Ultimately your query would look like this:
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3Aabc&start-date=30daysAgo&end-date=yesterday&metrics=ga%3Apageviews&dimensions=ga%3ApreviousPagePath%2Cga%3AnextPagePath&sort=-ga%3Apageviews&filters=ga%3ApreviousPagePath%3D%40pricing
The query above will give you the "Next Page" along with pageviews assuming the "previous" page contains the word "pricing".
We could easily build such report widget for you:
You would insert a javascript source code snippet into your page. The javascript would pass the page url to our server and we would return the next "most popular pages visited".
The pages could be "linkified" so that someone could click the link to go to that page.
We already have caching mechanism in place. So each pageview would not require a new query to google (making it quicker and also staying away from the API quota that was mentioned above). For pages that are hardly ever looked at (e.g. less than once a week), we could make "on-demand" calls to get the statistics.
In my experience with the API, the lag in the API is only a couple hours. It may be longer for larger sites.
Please let me know if you are interested in such widget and I can work with you.

Related

Is it possible to selectively delete data (specifi page URLs) from Google Analytics?

I'm pretty sure the answer to this question is "no", but I would like to get a definitive answer from an official source, and also understand what my alternative options might be.
Long story short, my app has old data in it that used to include user email addresses as a GET parameter. Those URLs are showing up as unique page view URLs in Google analytics, like this:
I don't want to be recording email addresses in my Google Analytics account (for privacy reasons), and I have fixed the code that was causing this in the first place, but I also want to delete or scrub the old data that currently exists in Google Analytics.
From everything I've read, it doesn't sound like this is possible without completely deleting the property, maybe even the account?
To be clear, I am NOT interested in creating new views that don't include URLs with email parameters in them, or otherwise change the view and not the data. The data needs to be gone and be completely inaccessible to anyone with access to this Google Analytics account.
Here are the options I've come up with:
Delete the property and start over. I'm pretty sure this will
actually delete the collected data, but it's not clear to me if I
would have to actually delete the account itself to achieve that.
Set the data retention time to the lowest possible value (looks like 14 months right now) and wait 14 months for it to go away https://support.google.com/analytics/answer/7667196?hl=en
Perform some kind of magic to get in contact with an actual human at Google who could help me scrub or remove this data.
Does this sound right? Are there options I'm missing? If there's a way to do this through a Google API that would not be a problem.
If this is still a relevant issue. GoogleAnalytics provides a way to delete some data. Universal Analytics https://support.google.com/analytics/answer/9450800?hl=en and GA4 https://support.google.com/analytics/answer/9940393?hl=en&ref_topic=2919631
You are right: changing the data, that you have collected, and Google Analytics have already processed, is not possible. You have the option to make changes during processing with various filters, e.g. Search-and-replace filters, but as it is written in this official support article:
Like all filters, search-and-replace filters only apply to hits
collected after you've applied the filter to the view (filters cannot
change historical data).
Regarding you suggested options:
Deleting a view or property will result in a permanent loss of data after a 35 days period of waiting time. (While this could be undone.) So unless the requirement of scrubbing the collected PII is more important than having your historical data, this should not be a way to go. The same applies to deleting the whole account, so it would be enough to delete affected properties or views.
From the article you have linked as well, you can see, that data retention is about removing user and event level data, and it will not affect the data in aggregated reports. My understanding is, that an already created, page level report will keep showing the page with an email address:
Keep in mind that standard aggregated Google Analytics reporting is
not affected.
I hope these references help you to evaluate your options. Sorry for not being able to come up with a solution, but the basic concept is, as highlighted in this Google article:
Once Analytics processes the data, it’s stored in a database where it can’t be changed

Google Analytics Bloated Data

I manage an internal website and we recently implemented campaign tracking for our emails and homepage links to see where traffic comes from.
I set up the URLs using the Google URL builder.
The data we're receiving is very bloated. We ran a test URL with 8 people, and we received 129 "views", with an average of 9 views per day for over a month. No one clicked this link after the first day.
Our average session times were about 30 minutes, which is very strange.
My questions are:
how does google track campaigns? If you use a tracking URL, does the cookie track views for any organic views after that?
Is there a tool we can use to only track first time visits using a campaign URL?
Admittedly, I'm fairly new to Google Analytics, but no one on our marketing analytics team was able to help.
Since you used the Google URL builder I don't think you have made any mistakes there. However I strongly think that the bloated data is due to Bot traffic in your account. And yes, the bot traffic does increase average session duration.
So here's a set of steps I'll suggest:
1) Create 3 views in Google Analytics (It is a best practice):
Unfiltered, Master, Test
2) Check for Langauage spam and weird referrals in your report.
3) Add filters to "Test" view to remove these bots & spam referrals. You'll need to write a regular expression for each of these filters. Also make sure you have enabled "bot filtering" in view settings for master & test view. (I am leaving Unfiltered view as it is our data backup in case if anything goes wrong.)
4) Check your traffic for next few days and try doing the URL test again and see the results.
5) If the results in Test View are correct, then apply the same filters to "Master" view.
I hope this helps.

enabling hourly data in google analytics

I have two view/profiles linked to my google analytics account. I want to fetch the hourly data for the current day, ie
start date:today
end date: today
with a few filters and dimensions.
Now I am getting the response for one view that means it is possible in google analytics, however for the other view its showing all the values as 0- this applies both to the gui and the api.
Can anyone suggest me how to enable it for the other view as well?
You cannot. Google Analytics needs some processing time. It might be that some data appears immediately, especially on small accounts, but it's not guaranteed and not a thing you can "enable" or count on.
Updated: Okay, that was a dumb answer. Still, there is a processing latency event in GA Premium. It is possible to get realtime data, but that's a different API with limited data (the core reporting API might return data, but no guarantees for that).
But I admit, since your problem is that you do not get data for the whole day yor have a different problem. But with a premium account you should be able to contact your account manager/technical support.

Google Analytics: Report delayed conversion?

We have a site that tracks conversions through Google Analytics for redirects to an affiliate. However, not all redirected visitors convert to a sale after they leave our site. Our affiliate reports back to us weekly on who converted (and we can identify an individual user session from that report). Is there a way to get that conversion data back into Analytics? We've got a great coding team, but I just need to point them in the right direction.
Good question Jeff. If you don't mind the accuracy of the timing being off, your team could certainly just step through your site and intentionally trip the conversions.
Other than that, you may look into using a custom solution to bulk import that data using this type of API: Google Analytics for Mobile Websites
This Google Analytic server-side solution supports PERL, ASP.NET, JSP, and PHP. If you're looking for a repeatable process for batch importing GA data, this maybe a viable solution for you.
Hope this gets you going in the right direction.
I would not recommend manually 'tripping' the conversions.
There is no easy way to get the data back into Analytics. And it would depend on your reporting requirements (time lines, etc)
One way to approach this is to set a custom variable that is scoped to a visitor that would identify the visitor in an anonymous way (not personally identifiable manner, beware the privacy policy).
http://cutroni.com/blog/2011/05/05/merging-google-analytics-with-your-data-warehouse/
So when a visitor comes to the site, a custom variable would get set. This variable acts as a key to associate behavior on the site and the affiliates. Once you receive the data about which visitors converted from your affiliates associated to the non-personally-identifiable ID, you can use this to have code fire some conversion events once it recognizes on a separate visit that a visitor with certain custom variables set using the _getVisitorCustomVar()
http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html

Can Google Analytics do a user's who looked at x also looked at y?

Just wondering if this this possible? I realise you could never use it to display recommendations on a page but it would be useful from an analytics point of view to see for example what other products user's who've looked at product x have also looked at.
You can use Advanced Segmentation to do this.
Advanced Segments slice Google Analytics data on the basis of sessions. Sessions are a collection of pageviews that correspond to the popular notion of a visit.
If you create an Advanced Segment for users who visited /product/x/, it will return data from all the sessions in which that page was viewed. (Similarly, you could create a segment for /product/x AND /product/y. From there, you could filter it to only include your product pages, and exclude the original products themselves.) As a result, this session-based querying is perfect for your use case.
So, yes, you could use Google Analytics API data to inform a simple recommendations engine. The only caveat I'd give is that the Google Analytics API is a little slow, so you'd want to cache the data locally in your app, rather than querying it directly on every pageload.

Resources