How to integrate the Piwik web statistics tracking system in a Drupal site? Right now, I put the Piwik code at the end of html.tpl.php.

How I can integrate it in a Drupal site, so that this JavaScript can be aggregated? Or better loaded and keep my template clean?

Can I put this code to an external JavaScript file (+ how?) and then just declare it at theme.info?
Even better, use the drupal module that does all the hard work - Piwik Web Analytics.
Here is a quote about it (from the module's project page):

... Adds the Piwik web statistics tracking system to your website.
The module allows you to add the following statistics features to your site:

Single/multi domain tracking
Selectively track/exclude certain users, roles and pages
Monitor what type of links are tracked (downloads, outgoing and mailto)
Monitor what files are downloaded from your pages
Cache the Piwik code on your local server for improved page loading times
Custom variables support with tokens (D7 only)
Custom code snippets
Site Search
Drupal messages tracking
Modal dialog tracking (Colorbox)
Access denied (403) and Page not found (404) tracking
User ID tracking across devices
DoNotTrack support