Search Meter WordPress plugin version 2.1

Search Meter 2.1 is a new version of my WordPress blog search statistics plugin. This version fixes the dreaded “duplicate search” problem that a few people have reported. It’s interesting that there were two causes of this problem — the first was already fixed in version 2.0, but the fix for the second variant was much trickier.

You can go straight to the Search Meter page to download the plugin. As well, you might be interested in reading about how I was finally able to fix the “duplicate search” problem.

As I said, there were two separate problems that had the same cause: a single search would show up more than once in Search Meter’s statistics. The first problem was fixed the “right” way: I created a diagnostic version of the plugin, tried it out, discovered the problem, and fixed it. The problem turned out to be Google AdSense!

Every time somebody searches a WordPress blog, it return a search results page. If this page has AdSense ads on it, then they will get a duplicate request. Here’s why this happens.

  1. The browser requests the blog page.
  2. WordPress sends the search results page.
  3. The AdSense scripts on the page kick in and request ads from Google.
  4. Google requests the same search results page, so it can analyse the text and serve up relevant ads.

So Search Meter sees two search requests: the original request, and the second one from Google.

The way I decided to differentiate them is that the Google request naturally comes with no HTTP referrer. So I simply made Search Meter ignore searches made that have no referrer. Problem solved, and as a bonus the diagnostic code I wrote became Search Meter’s “Recent Searches” feature.

I released this fix in Search Meter 2.0, and patted myself on the back for fixing the problem. Not so fast. People still reported the problem, and I even saw it on one of my own blogs. These duplicate requests were exactly the same, even with the same referrer and source IP address, so it wasn’t caused by a third party like Google. In fact, it was almost as if the plugin was being called more than once for each single request.

The fix for this was obvious in retrospect: simply count the number of times the plugin gets called within a given request, and ignore the second and subsequent calls. This is the main change in this new version; testers have reported that it fixes the problem nicely.

The funny thing about this is that I never actually found the definitive reason why it happens at all. My guess is that it’s caused by certain plugins or themes that call WordPress’s the_posts function. Search Meter works by hooking a filter into this function, but previous versions assumed that the function was only called once per request. Normally this is true, but there nothing to stop a theme or plugin calling the_posts any number of times. That (I think) is why this new version does not exhibit the problem.

Thanks for reading — off you go now to the Search Meter page to download the fruit of my investigations.

Share This | Comments | Permalink | Trackback | Comments feed

6 comments

  • [...] Ich hab vor ner weile mal das Searchmeter Plugin installiert. Damit werden Suchanfragen gespeichert. Lustig wonach leute bei mir so suchen. Sie Anzahl ist komischerweise immer ein Vielfaches von 2, wobei ich bei manchen Begriffen auch glaube man muss sie durch 4 Teilen. “Dana nackt” und “mixed wrestling” sind meine Favoriten. Sorry, dass ich damit nicht dienen kann. [...]

  • [...] Wenn ich täglich so durch meine Statistiken blättere und SemmelStatz mir mittlerweile knapp 200 Besucher pro Tag anzeigt und auch die Zahl der Abonnenten meines RSS-Feeds stetig ansteigt, frage ich mich allerdings jedes mal, warum es mit eurem Feedback in den Kommentaren so mau aussieht … Naja und um dem ein wenig entgegenzuwirken, protokolliere ich jetzt halt mal eure Suchanfragen. Big Brother is watching you Jedem, der es mir gleichtun will, empfehle ich das Plugin Search Meter. Dieses liefert detailliert Auskunft über alle innerhalb des Blogs getätigten Suchanfragen. So soll man angeblich gezielter auf die werte Leserschaft eingehen können. Oder aber ihr verratet mir ganz einfach, warum ihr meiner Seite ab und an einen Besuch abstattet. In diesem Sinne: vielen Dank für die Aufmerksamkeit. [...]

  • Potaje says:

    Search Meter 2.1…

    Bennett, desde Semicolon, ha actualizado el plugin para Wordpress Search Meter a la versión 2.1.

    Los resultados de las búsquedas siguen bajo la pestaña Tablero. La diferencia (visible) en esta versión es que se han añadido dos nuevas listas e…

  • [...] Improved Search Monetization The blogging platform that we use here and on CG is WordPress, it has a lot of cool features built in and can be improved by plug-ins. One such plug-in is search meter which lets you monitor what people and search for and do a few other cool things. [...]

  • [...] Search Meter >> Sitenizde Yapılan Aramaları Kaydeder ve Yöneticiye Sunar. [...]

  • Ben 10 says:

    I’m using version 2.5 still I’m getting duplicate searches how to avoid these I’m using search meter in the right footer please visit my site and can you tell me the solution

Post a comment

(required)
(required)
(some HTML allowed; for literal < and &, use &lt; and &amp;)
Close
E-mail It