I need to enable the tracking of site searches in Drupal 7 using Google Analytics without installing the additional "google_analytics" module.

So far, I find some info (some previous question in this site, in example) about performing this task using that module, I just want to know if I can do that without it?

(Edited to add.) I found some info regading the "query parameter" to set in the GA site. I found it is recommended (http://www.wesjones.net/home/2010/11/track-drupal-site-search-in-google-analytics) to use "search" as query parameter, but I was thinking that the parameters would be something like "search/node" and "search/user". Any ideas D7-related?

(Edited to add.) I select the first reply as it effectively solves my initial question. Later I added a second one but it is kind of a different one. And maybe it is valuable to not mix things up.

  • 1
    Yes you can. But doing it without modules is Drupal independent, html / js problem. – Mołot Jun 6 '13 at 14:22
  • thanks Molot, I understand the point and that really is an advantage of doing it using the module :) – versvs Jun 6 '13 at 14:27
  • @Mołot Yes, adding GA to a Drupal site w/o the standard module is a simple HTML task. However, how to do this properly in a Drupal site makes it on topic. – mpdonadio Jun 6 '13 at 15:18
  • MPD, for sure, that's why i voted his comment up, it was useful to keep in mind that aspect :) – versvs Jun 6 '13 at 16:07

I think the module serves well, but if you don't want to use the module for some reason, you can always create a new block and copy/paste the code provided by Google Analytics in there. Make sure you select the Text Format as Full HTML or similar which doesn't strip out <script> tags.

And of course, enable the block and move it to a footer region.

  • Thanks, the thing is that the project already has GA installed (integrated via template), so going back to module just to add the tracking code isnt necessary. But I havent work with that module and i'm not sure if the module is performing additional tuning to get site search tracking to work :) – versvs Jun 6 '13 at 14:26
  • I don't remember about site search tracking exactly, but the module does lots of other things. I think the most important feature of the module would be to allow using tokens as custom variables in GA. If you are already doing this in template, it shouldn't be too hard to replicate most of the features. – hw. Jun 6 '13 at 14:38
  • 1
    Other uses of the module would be to specify roles, pages, etc... where the tracking code should be embedded. Other features are listed on the project page – hw. Jun 6 '13 at 14:40

The only way you can do that without installing the module is to copy the google analytics script into a block and place it at the footer of your site.

  • Thanks 4life, the code is already added, my question is more like "is the module doing some stuff i'm missing or if i already has the code installed it makes no difference? :) – versvs Jun 6 '13 at 14:26
  • @versvs looking at your comment above I'm inclined to think I misunderstood your question. Could you maybe clarify it? GA module pretty much tracks all major events. Search too, unless your implementation somehow got incompatible. – Mołot Jun 6 '13 at 14:30
  • I was setting up "site search" in Analytics site. And I was asked the "query parameter", instinctively I was about to answer "search/node" && "search/user" but some googling made me discover the module and that many people recommends setting this parameter to "search" only, without surnames. – versvs Jun 6 '13 at 14:33

Or if you understand theming, you can copy the script below the footer of your page.tpl.php file. That's assuming every page on the front end of your site uses the same page temmplate file. You would need put this code in every page template file.

Or even better. Make a copy of the html.tpl.php file from the modules/system/ folder and copy that into your theme. Paste the anayltics code above the . Be sure you clear your cash once you are done.

  • Thanks Bobby, the code is installed and it is even filtering admin-role users out :) My question (reformuled, sorry if you read the first version!) is more related to the site search setting up, in which I don't know if the module was configuring something for me automagically (now I understands it doesnt do that, and I'm only looking for confirmation on query parameter to add in GA site :) Thanks again! – versvs Jun 6 '13 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.