27

I have a couple of Github projects that I want to be able to track the traffic to. I have done this in the past by adding Google Analytics tracking code to each wiki page. However, the Github wiki upgrade in September broke this and I don't seem to be able to add Javascript code to my wiki pages anymore.

A couple of random other points: 1) I'm aware that Github probably blocked JS on the wiki for security reasons. 2) I know Github provides its own very basic traffic graph but I would like all the power of GA.

Is there any way for me to restore Google Analytics tracking to my Github wiki? If not, is there an alternative?

mchr
  • 6,161
  • 6
  • 52
  • 74
  • 1
    If you are here, you might want to have a look at a mroe recent version of this problem: http://stackoverflow.com/questions/17207458/how-to-add-google-analytics-tracking-id-to-github-pages – Ozair Kafray Apr 17 '14 at 09:53
  • 2
    Clarification: @OzairKafray's updated StackOverflow question is for Github Pages *not* for Github wiki pages. – MetaSean Jan 30 '16 at 02:19

6 Answers6

16

Lately, the "Traffic" feature is unavailable. In order not to implement something of your own, I have created githalytics.com which let you "add" google analytics to your github repository. Of course there are limitations and drawbacks as mentioned before. Free free to check

user1561612
  • 161
  • 1
  • 2
  • 1. You create a google analytics account (if not have one already) 2. You visit githalyrics.com 3. Submit your github repository url and your google analytics property ID 4. You get a snippet that you paste in your repositories README file. Then when someone visits your repository this visit is forwarded to google analytics. – user1561612 Aug 05 '12 at 17:52
  • 4
    Sorry I was actually asking how your implementation works. I would be surprised if a JS fragment in a README file is rendered so that it is executed. – mchr Aug 05 '12 at 22:01
  • 1
    I tried this. It does work if you only want to track a single page. It uses a static image url which is hosted on gitalytics.com. I was able to insert the code in my README.md... I suspect I could create several gitalytics accounts for each wiki page and that would also work but I haven't tried that yet. – blak3r Oct 09 '12 at 07:12
  • @user1561612: Does it matter which URL will be specified when creating account on GA? It asks for _Default URL_. I assumed that it should have the same value as _github repository url_ in step 2. – b1r3k Nov 28 '12 at 12:41
  • You may want to include instructions about how to set this service up and an overview about how it's implemented in your answer. Very interesting project! – Steven Wexler Jun 11 '14 at 13:16
  • 5
    Is it dead? Link seems unrelated website. – Ciro Santilli OurBigBook.com Aug 17 '15 at 07:35
16

You could leverage the Google Analytics for Mobile strategy.

The draw backs are that :

  • You would only be able to manually publish static image urls in for each wiki page.
  • You would need to host the Google Analytics for Mobile server-side file on another server. Somewhat negating the whole exercise.
gbakernet
  • 326
  • 2
  • 5
  • This isn't ideal for me but thanks for the suggestion. I'm accepting your answer as the best available. – mchr Dec 16 '10 at 00:00
6

Note that since January 2014, GitHub provides Traffic Analysis with a bit more information, for all pages of your repo (including commit activity, wiki, ...):

"Introducing GitHub Traffic Analytics"

https://f.cloud.github.com/assets/25/1615617/d346d8e4-55fc-11e3-8974-77e411a3435a.png


In 2019, Tim Qian mentions in the comments:

The only problem is it only stores traffics for 14 days.
To resolve it, I made a tool to record it: repo-analytics.github.io.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The only problem is it only stores traffics for 14 days, to resolve it, I made a tool to record it https://repo-analytics.github.io – timqian Oct 16 '19 at 11:50
  • 1
    @TimQian Thank you. I have included your comment in the answer for more visibility. – VonC Oct 16 '19 at 12:10
3

You can either use Github traffic analysis (see VonC answer) or ga-beacon, a project by Ilyah Gregorik.

  • Create a new web property in analytics
  • Bind it to https://ga-beacon.appspot.com/
  • Add this markup to your pages (replace UA-XXXXX-X, your-repo and page-name):

    [![Analytics](https://ga-beacon.appspot.com/UA-XXXXX-X/your-repo/page-name)](https://github.com/igrigorik/ga-beacon)

This will display a badge in your wiki page, but you can also use a single-pixel image.

Nacho Coloma
  • 7,070
  • 2
  • 40
  • 43
  • 1
    Does this still work? At least on the surface GitHub is serving all images from their servers (for privacy reasons) and I don't know if this was always the case. Does GitHub actually (internally) request the remote image for every request or does it cache it? – vossad01 Apr 25 '17 at 00:32
1

The other alternative is to include an external image on each of your wiki pages. Then, track the image download stats.

You could then host the images on an image hosting provider that allows:

  1. Download stats
  2. SSL Support - If you link to an external image that
  3. Hotlinking

I'm still searching for such a image hosting provider which provides all of this. I will post back once I find a suitable one.

i posted my research here: https://stackoverflow.com/questions/12795081/i-want-to-track-page-views-on-my-github-wiki-pages-any-suggestions-for-an-ima?lq=1

Community
  • 1
  • 1
blak3r
  • 16,066
  • 16
  • 78
  • 98
  • 1
    Your research link is broken. – kentcdodds Dec 08 '13 at 15:14
  • @kentcdodds works for me... It was "closed" though so maybe it's not public. Contact me through my website http://www.blakerobertson.com/contact and i'll give it to you. – blak3r Dec 09 '13 at 00:45
1

As an alternative to ghalytics.com, I also came across BitDeli Github Badge: https://github.com/bitdeli/profile-ghbadge

It's pretty much the same thing, except it uses BitDeli as the analytics engine instead of GA.

Both suffer from the same apparent limitation: they can not capture the referrer header, since you need JS to extract that. This means that you cannot do analysis on search keywords, sites that link to you, or social network sources. Which is one of the main uses of GA, in my opinion.

The only workaround I can think of is to create a different landing page for your repo than README.md, and then hope that all your traffic will come through the landing page instead of directly to your repo. This landing page could just be a URL shortener (eg bit.ly) with its own analytics service, or a github-pages site with a GA snippet.

Dergachev
  • 348
  • 3
  • 6