Fixing ExactMetrics Stats Not Showing for Posts with Multiple Categories and Yoast SEO
Content
If you're using ExactMetrics (formerly GADWP) alongside Yoast SEO and have noticed that your article-specific statistics are not showing for posts with multiple categories, you're not alone. This is a common configuration conflict that can be resolved with a small code adjustment.
The Problem: Yoast SEO Primary Category vs. ExactMetrics Tracking
The issue occurs when a WordPress post is assigned to more than one category. Yoast SEO allows you to select a "Primary" category, which then becomes part of the post's permalink structure (e.g., yoursite.com/primary-category/post-name/).
By default, the ExactMetrics plugin may track the post using a different URI, often based on the first category assigned or the post's base slug, rather than the primary category chosen in Yoast. This creates a mismatch. The data is being sent to Google Analytics correctly under the primary category URL, but the ExactMetrics dashboard inside WordPress is looking for data under a different URI. This is why the stats appear as zero or blank in your WordPress admin, while the data is actually present and correct in your main Google Analytics property.
The Solution: Use a Custom Filter
The solution is to add a small code snippet to your website that tells ExactMetrics to use the correct, canonical permalink generated by Yoast SEO when checking for stats. This aligns the data lookup with the actual tracked URL.
Step 1: Add the following code to your theme's functions.php file, or preferably, using a code snippets plugin.
/**
* Adjust ExactMetrics Backend Item URI for Yoast SEO Primary Category.
*/
add_filter( 'gadwp_backenditem_uri', 'my_custom_gadwp_uri', 10, 1 );
function my_custom_gadwp_uri( $uri ) {
// Check if we're in the admin and on a post listing page
if ( ! is_admin() ) {
return $uri;
}
global $post;
// Check if Yoast SEO function 'get_primary_term' exists
if ( ! function_exists( 'yoast_get_primary_term' ) ) {
return $uri;
}
// Get the primary category for the post using Yoast SEO
$primary_category = yoast_get_primary_term( 'category', $post );
if ( $primary_category ) {
// If a primary category is found, rebuild the URI with it
$category_link = get_category_link( $primary_category );
$post_slug = $post->post_name;
// Construct the new URI
$new_uri = parse_url( $category_link, PHP_URL_PATH ) . $post_slug . '/';
return $new_uri;
}
// If no primary category is set, return the original URI
return $uri;
}
Step 2: Save the changes. The ExactMetrics dashboard should now correctly retrieve statistics for posts, even when a primary category is selected via Yoast SEO.
Important Notes
- This code is provided as an example. The exact implementation might need to be adjusted for your specific permalink structure.
- Always test code on a staging site before applying it to your live website.
- If you are uncomfortable adding code, you may need to consult a developer for assistance.
- This conflict highlights how plugin interactions can sometimes require custom solutions. The ExactMetrics team is likely aware of such scenarios, as they provide the
gadwp_backenditem_urifilter for developers to use.
By implementing this filter, you bridge the gap between the two plugins, ensuring your dashboard data accurately reflects the traffic your posts are receiving.
Related Support Threads Support
-
Article Specific Data vs. Yoast SEO permalinkhttps://wordpress.org/support/topic/article-specific-data-vs-yoast-seo-permalink/
-
Stats not showing for post with more than one categoryhttps://wordpress.org/support/topic/stats-not-showing-for-post-with-more-than-one-category/
-
Primary category as canonical for single post statshttps://wordpress.org/support/topic/primary-category-as-canonical-for-single-post-stats/