How to integrate the Piwik web statistics tracking system in a Drupal site?
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