user7289
user7289

Reputation: 34338

Getting stats about a page on my site and links on that page from the Google API

I have a blog with the Google Analytics tag in the various pages. I also have links on my site pointing to pages on my site as well as external pages. I have not set up custom events or anything like that.

For a given url/page on my site, within a certain date range, I want to programatically get (ideally from the GA API):

  1. Search words/traffic sources that unique users/traffic from outside my website (e.g. organic traffic searching on Google) used to land on and view that page

  2. For specific links on that page - both internal and external - I want to know the number of unique users who clicked on the link and the number of clicks

  3. For specific links on that page - both internal and external - I want to know the search terms/sources of the users/clicks of the links vs. the visitors that didn't click on the links

Is there a way I can fire a given link on my blog into the Google Analytics API to get this data? I already have a 2-column table that has all of the pages on my site (column 1) and all of the links/urls on those pages (column 2).

I am using Python for all of this btw.

Thanks in advance for any help!

Upvotes: 0

Views: 267

Answers (1)

Max
Max

Reputation: 13334

Regarding the information you're looking for:

  1. You won't get organic keywords via the GA API: what you will get most of the time is (not provided) (here is some info and workarounds). You can get this data in the GA UI by linking the search console, but that data won't be exposed via the GA API, only the Search Console API (formerly "webmasters"), which unfortunately you won't be able to link with your GA data.
  2. You will need to implement custom events if you want to track link clicks, as by default GA doesn't do it (here is an example which you can use for both internal and external links). Once you have the events implemented, you can use the ga:eventAction or ga:eventLabel to filter on your links (depending on how you implemented the events), and ga:totalEvents / ga:uniqueEvents to get the total / unique number of clicks.
  3. You will need to create segments in order to define conditions about what users did or did not do. What I advise you to do is to create and test your segments via the UI to make sure they're correct, then simply refer to the segments via ID using the API.

As for the GA API implementation, before coding I advise you to get familiar with the API using:

Once you get the results you're looking for, you can automate with the Google Python Client (it's the same client for (nearly) all Google APIs), GA being a service you use with the client, and you'll find some python samples here.

Upvotes: 1

Related Questions