I already use Piwik's custom variables in Moodle, to track the most popular courses and the most active usernames.
I did this by editing my theme's files, rather than by using the 'extra html' interface. This works for us, because we force our users to use one theme (plus a few accessible variations).
Here's an example. We're storing the username in custom variable 1, or 'Not logged in' if they're not logged in. We're storing the course the user is currently looking at in custom variable 2.
<script type="text/javascript">
Your script that actually includes Piwik will be here.
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.disableCookies();
<?php if(isset($USER->username)) { ?>
piwikTracker.setCustomVariable(1,"Username","<?php echo $USER->username; ?>", "visit");
<?php } else { ?>
piwikTracker.setCustomVariable(1,"Username","Not logged in", "visit");
<?php } ?>
<?php if(isset($COURSE->fullname)) { ?>
piwikTracker.setCustomVariable(2,"Course","<?php echo $COURSE->fullname . ' (' . $COURSE->shortname . ')'; ?>", "page");
<?php } ?>
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script>
You'll probably want to put this just before the </body> in your theme layout files, in /theme/theme_name/layout. Pro tip: we have the same footer on all our pages. We have a file called footer-content.php in that folder, then just do include("footer-content.php"); in the right place in each of our /layout files.
The currently logged-in user's settings are stored in a PHP object called $USER. If you want to see what you can grab from that object, you could run var_dump($USER); somewhere subtle.