Extension:GoogleAnalyticsTopPages

GoogleAnalyticsTopPages provides a parser hook, which adds a list of top pages to the wikipage content. The top pages are retrieved from Google Analytics via the Google Analytics API. You need a Google Service account to use this Extension.

Requirements
This Extension requires the Extension GoogleAPIClient to work.

Configuration
Before you configure the Extension, make sure, you have a Service account and access to the Google Analytics API.

Google service account
The following, simple step-by-step tutorial helps you to setup a service account to use this extension:
 * 1) Open the developer console and login with your Google account
 * 2) Navigate to APIs & auth and click APIs
 * 3) Find Analytics API and activate it (click on off), you need to accept the Terms of Service!
 * 4) Go to Credentials
 * 5) In section OAuth click Create new Client ID
 * 6) As application type choose Service account
 * 7) Click Create Client ID
 * 8) You see a secret key and a download with the certificate will start. Save the certificate on your Computer and note the secret key (don't loose this key!)
 * 9) Save your certificate somewhere on your server, but be sure to not save it somewhere public (e.g. in your wikis root or webservers root path!)
 * 10) Use the data of the new created service account to configure GoogleAnalyticsTopPages

Extension configuration
The extension needs at least the following configuration variables (you see these in your Google Developer Console and Google Analytics account, remove "<" and ">"):

View ID: The View ID is the ID of a View in your Google Analytics Account. Go to Google Analytics, click on Admin and select the view related to your wiki where you want to use GoogleanalyticsTopPages. Click on View Settings and use the number in View ID.

path to your certificate: The absolute path to your certificate file for your service account you created above, e.g..

Usage
The usage of the extension is very simple. It provides a new parser tag to generate a list of top pages:. Simply add this tag to a wiki page and position where you want to show this list and save.

Update data
To update the list of top pages, you need to use the API. The extension introduces a new API modules,, which updates the internal database table. To use it, you have to make a POST request to the API in the following schema:

/api.php?action=googlepagestatsupdate&key=$wgSecretKey&format=json]

$wgSecretKey: You need to add your Secret key (can be found in your ) here (replace  ) to make sure, that the API is only used by authorized applications. To disable this check (and use the API without the Sectret key, which isn't recommended) set the following configuration variable in your :

The result will be (if all is configured correctly):

You can automate the requests to the API using cronjob, e.g. to update the data every day, add the following cronjob: