Skip to content

Instantly share code, notes, and snippets.

@markbirbeck
Created July 17, 2011 15:36
Show Gist options
  • Save markbirbeck/1087698 to your computer and use it in GitHub Desktop.
Save markbirbeck/1087698 to your computer and use it in GitHub Desktop.
Patch for Drupal Google Analytics module based on http://drupal.org/files/issues/push_commands_0.patch
--- googleanalytics.module 2010-09-14 22:52:35.000000000 +0100
+++ googleanalytics.module 2010-09-23 09:44:17.000000000 +0100
@@ -160,6 +160,17 @@ function googleanalytics_footer($main =
$url_custom = '"/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer';
}
+ // hook_googleanalytics_custom_url
+ $url_custom_replace = module_invoke_all('googleanalytics_custom_url');
+ if (!empty($url_custom_replace)) {
+ $url_custom = join(' ', $url_custom_replace);
+ }
+
+ // hook_googleanalytics_push_commands
+ // allow modules to add command arrays via _gaq.push();
+ // see http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gaq.html#_gaq.push
+ $push_commands = module_invoke_all('googleanalytics_push_commands');
+
// Add any custom code snippets if specified.
$codesnippet_before = variable_get('googleanalytics_codesnippet_before', '');
$codesnippet_after = variable_get('googleanalytics_codesnippet_after', '');
@@ -214,6 +225,11 @@ function googleanalytics_footer($main =
if (!empty($codesnippet_before)) {
$script .= $codesnippet_before;
}
+ if (!empty($push_commands)) {
+ foreach ($push_commands as $command) {
+ $script .= "_gaq.push([$command]);";
+ }
+ }
if (!empty($custom_var)) {
$script .= $custom_var;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment