Product Development January 15, 2020

Is this crazy? Hit counter pulling from Google Analytics

Michael Lynch @mtlynch

I'm building an event aggregator for live comedy shows. I want to convince event organizers that there's value in posting their event on my site, so one of the ways I'm considering is displaying pageviews and other analytics on their event pages so that they can see people are coming to my site to view their events. Indie Hackers used to do this, and you can stil see it on old articles (edit: they still do! It looks like it's only visible to the thread-starter).

Google Analytics already has all of my site's traffic data, and they offer an API through which I can pull this data and display it to users in my web app (I'm pretty sure).

My hesitation is that I've searched online, and I can't find examples of anyone else doing this. From skimming their API docs, I imagine I could implement it in a day or two, but whenever I find myself doing something that nobody else is doing, I wonder why. In this case, I can't figure out why nobody else is doing this.

The alternative is to roll my own hit counter, where I have to worry about de-duping, filtering bot traffic, honoring data privacy laws, etc. There are also hit counting services and libraries, but why do that when Google Analytics already has all the data?

Is using Google Analytics in this way a bad idea for reasons I'm not seeing? To be clear, I'm not proposing I build a business selling GA-based hit counters, just whether it's sensible to build this for my site.

Update (2020-01-20): I did it and it seems to work fine:

  1. 2

    If I were you I'd just do it manually and put a caveat "Hit counter may not be 100% accurate. Search engine spiders, computer scripts, and constant refreshes may boost this number". Most people will be fine with that and it'll save you hours of time for a feature that you aren't sure is that important.

    1. 1

      Manually's pretty tough because I have ~100 pages at this point. Copy/pasting 100 numbers from Google Analytics would take a while and be not that fun.

      I played around with the Google Analytics API, and it's not that difficult to pull in page view metrics. It seems like something that might be doable with 5-10 dev hours.

      1. 1

        Sorry I guess manually was the wrong word to use. I meant to roll your own via server side tracking

  2. 2

    It's not crazy at all!
    Just take a look at, for example this website, which is a static website and still displays pageviews for the articles. I think if you just look around at static websites, plenty of them use the exact same approach.

    1. 1

      Thanks! My question isn't so much about the idea of displaying pageviews as it is about pulling the data from Google Analytics in particular. Are other sites doing that?

      1. 1

        I see! Well, the link I provided shows for sure people pulls data from Google analytics. If you are trying to convince event managers to use your system, I think is the best approach by far.

        It will take no time to deploy and then you'll see whether the metrics you display are the ones your customers want to see. This is an assumption on your side, and will need to validate it as quickly and as cheaply as you can.

        Later you'll have time to figure out whether your own stats are worth it. Also, consider Matomo instead of Google Analytics, much more privacy friendly.

  3. 2

    Keep in mind that most (if not all) ad blockers block Google Analytics. Depending on how your project is built and hosted, you could get more accurate page view numbers by logging the analytics at the server level.

    1. 1

      I don't mind losing numbers on ad-blocker users. I've done analytics before by scraping my server logs, and it's just a pain because there's so much garbage traffic mixed in (web vulnerability scanners, people reloading a lot). I feel like with the time I spend post-processing it, I might as well learn to pull from GA, who's already post-processed it.

  4. 2

    How are you going to pull in and display the data? Off the top of my head, you'll need to consider that the Google Analytics API has daily quotas (so you'll need caching), it's not real-time and there's limits to how long it keeps data. It's more intended for building reports rather than as a user visible hit counter as far as I can see.

    Maybe useful for ideas and understanding things to watch out for:
    https://developers.google.com/analytics/solutions/google-analytics-super-proxy

    1. 1

      How are you going to pull in and display the data? Off the top of my head, you'll need to consider that the Google Analytics API has daily quotas (so you'll need caching),

      Right, good point. I was thinking just a scheduled task that runs every X hours to update a local cache. I'm still in O(dozens) of pages, so I don't think I'll run up against quotas too soon.

      it's not real-time and there's limits to how long it keeps data. It's more intended for building reports rather than as a user visible hit counter as far as I can see.

      Yeah, all the API documentation I've read is framed around building admin reports. Non-real time data is fine for my use-case as long as it's current to within a few hours.

      I wasn't aware of limits on retention. Are there limits? Google Analytics has data for one of my old blogs going back to 2011: https://imgur.com/kHnf7jg

Recommended Posts