WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
Custom search query being tracked incorrectly (2 posts)

  1. simonsmith
    Member
    Posted 2 years ago #

    Here's the story:

    - Multisite instance using subdomains
    - Using business directory listing theme at subdomain.domain.com
    - Theme uses a custom search query, e.g. subdomain.domain.com/?ls=category&location=city
    - 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','http://subdomain.domain.com/?s=category&cat=plus-5-results']

    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?

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

  2. simonsmith
    Member
    Posted 2 years ago #

    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 + document.location.search + '&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'";
    }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic