Well I have been looking to use this module but concerned that if google analytics goes down my site will not load because this mod includes everything at the top. Google actually tells you to include the code at the bottom of the page just before the </body> tag to avoid this issue. So I have come up with a hack to include the code at the bottom. Here it is:
First we need to move files around a bit so they will not load at the top but at the bottom.
1. Create a new folder in includes/templates/yourtemplate named 'bottom_jscript'
2. Now move 'jscript_google_analytics.php' to the new folder
3. Create a new folder in includes/modules/pages/checkout_success named 'google_analytics'
4. Move 'jscript_google_analytics.php' and 'on_load_google_analytics.js' to this new folder.
Ok now we have our files in the new folders lets move to the hack.
5. We will add the code below to includes/templates/yourtemplate/common/tpl_main_page.php at the very bottom just before the body tag as instructed by google - and yes I would jump off a bridge if google said too....
PHP Code:
/** Google Analytics Main Code include
* load all site-wide bottom jscript_*.php files from includes/templates/YOURTEMPLATE/bottom_jscript/, alphabetically
*/
$directory_array = $template->get_template_part($template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'bottom_jscript'), '/^jscript_/', '.php');
while(list ($key, $value) = each($directory_array)) {
/**
* include content from all site-wide bottom jscript_*.php files from includes/templates/YOURTEMPLATE/jscript, alphabetically.
* These .PHP files can be manipulated by PHP when they're called, and are copied in-full to the browser page
*/
require($template->get_template_dir('.php',DIR_WS_TEMPLATE, $current_page_base,'bottom_jscript') . '/' . $value); echo "\n";
}
//check to see if current page is checkout_success and include google analytics for order if it is
if($page_directory == 'includes/modules/pages/checkout_success')
{
/**
* load all google_analytics-specific jscript_*.js files from includes/modules/pages/PAGENAME/google_analytics, alphabetically
*/
$directory_array = $template->get_template_part($page_directory . 'google_analytics', '/^jscript_/', '.js');
while(list ($key, $value) = each($directory_array)) {
echo '<script type="text/javascript" src="' . $page_directory . 'google_analytics' . '/' . $value . '"></script>' . "\n";
}
/**
* include content from all google_analytics-specific jscript_*.php files from includes/modules/pages/PAGENAME/google_analytics, alphabetically.
*/
$directory_array = $template->get_template_part($page_directory . '/google_analytics', '/^jscript_/');
while(list ($key, $value) = each($directory_array)) {
/**
* include content from all google_analytics-specific jscript_*.php files from includes/modules/pages/PAGENAME, alphabetically.
* These .PHP files can be manipulated by PHP when they're called, and are copied in-full to the browser page
*/
require($page_directory . '/google_analytics' . '/' . $value); echo "\n";
}
}
That is it now the code will be included on each page and the cart contents will be included at checkout success, had to use a simple check to avoid running code for every page as it is not needed.
I will be testing this but works so far let me know if you have any thoughts.