function GoogleAnalyticsBasicTest::testGoogleAnalyticsTrackingCode in Google Analytics 6.3
Same name and namespace in other branches
- 6.4 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsTrackingCode()
- 7.2 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsTrackingCode()
- 7 googleanalytics.test \GoogleAnalyticsBasicTest::testGoogleAnalyticsTrackingCode()
File
- ./
googleanalytics.test, line 103 - Test file for Google Analytics module.
Class
- GoogleAnalyticsBasicTest
- @file Test file for Google Analytics module.
Code
function testGoogleAnalyticsTrackingCode() {
$ua_code = 'UA-123456-2';
variable_set('googleanalytics_account', $ua_code);
// Show tracking code on every page except the listed pages.
variable_set('googleanalytics_visibility', 0);
// Enable tracking code for all user roles.
variable_set('googleanalytics_roles', array());
/* Sample JS code as added to page:
<script type="text/javascript" src="/sites/all/modules/google_analytics/googleanalytics.js?w"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-123456-7']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
*/
// Test whether tracking code uses latest JS.
variable_set('googleanalytics_cache', 0);
$this
->drupalGet('');
$this
->assertRaw('google-analytics.com/ga.js', '[testGoogleAnalyticsTrackingCode]: Latest tracking code used.');
// Test whether the alternate doubleclick library is used
variable_set('googleanalytics_trackdoubleclick', 1);
$this
->drupalGet('');
$this
->assertRaw('stats.g.doubleclick.net/dc.js', '[testGoogleAnalyticsTrackingCode]: Doubleclick tracking code used.');
// Test whether anonymize visitors IP address feature has been enabled.
$this
->drupalGet('');
$this
->assertNoRaw('_gaq.push(["_gat._anonymizeIp"]);', '[testGoogleAnalyticsTrackingCode]: Anonymize visitors IP address not found on frontpage.');
// Enable anonymizing of IP addresses.
variable_set('googleanalytics_tracker_anonymizeip', 1);
$this
->drupalGet('');
$this
->assertRaw('_gaq.push(["_gat._anonymizeIp"]);', '[testGoogleAnalyticsTrackingCode]: Anonymize visitors IP address found on frontpage.');
// Test whether the BEFORE and AFTER code is added to the tracker.
variable_set('googleanalytics_codesnippet_before', '_setDetectFlash(false);');
variable_set('googleanalytics_codesnippet_after', '_gaq.push(["t2._setAccount", "UA-123456-3"]);_gaq.push(["t2._trackPageview"]);');
$this
->drupalGet('');
$this
->assertRaw('_setDetectFlash(false);', '[testGoogleAnalyticsTrackingCode]: Before codesnippet has been found with "Flash" detection disabled.');
$this
->assertRaw('t2._setAccount', '[testGoogleAnalyticsTrackingCode]: After codesnippet with "t2" tracker has been found.');
}