How do I insert Piwik CustomDimensions in the Moodle plugin (local Google Analytics)?

How do I insert Piwik CustomDimensions in the Moodle plugin (local Google Analytics)?

by Rolf Cper -
Number of replies: 0

Hello,

Since the Piwik forums are managed badly, I pose this question in this Moodle forum.
I use the local-plugin in Moodle 3.0 which was originally developed for Google Analytics (GA).
I use this for both GA and Piwik web-analysis tool of visitors.
I have adapted the code on PHP level (/local/analytics/guniversal.php) so this plugin simultaneously serves both GA and Piwik with data for statistical analysis.
Both analysis tools can process correctly the standard Javascript-presentation of data.
But I want to do more, that is: use Custom Dimensions that should technically be possible in GA as well as in Piwik.
In Moodle Administration (Site Administration / ► Plugins / ► Local plugins / ► Analytics) I chose GA, and "underwater" both code-blocks for GA and Piwik appear at the same time in the footer of each Moodle page.
In guniversal.php I have figured out how to give the aliases of the course-students to GA (through self-made PHP-variable ".$userData.").
The data of $userData shows up fine in GA statistics overview (not via custom variable).
I also want to give the same data ($userData) to Piwik using a Custom Dimension (or the older Piwik-version: Custom Variable).
The tutorial and FAQ of Piwik are very unclear herein, as they describe on multiple pages differently the exact wording of the required line of code. What is the correct/exact formulation of the algorithm?
This way I cannot get the code to work properly (partly because Piwik is very slow and it takes a long time before I would get to see any test-result of my code changes in Piwik reports).
Below are some examples I tried to implement. Does anyone know what the correct Javascript code should be, either for CustomDimension or for CustomVariable?
---------
...
//Rges 22feb17: 2 methods: a) CustomDimension en b) CustomVariable.
  //a) new method: What is the correct notation?
  setCustomDimension(1, '".$userData."');
  _paq.push(['setCustomDimension', 'customDimensionId = 1', 'customDimensionValue = ".$userData."']);
  _paq.push(['setCustomDimension', 'customDimensionId:1', 'customDimensionValue:".$userData."']);
  _paq.push(['setCustomDimension', 1, '".$userData."']);

 
  //b) old method: What is the proper formulation?
  setCustomVariable('id:1', 'name':'CperUserData', 'value':'".$userData."', 'scope':'visit' );
  _paq.push([setCustomVariable('id:1', 'name':'CperUserData', 'value':'".$userData."', 'scope':'visit' );
  _paq.push([setCustomVariable('2', 'CperUserData', '".$userData."', 'visit' );
  _paq.push(['setCustomVariable', 3,'CperUserData','".$userData."', 'visit']);
     
  _paq.push(['setDocumentTitle', document.domain + '/' + document.title]);
  _paq.push(['setCookieDomain', '*.www.cper.org']);
  // accurately measure the time spent on the last pageview of a visit: enableHeartBeatTimer
  _paq.push(['enableHeartBeatTimer']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
etc.
---------

Thanking you in advance for your effort and advice, I remain.
Sincerely,
Rolf Snijders

Moodle 3.0 on WIMP platform
Piwik 3.0.1 on WIMP
PHP v.5.6.0
MySQL Server 5.5.4

Average of ratings: -