Support » Plugin: Google Analytics for WordPress by MonsterInsights » [Plugin: Google Analytics for WordPress] Custom search query being tracked incorrectly

  • simonsmith


    Here’s the story:

    – Multisite instance using subdomains
    – Using business directory listing theme at
    – Theme uses a custom search query, e.g.
    – For some reason, Google Analytics for WordPress tracks the page view with (1) the full subdomain information, rather than the relative URL, and (2) the wrong querystring information; for example, this: [‘_trackPageview’,’’]

    I imagine that there’s a reason for this, but it’s causing issues with analytics reporting. For example, we can’t get accurate search usage reports in Google Analytics, and our reports are showing the full subdomain and domain information rather than just the relative URL information.

    Is there a way to turn this off, so the plugin just calls [‘_trackPageview’] as it does on other pages without specifying the URL? Or do we have to hack the plugin code until (hopefully!) a future release addresses this?

Viewing 1 replies (of 1 total)
  • simonsmith


    Solved this (hacked–need a better solution) by modifying code in googleanalytics.php as follows:

    if ( is_404() ) {
    $push[] = “‘_trackPageview’,’/404.html?page=’ + document.location.pathname + + ‘&from=’ + document.referrer”;
    } else if ($wp_query->is_search) {
    // MODIFIED by Simon as this wasn’t working properly with custom searches.
    // Removed custom stuff focused on search tracking and changed it to general _trackPageview call.
    // $pushstr = “‘_trackPageview’,'”.get_bloginfo(‘url’).”/?s=”;
    // if ($wp_query->found_posts == 0) {
    // $push[] = $pushstr.”no-results:”.rawurlencode($wp_query->query_vars[‘s’]).”&cat=no-results'”;
    // } else if ($wp_query->found_posts == 1) {
    // $push[] = $pushstr.rawurlencode($wp_query->query_vars[‘s’]).”&cat=1-result'”;
    // } else if ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
    // $push[] = $pushstr.rawurlencode($wp_query->query_vars[‘s’]).”&cat=2-5-results'”;
    // } else {
    // $push[] = $pushstr.rawurlencode($wp_query->query_vars[‘s’]).”&cat=plus-5-results'”;
    // }
    $push[] = “‘_trackPageview'”;
    } else {
    $push[] = “‘_trackPageview'”;

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Google Analytics for WordPress] Custom search query being tracked incorrectly’ is closed to new replies.