Use hook_menu, hook_footer, and support A/B test
| Project: | Google Website Optimizer |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Thanks for putting together this module! I had a couple of issues with it on my site and a couple of ideas for potentially improving it. Sorry to post this all in one patch, but hopefully it's still readable:
1) I switched from using hook_init to using hook_menu and hook_footer to get the javascript on the page. I believe this will allow the module to work better on sites that use page caching, without introducing any problems. The problem with using hook_init, is that it is called on every page load and when caching is enabled this hurts performance and can cause problems. Adding common.inc is not a great solution, I don't think, because this can cause problems for other modules (it caused devel to WSOD my site because devel was expecting a function that didn't exist yet). drupal_bootsrap(FULL) would be the traditional solution, but would hurt performance.
Moving to hook_menu and hook_footer lets the added tracking scripts be cached along with the rest of the page, so I think that's probably the best solution. It's not dynamic content, so it's a good candidate for caching, as long as you clear your cache after making changes.
2) I also switched from using drupal_add_js to avoid the "hack" of closing and re-opening tags. Using drupal_set_html_head and hook_footer seemed cleaner to me.
3) I added an optional field "control_page_path". If that field is entered, the test will be run as an A/B test, otherwise the previous behavior should remain.
I hope this is useful! Thanks again,
Chad
| Attachment | Size |
|---|---|
| google_website_optimizer-newhooks.patch | 6.12 KB |

#1
Sorry, I forgot to include the install file patch. Attached here.