'#description'=>t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, <a href="@analytics">register your site with Google Analytics</a>, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. <a href="@webpropertyid">Find more information in the documentation</a>.',array('@analytics'=>'http://www.google.com/analytics/','@webpropertyid'=>url('https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts',array('fragment'=>'webProperty')))),
'#description'=>t('If you selected "Multiple top-level domains" above, enter all related top-level domains. Add one domain per line. By default, the data in your reports only includes the path and name of the page, and not the domain name. For more information see section <em>Show separate domain names</em> in <a href="@url">Tracking Multiple Domains</a>.',array('@url'=>url('http://support.google.com/analytics/bin/answer.py',array('query'=>array('answer'=>'1034342'))))),
);
// Page specific visibility configurations.
$php_access=user_access('use PHP for tracking visibility');
$description=t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.",array('%blog'=>'blog','%blog-wildcard'=>'blog/*','%front'=>'<front>'));
if(module_exists('php')&&$php_access){
$options[]=t('Pages on which this PHP code returns <code>TRUE</code> (experts only)');
$title=t('Pages or PHP code');
$description.=' '.t('If the PHP option is chosen, enter PHP code between %php. Note that executing incorrect PHP code can break your Drupal site.',array('%php'=>'<?php ?>'));
'#description'=>t('If none of the roles are selected, all users will be tracked. If a user has any of the roles checked, that user will be tracked (or excluded, depending on the setting above).'),
);
// Standard tracking configurations.
$form['tracking']['user_vis_settings']=array(
'#type'=>'fieldset',
'#title'=>t('Users'),
);
$t_permission=array('%permission'=>t('opt-in or out of tracking'));
'#description'=>t('A file extension list separated by the | character that will be tracked as download when clicked. Regular expressions are supported. For example: !extensions',array('!extensions'=>GOOGLEANALYTICS_TRACKFILES_EXTENSIONS)),
'#description'=>t('This will track the selected message types shown to users. Tracking of form validation errors may help you identifying usability issues in your site. For each visit (user session), a maximum of approximately 500 combined GATC requests (both events and page views) can be tracked. Every message is tracked as one individual event. Note that - as the number of events in a session approaches the limit - additional events might not be tracked. Messages from excluded pages cannot tracked.'),
'#options'=>array(
'status'=>t('Status message'),
'warning'=>t('Warning message'),
'error'=>t('Error message'),
),
);
// Google already have many translations, if not - they display a note to change the language.
'#description'=>t('If checked, internal search keywords are tracked. You must configure your Google account to use the internal query parameter <strong>search</strong>. For more information see <a href="@url">Setting Up Site Search for a Profile</a>.',array('@url'=>url('http://support.google.com/analytics/bin/answer.py',array('query'=>array('answer'=>'1012264'))))).$site_search_dependencies,
'#description'=>t('If checked, the alternative Google <a href="@doubleclick">DoubleClick data tracking</a> is used to enable AdWords remarketing features. If you choose this option you will need to <a href="@privacy">update your privacy policy</a>.',array('@doubleclick'=>url('http://support.google.com/analytics/bin/answer.py',array('query'=>array('answer'=>'2444872'))),'@privacy'=>url('http://support.google.com/analytics/bin/answer.py',array('query'=>array('answer'=>'2636405'))))),
'#description'=>t('Tell Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting. In some countries it is not allowed to collect personally identifying information for privacy reasons and this setting may help you to comply with the local laws.'),
'#description'=>t('If enabled and your server receives the <a href="@donottrack">Do-Not-Track</a> header from the client browser, the Google Analytics module will not embed any tracking code into your site. Compliance with Do Not Track could be purely voluntary, enforced by industry self-regulation, or mandated by state or federal law. Please accept your visitors privacy. If they have opt-out from tracking and advertising, you should accept their personal decision. This feature is currently limited to logged in users and disabled page caching.',array('@donottrack'=>'http://donottrack.us/')),
'#description'=>t('You can add Google Analytics <a href="@custom_var_documentation">Custom Variables</a> here. These will be added to every page that Google Analytics tracking code appears on. Google Analytics will only accept custom variables if the <em>name</em> and <em>value</em> combined are less than 128 bytes after URL encoding. Keep the names as short as possible and expect long values to get trimmed. You may use tokens in custom variable names and values. Global and user tokens are always available; on node pages, node tokens are also available.',array('@custom_var_documentation'=>'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables')),
'#description'=>t('You can supplement Google Analytics\' basic IP address tracking of visitors by segmenting users based on custom variables. Section 7 of the <a href="@ga_tos">Google Analytics terms of service</a> requires that You will not (and will not allow any third party to) use the Service to track, collect or upload any data that personally identifies an individual (such as a name, email address or billing information), or other data which can be reasonably linked to such information by Google. You will have and abide by an appropriate Privacy Policy and will comply with all applicable laws and regulations relating to the collection of information from Visitors. You must post a Privacy Policy and that Privacy Policy must provide notice of Your use of cookies that are used to collect traffic data, and You must not circumvent any privacy features (e.g., an opt-out) that are part of the Service.',array('@ga_tos'=>'http://www.google.com/analytics/terms/gb.html')),
'#description'=>t("If checked, the tracking code file is retrieved from Google Analytics and cached locally. It is updated daily from Google's servers to ensure updates to tracking code are reflected in the local copy. Do not activate this until after Google Analytics has confirmed that site tracking is working!"),
'#title'=>t('Track translation sets as one unit'),
'#description'=>t('When a node is part of a translation set, record statistics for the originating node instead. This allows for a translation set to be treated as a single unit.'),
'#description'=>t('You can add custom Google Analytics <a href="@snippets">code snippets</a> here. These will be added every time tracking is in effect. Before you add your custom code, you should read the <a href="@ga_concepts_overview">Google Analytics Tracking Code - Functional Overview</a> and the <a href="@ga_js_api">Google Analytics Tracking API</a> documentation. <strong>Do not include the <script> tags</strong>, and always end your code with a semicolon (;).',array('@snippets'=>'http://drupal.org/node/248699','@ga_concepts_overview'=>'https://developers.google.com/analytics/resources/concepts/gaConceptsTrackingOverview','@ga_js_api'=>'https://developers.google.com/analytics/devguides/collection/gajs/methods/')),
'#description'=>t("Code in this textarea will be added <strong>after</strong> _gaq.push(['_trackPageview']). This is useful if you'd like to track a site in two accounts."),
'#description'=>t('Google recommends adding the external JavaScript files to the header for performance reasons. If <em>Multiple top-level domains</em> has been selected, this setting will be forced to header.'),
form_set_error("googleanalytics_custom_var][slots][".$custom_var['slot']."][name",t('The custom variable @slot-number requires a <em>Name</em> if a <em>Value</em> has been provided.',array('@slot-number'=>$custom_var['slot'])));
form_set_error("googleanalytics_custom_var][slots][".$custom_var['slot']."][value",t('The custom variable @slot-number requires a <em>Value</em> if a <em>Name</em> has been provided.',array('@slot-number'=>$custom_var['slot'])));
form_set_error('googleanalytics_cross_domains',t('A list of top-level domains is required if <em>Multiple top-level domains</em> has been selected.'));
}
// Clear obsolete local cache if cache has been disabled.
form_set_error('googleanalytics_codesnippet_before',t('Do not add the tracker code provided by Google into the javascript code snippets! This module already builds the tracker code based on your Google Analytics account number and settings.'));
form_set_error('googleanalytics_codesnippet_after',t('Do not add the tracker code provided by Google into the javascript code snippets! This module already builds the tracker code based on your Google Analytics account number and settings.'));
form_error($element,t('The %element-title is using the following forbidden tokens with personal identifying information: @invalid-tokens.',array('%element-title'=>$element['#title'],'@invalid-tokens'=>implode(', ',$invalid_tokens))));
'description'=>$t('Google Analytics module has not been configured yet. Please configure its settings from the <a href="@url">Google Analytics settings page</a>.',array('@url'=>url('admin/config/system/googleanalytics'))),
'severity'=>REQUIREMENT_WARNING,
'value'=>$t('Not configured'),
);
}
}
return$requirements;
}
/**
* Upgrade old extension variable to new and use old name as enabled/disabled flag.
drupal_set_message(Database::getConnection()->prefixTables("<strong>Attempted</strong> to upgrade Google Analytics custom 'before' code snippet. Backup of previous code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_before_backup_6300'. Please consult Google's <a href='https://developers.google.com/analytics/devguides/collection/gajs/'>Asynchronous Tracking Usage Guide</a> if the upgrade was successfully."),'warning');
drupal_set_message(Database::getConnection()->prefixTables("Automatic upgrade of Google Analytics custom 'after' code snippet has been skipped. Backup of previous code snippet has been saved in database table '{variable}' as 'googleanalytics_codesnippet_after_backup_6300'. You need to manually upgrade the custom 'after' code snippet."),'error');
$messages[]=t("The D6 token placeholder [user-role-names] used in the custom variable 'User roles' has been replaced with [current-user:role-names].");
}
returnimplode(' ',$messages);
}
/**
* Automatically enable anonymizing of IP addresses for Germany.
*/
functiongoogleanalytics_update_7001(){
// By German law it's always best to enable the anonymizing of IP addresses.
returnt('The default country in your regional settings is Germany. Anonymizing of IP addresses has been enabled for privacy reasons.');
}
else{
returnt('The default country in your regional settings is <em>not</em> Germany. The anonymizing of IP addresses setting has not been changed. Make sure your site settings comply with the local privacy rules.');
}
}
/**
* Upgrade "User roles" tracking to custom variables.
returnt('The deprecated profile segmentation setting for "User roles" has been added to custom variables. You need to deselect all selected profile fields in <a href="@admin">Google Analytics settings</a> and upgrade other profile fields manually or you may loose tracking data in future! See Google Analytics <a href="@customvar">Custom Variables</a> for more information.',array('@customvar'=>'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables','@admin'=>url('admin/config/system/googleanalytics')));
}
else{
returnt('You need to deselect all selected profile fields in <a href="@admin">Google Analytics settings</a> and upgrade other profile fields manually or you may loose tracking data in future! See Google Analytics <a href="@customvar">Custom Variables</a> for more information.',array('@customvar'=>'https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingCustomVariables','@admin'=>url('admin/config/system/googleanalytics')));
}
}
/**
* Rename googleanalytics_trackoutgoing variable to googleanalytics_trackoutbound.
returnt('<a href="@ga_url">Google Analytics</a> is a free (registration required) website traffic and marketing effectiveness service.',array('@ga_url'=>'http://www.google.com/analytics/'));
}
}
/**
* Implements hook_theme().
*/
functiongoogleanalytics_theme(){
returnarray(
'googleanalytics_admin_custom_var_table'=>array(
'render element'=>'form',
),
);
}
/**
* Implements hook_permission().
*/
functiongoogleanalytics_permission(){
returnarray(
'administer google analytics'=>array(
'title'=>t('Administer Google Analytics'),
'description'=>t('Perform maintenance tasks for Google Analytics.'),
),
'opt-in or out of tracking'=>array(
'title'=>t('Opt-in or out of tracking'),
'description'=>t('Allow users to decide if tracking code will be added to pages or not.'),
),
'use PHP for tracking visibility'=>array(
'title'=>t('Use PHP for tracking visibility'),
'description'=>t('Enter PHP code in the field for tracking visibility settings.'),
if($category=='account'&&user_access('opt-in or out of tracking')&&($custom=variable_get('googleanalytics_custom',0))!=0&&_googleanalytics_visibility_roles($account)){
$form['googleanalytics']=array(
'#type'=>'fieldset',
'#title'=>t('Google Analytics configuration'),
'#weight'=>3,
'#collapsible'=>TRUE,
'#tree'=>TRUE
);
switch($custom){
case1:
$description=t('Users are tracked by default, but you are able to opt out.');
break;
case2:
$description=t('Users are <em>not</em> tracked by default, but you are able to opt in.');
break;
}
// Disable tracking for visitors who have opted out from tracking via DNT (Do-Not-Track) header.
$this->assertRaw(t('A valid Google Analytics Web Property ID is case sensitive and formatted like UA-xxxxxxx-yy.'),'[testGoogleAnalyticsConfiguration]: Invalid Web Property ID number validated.');
}
functiontestGoogleAnalyticsPageVisibility(){
$ua_code='UA-123456-1';
variable_set('googleanalytics_account',$ua_code);
// Show tracking on "every page except the listed pages".
// Test whether 403 forbidden tracking code is shown if user has no access.
$this->drupalGet('admin');
$this->assertRaw('/403.html','[testGoogleAnalyticsPageVisibility]: 403 Forbidden tracking code shown if user has no access.');
// Test whether 404 not found tracking code is shown on non-existent pages.
$this->drupalGet($this->randomName(64));
$this->assertRaw('/404.html','[testGoogleAnalyticsPageVisibility]: 404 Not Found tracking code shown on non-existent page.');
// DNT Tests:
// Enable caching of pages for anonymous users.
variable_set('cache',1);
// Test whether DNT headers will fail to disable embedding of tracking code.
$this->drupalGet('',array(),array('DNT: 1'));
$this->assertRaw('_gaq.push(["_trackPageview"]);','[testGoogleAnalyticsDNTVisibility]: DNT header send from client, but page caching is enabled and tracker cannot removed.');
// DNT works only with caching of pages for anonymous users disabled.
variable_set('cache',0);
$this->drupalGet('');
$this->assertRaw('_gaq.push(["_trackPageview"]);','[testGoogleAnalyticsDNTVisibility]: Tracking is enabled without DNT header.');
// Test whether DNT header is able to remove the tracking code.
$this->drupalGet('',array(),array('DNT: 1'));
$this->assertNoRaw('_gaq.push(["_trackPageview"]);','[testGoogleAnalyticsDNTVisibility]: DNT header received from client. Tracking has been disabled by browser.');
// Disable DNT feature and see if tracker is still embedded.
$this->assertRaw('_gaq.push(["_trackPageview"]);','[testGoogleAnalyticsDNTVisibility]: DNT feature is disabled, DNT header from browser has been ignored.');
}
functiontestGoogleAnalyticsTrackingCode(){
$ua_code='UA-123456-2';
variable_set('googleanalytics_account',$ua_code);
// Show tracking code on every page except the listed pages.
$this->assertRaw('_gaq.push(["_setDomainName",','[testGoogleAnalyticsTrackingCode]: One domain with multiple subdomains is active on real host.');
}
else{
// Special cases, Localhost and IP addresses don't show '_setDomainName'.
$this->assertNoRaw('_gaq.push(["_setDomainName",','[testGoogleAnalyticsTrackingCode]: One domain with multiple subdomains may be active on localhost (test result is not reliable).');
$this->assertRaw('_gaq.push(["_setDomainName", "none"]);','[testGoogleAnalyticsTrackingCode]: _setDomainName: "none" found. Cross domain tracking is active.');
$this->assertRaw('_gaq.push(["_setAllowLinker", true]);','[testGoogleAnalyticsTrackingCode]: _setAllowLinker: true found. Cross domain tracking is active.');
$this->assertRaw('"trackCrossDomains":["www.example.com","www.example.net"]','[testGoogleAnalyticsTrackingCode]: Cross domain tracking with www.example.com and www.example.net is active.');
// Test whether the BEFORE and AFTER code is added to the tracker.
$this->assertRaw("_gaq.push(['_setCustomVar', 1, \"Name: $site_slogan\", \"Value: $site_slogan\", 3]",'[testGoogleAnalyticsCustomVariables]: Tokens have been replaced in custom variable.');
$this->assertNoRaw("_gaq.push(['_setCustomVar', 2,",'[testGoogleAnalyticsCustomVariables]: Value with empty name is not shown.');
$this->assertNoRaw("_gaq.push(['_setCustomVar', 3,",'[testGoogleAnalyticsCustomVariables]: Name with empty value is not shown.');
$this->assertNoRaw("_gaq.push(['_setCustomVar', 4,",'[testGoogleAnalyticsCustomVariables]: Empty name and value is not shown.');
$this->assertNoRaw("_gaq.push(['_setCustomVar', 5,",'[testGoogleAnalyticsCustomVariables]: Empty name and value is not shown.');
$this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Username field is required."]);','[testGoogleAnalyticsStatusMessages]: _trackEvent "Username field is required." is shown.');
$this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Password field is required."]);','[testGoogleAnalyticsStatusMessages]: _trackEvent "Password field is required." is shown.');
//drupal_set_message('Example error <em>message</em> with html tags and <a href="http://example.com/">link</a>.', 'error');
//$this->drupalGet('');
//$this->assertNoRaw('_gaq.push(["_trackEvent", "Messages", "Status message", "Example status message."]);', '[testGoogleAnalyticsStatusMessages]: Example status message is not enabled for tracking.');
//$this->assertNoRaw('_gaq.push(["_trackEvent", "Messages", "Warning message", "Example warning message."]);', '[testGoogleAnalyticsStatusMessages]: Example warning message is not enabled for tracking.');
//$this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Example error message."]);', '[testGoogleAnalyticsStatusMessages]: Example error message is shown.');
//$this->assertRaw('_gaq.push(["_trackEvent", "Messages", "Error message", "Example error message with html tags and link."]);', '[testGoogleAnalyticsStatusMessages]: HTML has been stripped successful from Example error message with html tags and link.');
$this->assertRaw($ua_code,'[testGoogleAnalyticsRoleVisibility]: Tracking code is displayed for anonymous users on frontpage with default settings.');
$this->drupalGet('admin');
$this->assertRaw('/403.html','[testGoogleAnalyticsRoleVisibility]: 403 Forbidden tracking code is displayed for anonymous users in admin section with default settings.');
$this->drupalLogin($this->admin_user);
$this->drupalGet('');
$this->assertRaw($ua_code,'[testGoogleAnalyticsRoleVisibility]: Tracking code is displayed for authenticated users on frontpage with default settings.');
$this->drupalGet('admin');
$this->assertNoRaw($ua_code,'[testGoogleAnalyticsRoleVisibility]: Tracking code is NOT displayed for authenticated users in admin section with default settings.');
// Test if the non-default settings are working as expected.
$this->assertRaw($ua_code,'[testGoogleAnalyticsRoleVisibility]: Tracking code is added to every role and displayed for anonymous users.');
$this->drupalGet('admin');
$this->assertRaw('/403.html','[testGoogleAnalyticsRoleVisibility]: 403 Forbidden tracking code is shown for anonymous users if every role except the selected ones is selected.');
$this->drupalLogin($this->admin_user);
$this->drupalGet('');
$this->assertRaw($ua_code,'[testGoogleAnalyticsRoleVisibility]: Tracking code is added to every role and displayed on frontpage for authenticated users.');
$this->drupalGet('admin');
$this->assertNoRaw($ua_code,'[testGoogleAnalyticsRoleVisibility]: Tracking code is added to every role and NOT displayed in admin section for authenticated users.');
* Definition of variables for Variable API module.
*/
/**
* Implements hook_variable_info().
*/
functiongoogleanalytics_variable_info($options){
$variables['googleanalytics_account']=array(
'type'=>'string',
'title'=>t('Web Property ID',array(),$options),
'default'=>'UA-',
'description'=>t('This ID is unique to each site you want to track separately, and is in the form of UA-xxxxxxx-yy. To get a Web Property ID, <a href="@analytics">register your site with Google Analytics</a>, or if you already have registered your site, go to your Google Analytics Settings page to see the ID next to every site profile. <a href="@webpropertyid">Find more information in the documentation</a>.',array('@analytics'=>'http://www.google.com/analytics/','@webpropertyid'=>url('https://developers.google.com/analytics/resources/concepts/gaConceptsAccounts',array('fragment'=>'webProperty'))),$options),