SUNScholar/Google/Analytics/External

BACK TO GOOGLE ANALYTICS

Step 1 - Create GA account

 * 1) Logon to the Google Developers Console https://console.developers.google.com/project with whatever email address you use to access/manage your existing Google Analytics account(s).
 * 2) Create a new Google Project. The assumption is that you are developing some new software and will make use of the Google code repository. This is not the case but you need to create the skeleton project before you can proceed to the next step.
 * 3) Enable the Analytics API for the project. In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure the status is ON for the Analytics API.
 * 4) In the sidebar on the left, select Credentials.
 * 5) Select OAuth / Create new Client ID, then in the subsequent popup screen select Service account. This will automatically generate the required Service Account email address and certificate.
 * 6) Go to your Google Analytics dashboard http://www.google.com/analytics/. Create an account for the newly generated Service Account email address and give it permission to 'Read and Analyze' at account level. See *Note below.
 * 7) Download the P12 key file, and place it somewhere that your DSpace application can access and be referenced as described below in the configuration section. The preferred download folder is: /home/dspace


 * Note:- The Google documentation specifies that the Service Account email address should only require 'Read and Analyze' permission to this specific Property, it does not need permissions to your Account level Google Analytics.





Select P12.

Step 2 - Enable update of GA data
Edit the following file: nano $HOME//dspace/config/dspace.cfg Search for the following: xmlui.google.analytics.key Enter your google analytics key.

See example below. xmlui.google.analytics.key=UA-13284371-1
 * 1) If you would like to use Google Analytics to track general website statistics then
 * 2) use the following parameter to provide your Analytics key. First sign up for an
 * 3) account at http://analytics.google.com, then create an entry for your repository
 * 4) website. Analytics will give you a snipet of JavaScript code to place on your site,
 * 5) inside that snipet is your Google Analytics key usually found in this line:
 * 6) _uacct = "UA-XXXXXXX-X"
 * 7) Take this key (just the UA-XXXXXX-X part) and place it here in this parameter.

Alternative Using Piwik (Optional)
An alternative is to use your own Piwik statistics server. See: http://piwik.org.

Our campus server is available at: http://piwik.sun.ac.za.

The administrator setup an account for us and added http://scholar.sun.ac.za as a service.


 * Please note
 * 1) Google analytics must be enabled in the dspace.cfg file. Just use a fictitious code number.
 * 2) You must comment out the google analytics JavaScript code in the file and paste in the Piwik JavaScript code in it's place.

We were sent the following javascript code snippet and added/merged it into the following XSL stylesheet file: page-structure.xsl

  var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.sun.ac.za/" : "http://piwik.sun.ac.za/"); document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));   try {  var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 3);  piwikTracker.trackPageView;</xsl:text> piwikTracker.enableLinkTracking;</xsl:text>  }    	catch( err ) { }	      </xsl:text> </xsl:if>