How to create a module to insert some analytics code in the footer of website pages?
These two links should get you started:

https://www.drupal.org/node/206761

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_page_alter/7