| Commit | Line | Data |
|---|---|---|
| 0efd556a MC |
1 | <?php |
| 2 | /* Drupal Module: GoogleAnalytics | |
| 3 | * Adds the required Javascript to the top of all your Drupal pages | |
| 4 | * to allow tracking by the Google Analytics statistics package. | |
| 5 | * | |
| 6 | * @author: Mike Carter <mike@ixis.co.uk> | |
| 7 | */ | |
| 8 | ||
| 9 | /** | |
| 10 | * Implementation of hook_help(). | |
| 11 | */ | |
| 12 | function googleanalytics_help($section) { | |
| 13 | switch ($section) { | |
| 14 | case 'admin/modules#description': | |
| 15 | return t('Adds tracking code to all pages of your site'); | |
| 16 | case 'admin/settings/googleanalytics': | |
| 17 | return t('Google Analytics is a free statistics package based on the excellent Urchin system.'); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 21 | function googleanalytics_menu($may_cache) { | |
| 22 | if(!$may_cache) { | |
| 23 | $id = variable_get('googleanalytics_account', ''); | |
| 24 | ||
| 25 | if($id != '') { | |
| 26 | $output = '<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script> | |
| 27 | <script type="text/javascript"> | |
| 28 | _uacct = "'.$id.'"; | |
| 29 | urchinTracker(); | |
| 30 | </script>'; | |
| 31 | ||
| 32 | drupal_set_html_head($output); | |
| 33 | } | |
| 34 | } | |
| 35 | } | |
| 36 | ||
| 37 | ||
| 38 | /** | |
| 39 | * Implementation of hook_settings(). | |
| 40 | */ | |
| 41 | function googleanalytics_settings() { | |
| 42 | $output = form_group(t('Analytics Account Settings'), | |
| 43 | form_textfield(t('User ID'), 'googleanalytics_account',variable_get('googleanalytics_account',''),15,20,t('The user account is unique to the websites domain. You can obtain a user account from the %url website.', array('%url' => '<a href="http://www.google.com/analytics/">Google Analytics</a>') )) | |
| 44 | ); | |
| 45 | return $output; | |
| 46 | } | |
| 47 | ?> |