Active
Project:
Search by Page
Version:
7.x-1.x-dev
Component:
Main Search by Page module
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Nov 2010 at 12:06 UTC
Updated:
24 Sep 2014 at 00:25 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
hass commentedNot sure as I'm not using this module, but I've commented in http://drupal.org/node/488762#comment-1695998 how to solve this problem... This may be of help, too.
Comment #2
jhodgdonhttp://drupal.org/node/488762#comment-1695998 does indeed look helpful. It suggests setting up paths like search/your_search_path, to make the Google Analytics module recognize it as a search.
You can do that in Search by Page also, when you set up your search environment, just like you can in Faceted Search. Of course, if Google Analytics had a flexible way to say "This URL is a search URL", that might also help...
Sounds like a support request, not a bug in Search by Page. Good luck with your site...
Comment #3
flutedrumr commentedHmm. I have Search by Page overriding the default search path, so "search" should have been sufficient, but no cigar; I'll keep playing around with it and post if I find something that works.
Comment #4
jhodgdonHmmm indeed. So when you do a search, you should be seeing paths like search/my_search_term, and Google Analytics should be grabbing that as a search, right?
Comment #5
flutedrumr commentedYes to the paths showing up as search/my_search_term, no to Google Analytics grabbing that...
Comment #6
jhodgdonWell, I don't know anything about Google Analytics or the GA Drupal module... you might read the rest of this thread:
http://drupal.org/node/488762#comment-3662964
as it talks about people in a similar situation (with the Faceted Search module), and the settings they used at Google to get things working.
If that still doesn't work, then maybe you can move this issue back to the Google Analytics project, and hass can help you out. Good luck!
Comment #7
hass commentedYour path need to be something like "search/search-by-page". This will result in a search result url "search/search-by-page/keyword1+keyword2+keyword3". Than GA is able to grab the keywords and forms an url "search/search-by-page?search=keyword1+keyword2+keyword3". Therefore the query param is "search". Hope this makes it finally clear.
Comment #8
flutedrumr commentedSo hass, you think the problem might lie with overriding the default search path? i.e., using "search" as the path instead of "search/search_by_page"? Also wouldn't the "query parameter" be the name of the input field in the search form, e.g., "keys" or "search_block_form"?
Comment #9
flutedrumr commentedOkay, in the Google Analytics Site Search Query Parameter, I've tried the following, none of which work. GA keeps reading the URL as a "normal" page:
search
keys
search_by_page
search-by-page
search/search_by_page
search/search-by-page
I did notice one quirk within Drupal's dblog that seems like it's related. I have the core search form "disabled" for anonymous users, and the Search by Page path set to "search" so visitors always get Search by Page results. When I search from the Search by Page block or the page at /search, the dblog saves them as "search_by_page" events, with the search term as the Message. But if I log in and go to /search/search_by_page, then the dblog saves the queries as "search" events with the Message being "search term (Pages)". The later terms also show up on the Top Search Phrases report. Shouldn't these all be getting logged identically?
Comment #10
jhodgdonIf you go via the URL search/(anything), then the core Search module does the logging. If you go by the URL that you've set up in Search by Page, then Search by Page does the logging.
Setting up the Search by Page module to use a URL that is usually reserved for the core Search module might not work perfectly, and there's not much I can do about that. But I don't think it's a bug in Search by Page if you try to do this and you have problems.
Again, I don't know anything about Google Analytics or the Drupal module, sorry!
Comment #11
hass commentedLast try:
1. Enable Core "Search" module
2. Enable Google Analytics setting to support Search tracking
3. Configure query param in Google Analytics account (google.com/analytics) with "search". Don't try anything else - it will NOT work!
4. Configure a search module of your choice to show it's search results under the folder "search" (e.g. "example.com/search/[my-search-module]/This+are+my+search+keys")
5.
search_get_keys()function will grab the keywords from the URL. See http://api.drupal.org/api/drupal/modules--search--search.module/function... how this core function works.6. Verify if the GA code shows the search URL in
pageTracker("search/[my-search-module]?search=This are my search keys")7. It just works.
Do NOT TRY anything else. I'm out.
Comment #12
FortEZ commentedI have tried to implement the solution mentioned by hass, but it seems that: "
Path cannot include a /". If you try to use a path like search/custom_search_by_page in the search environment, nothing works properly. I am trying to figure out a way to get the specific search path but nothing seems to work.Did anyone manage to make GA and Search by Page work together?
Comment #13
hass commentedIf you cannot configure the path it is a bug in this module and not in GA
Comment #14
jhodgdonI took a look at the Google Analytics on-line help, and found this:
http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=75817
It appears that GA is set up so that it assumes the URLs for search on a web site are always something like this:
example.com/?queryparm=keyword
and you can set up GA to accept multiple query params.
The core Search module and Search by Page do not use this URL format. They use a format like:
example.com/search/keyword
example.com/your-sbp-environment-url/keyword
What I gather from hass in #11 is that the Drupal GA module is able to recognize example.com/search/keyword and pass it to Google in the format Google can accept. But the Drupal GA module does not recognize Search by Page URLs in this way to transform them.
So I think that is the root of the problem here. Correct?
Probably someone could write a small integration module that would do the same thing for Search by Page environments as the Drupal GA module is currently doing for core Search URLs. So I am changing this to a feature request.
If someone who's interested in this wants to try to do it, and posts the module here, I'd be happy to add their add-on module to the Search by Page distribution. Or I might get around to it sometime (no guarantees).
Sorry it's not currently working...
Comment #15
FortEZ commentedIn GA's code, file: googleanalytics.module, line: 107:
if (module_exists('search') && variable_get('googleanalytics_site_search', FALSE) && arg(0) == 'search' && $keys = search_get_keys())I wonder what will happen if I change
arg(0) == 'search'with:arg(0) == 'custom_search_by_page'I'll try that in a development server now...
Comment #16
jhodgdonThat might work for you, but of course, modifying googleanalytics.module means that you'll have trouble updating when they come out with a new version.
Comment #17
FortEZ commentedI'm still trying to figure this out. I'll probably implement a form field that will allow you to enter custom search strings (the ones from the "Search by Page" environments. In any case I will post here for any updates on this issue.
Comment #18
jhodgdonIdeally, there could be a module that would query Search by Page and/or Faceted Search for the environment paths, and supply that to Google Analytics.
Comment #19
FortEZ commentedI made it work by adding an extra function in google analytics module that handles custom search environments from search by page module. However, I want to make my code a bit smarter:
Ideally, there could be a module that would query Search by PageCan you give me an idea of how I could query the "Search by Page" module so that I would get the URL paths of the various environments in an array?
Comment #20
jhodgdonTo get the URLs, you would need to do pretty much what is done in search_by_page_menu() :
There should be something similar you can use in Faceted Search as well -- I would check the function faceted_search_menu(), because it will need to do something similar to what's shown here to make its paths work in Drupal.
Comment #21
FortEZ commentedThanks a lot. If anyone really needs a solution to integrate "Search by Page" and "Google Analytics" right now, let me know and I will post the changes that I did and worked without any issues.
I will probably release a "bridge" module within the next couple of weeks.
Comment #22
hass commentedBefore you release a "bridge" module - for something I do not really understand why you need it - let me know what you are doing there, please. Maybe the GA module can do something for you.
Comment #23
FortEZ commentedBasically, what I do is the following:
1) Created a custom function:
2) In the footer hook after the site search support:
If something is not clear, let me know.
Comment #24
flutedrumr commentedFortEZ, you added #2 to your theme template?
Comment #25
jhodgdonNot sure, but I think FortEZ is saying to add #2 to an existing function googleanalytics_footer() or something close to that.
Comment #26
FortEZ commentedYes, I have added this to the googleanalytics.module file. Assuming that you are using the latest version (3.0) of google_analytics module:
- I have added the function
googleanalytics_search_get_custom_keys()just before the text:- and the rest of the code after:
Comment #27
FortEZ commentedI'm attaching the modified version of the module file that works for me (you can use a compare function of a text editor to check the changes to the original file.
On a sidenote, since I'm not sure whether these changes will be implemented in the Google Analytics module, I will work on the bridge module this weekend so that we can have a more "drupalish" solution to the issue and avoid hacking a module's core.
Comment #28
jhodgdonA bridge module is probably the right thing to do. I think it should be added to the Search by Page project (since it isn't useful for most GA users), and will be happy to add it if you get it working.
You should be able to create a function your_module_name_footer() to take care of the footer stuff, and rename your googleanalytics_search_get_custom_keys() to your_module_name_get_custom_keys().
Actually, with the work FortEZ has already done (THANKS!), I have enough to go on. I will make a custom module today and post it here. If you all can test it, that will be most helpful.
Comment #29
FortEZ commented(Thank YOU for the Search by Page module :* )
I would be more than glad to test it!
Just out of curiosity (since I'm not very experienced in Drupal development):
The Google Analytics module creates some javascript code that is added at the bottom of the page. This custom code normally (if there is no search) looks like this:
but with the search (the same jscript code segment) looks like this:
The only thing that changes is the $url_custom variable (and this is what the pieces of code that I added do). How would you modify the javascript that GA has already created from an external module? Is there an easy way to do that?
I have done some research over this and only found that a solution similar to the javascript alter module can be implemented. Is this close to what you were thinking to do?
Comment #30
jhodgdonHmmm... I think this will work.
What I did was make sure that this little module has a higher weight than GA (meaning its hook_footer() will be executed afterwards), and do the gaq.push() thing there. Which will hopefully override the previous call to gaq.push(). I'm not sure if it will work, but it is at least worth a try... Can you test?
Just unzip this into your Search by Page module directory and enable the module (after removing the changes to Google Analytics that you put in before, otherwise it won't be much of a test).
Comment #31
FortEZ commentedOk, testing it now.
Comment #32
FortEZ commentedA white screen of death cause of a typo in sbp_ga.module file,
change:
to:
Other than that, it seems to be working fine!!!
I will take a closer look at the exported Javascript code in order to make sure that I'm not missing anything, but it seems promising!
:)))))
Comment #33
jhodgdonWhoops. Sorry about that. I make that particular typo a lot. :)
Here's a new zip file with the typo corrected, in case anyone else wants to test it.
Comment #34
hass commentedThis module will cause double trackings.
I still try to understand why you are not going to integrate with the
arg(0)path "search" as this would not require any strange "bridge" modules like this.Comment #35
jhodgdonWhy will it cause double trackings? It won't register as a standard search, because it's at the wrong URL.
Sorry if that is a dumb question -- I'm not as familiar with the GA API as you are.
And we don't use the arg(0) path of search because the search module does all kinds of weird stuff with it, and people should be free to set their own search URLs.
Comment #36
hass commentedAs I know from past 2.x API - if you add "_trackPageview" more than once you have n-times of trackings. Not sure if this may have changed. If you add it 10 times to the same page it is executed 10 times (not verified). On the other side this is a feature as you are able to track in more than one account and fake your stats. Additionally you may break tracking with Ubercart.
For a clean integration we need to get #231451: Add hook to alter data before sending it to browser fixed, but as an interims solution you may go with http://drupal.org/node/284599
Comment #37
jhodgdonI see, thanks. So what we need to do is to replace the call to gaq.push(["_trackPageview"]); that GA will add, with the new call, rather than calling it twice. That code on http://drupal.org/node/284599 looks like a reasonable (if ugly) approach to making that kind of a modification.
Comment #38
jhodgdonOK, here's a new zip file that attempts to do this. Note that there is no .install file needed for this version. I have a bit less confidence that this will work than the last one, but we can hope. :)
FortEZ - if you can test, that would be lovely. Use At Your Own Risk... if you can check your GA logs and see if you're getting double tracking, and take a look at the JS added to the page, that would probably be helpful.
haas - any comments you have would be welcome.
Comment #39
FortEZ commentedjhodgdon - I am launching a new development instance in EC2 right now, so that I can do as much testing as I want without breaking anything. I will get back to you with the results in a couple of hours.
Comment #40
jhodgdonJust getting back to this... Did you test the latest zip file, and if so, what were the results?
Comment #41
sainzu commentedHas anyone fixed this issue? Any update would be of great help.
Comment #42
jhodgdonRE #41 - you can test the module in the zip file in #38 and see if it works for you. That is the next step needed. I don't personally use Google Analytics so I cannot test it myself.
Comment #43
jhodgdonAt this point I am unlikely to add anything to this module for 6.x.
For 7.x, the right fix would be to integrate with the existing Google Analytics contrib module. I'd have to investigate how to do that.