GA Tracking without urls using WP tags

Corrections welcomed…
You can create Google Analytics reports based on WordPress tags like “blog,” even if your URL structure doesn’t directly reflect the tag. Here’s how to do it:
Methods to Track Tag-Based Analytics:

Using Custom Dimensions
Create…


This content originally appeared on DEV Community and was authored by Johnny

Corrections welcomed...
You can create Google Analytics reports based on WordPress tags like "blog," even if your URL structure doesn't directly reflect the tag. Here's how to do it:
Methods to Track Tag-Based Analytics:

Using Custom Dimensions
Create a Custom Dimension in Google Analytics:

Go to your Google Analytics property.
Navigate to "Admin" (gear icon).
Under the "Property" column, click "Custom Definitions" > "Custom Dimensions."

Click "New Custom Dimension."
Name it something like "Blog Tag."
Set the "Scope" to "Hit" (because you want to track the tag for each page view).

Click "Create."
Note the "Index" number of your new custom dimension (e.g., dimension1).

Add Tracking Code to Your WordPress Site:

You'll need to modify your Google Analytics tracking code to send the tag information to Google Analytics.
You can do this by editing your theme's functions.php file or using a plugin like "Insert Headers and Footers."
Here's an example of the code you would add:
<?php
function add_blog_tag_to_ga() {
if (is_single() && has_tag('blog')) {
global $post;
$tags = wp_get_post_tags($post->ID);
$tag_names = array();
foreach ($tags as $tag) {
$tag_names[] = $tag->name;
}
$tag_string = implode(', ', $tag_names);
?>
<br> ga(&#39;set&#39;, &#39;dimension[YOUR_CUSTOM_DIMENSION_INDEX]&#39;, &#39;[YOUR_TAG_STRING]&#39;);<br>
<?php
}
}
add_action('wp_footer', 'add_blog_tag_to_ga');
?>
Replace:
[YOUR_CUSTOM_DIMENSION_INDEX] with the index number of your custom dimension (e.g., dimension1).
[YOUR_TAG_STRING] with the $tag_string variable.
This code checks if the current page is a single post and has the tag "blog." If it does, it sends the tag names to Google Analytics as a custom dimension.
Create Custom Reports in Google Analytics:

In Google Analytics, go to "Customization" > "Custom Reports."

Create a new custom report.
Add your "Blog Tag" custom dimension as a dimension.
Add metrics like "Pageviews," "Users," etc.
You can now see reports based on your "blog" tag.


This content originally appeared on DEV Community and was authored by Johnny


Print Share Comment Cite Upload Translate Updates
APA

Johnny | Sciencx (2025-03-06T22:46:06+00:00) GA Tracking without urls using WP tags. Retrieved from https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/

MLA
" » GA Tracking without urls using WP tags." Johnny | Sciencx - Thursday March 6, 2025, https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/
HARVARD
Johnny | Sciencx Thursday March 6, 2025 » GA Tracking without urls using WP tags., viewed ,<https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/>
VANCOUVER
Johnny | Sciencx - » GA Tracking without urls using WP tags. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/
CHICAGO
" » GA Tracking without urls using WP tags." Johnny | Sciencx - Accessed . https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/
IEEE
" » GA Tracking without urls using WP tags." Johnny | Sciencx [Online]. Available: https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/. [Accessed: ]
rf:citation
» GA Tracking without urls using WP tags | Johnny | Sciencx | https://www.scien.cx/2025/03/06/ga-tracking-without-urls-using-wp-tags/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.