<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Johnny</title>
    <description>The latest articles on DEV Community by Johnny (@johnnyb).</description>
    <link>https://dev.to/johnnyb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2918936%2F145a5c67-8c87-4f1f-958a-1926f5a73d84.png</url>
      <title>DEV Community: Johnny</title>
      <link>https://dev.to/johnnyb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/johnnyb"/>
    <language>en</language>
    <item>
      <title>GA Tracking without urls using WP tags</title>
      <dc:creator>Johnny</dc:creator>
      <pubDate>Thu, 06 Mar 2025 22:46:06 +0000</pubDate>
      <link>https://dev.to/johnnyb/ga-tracking-without-urls-using-wp-tags-1af</link>
      <guid>https://dev.to/johnnyb/ga-tracking-without-urls-using-wp-tags-1af</guid>
      <description>&lt;p&gt;Corrections welcomed...&lt;br&gt;
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:&lt;br&gt;
Methods to Track Tag-Based Analytics:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Custom Dimensions&lt;/strong&gt;&lt;br&gt;
Create a Custom Dimension in Google Analytics:&lt;/p&gt;

&lt;p&gt;Go to your Google Analytics property.&lt;br&gt;
Navigate to "Admin" (gear icon).&lt;br&gt;
Under the "Property" column, click "Custom Definitions" &amp;gt; "Custom Dimensions."  &lt;/p&gt;

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

&lt;p&gt;Click "Create."&lt;br&gt;
Note the "Index" number of your new custom dimension (e.g., dimension1).  &lt;/p&gt;

&lt;p&gt;Add Tracking Code to Your WordPress Site:&lt;/p&gt;

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

&lt;p&gt;In Google Analytics, go to "Customization" &amp;gt; "Custom Reports."&lt;br&gt;&lt;br&gt;
Create a new custom report.&lt;br&gt;
Add your "Blog Tag" custom dimension as a dimension.&lt;br&gt;
Add metrics like "Pageviews," "Users," etc.&lt;br&gt;
You can now see reports based on your "blog" tag.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
