<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Google Analytics - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Google Analytics - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Wed, 03 Jun 2026 17:24:29 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/google-analytics/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Add Google Analytics to your Astro Website ]]>
                </title>
                <description>
                    <![CDATA[ You can use data insights derived from your website or app to make important decisions that'll help grow your business. This information can help you improve user experience, create effective content strategies, and so on. Google Analytics is an effe... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-add-google-analytics-to-your-astro-website/</link>
                <guid isPermaLink="false">66b0a2bfb30dd4d00547bb92</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Astro ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ihechikara Abba ]]>
                </dc:creator>
                <pubDate>Wed, 18 Oct 2023 18:07:14 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/10/andy-hermawan-bVBvv5xlX3g-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>You can use data insights derived from your website or app to make important decisions that'll help grow your business. This information can help you improve user experience, create effective content strategies, and so on.</p>
<p>Google Analytics is an effective tool for tracking and analyzing traffic and events on your websites and mobile apps. In this article, you'll learn how to add Google Analytics to your Astro website.</p>
<p>To follow along, you'll need the following:</p>
<ul>
<li>A Google account.</li>
<li>A deployed Astro project.</li>
</ul>
<p>Let's get started!</p>
<h2 id="heading-how-to-add-google-analytics-to-an-astro-website">How to Add Google Analytics to an Astro Website</h2>
<p>Before adding Google analytics, make sure you've already deployed your project. Here's one that I've deployed using Netlify: <a target="_blank" href="https://astro-article.netlify.app/">https://astro-article.netlify.app/</a>. This is an Astro blog template created with the <code>npm create astro@latest -- --template blog</code> command.</p>
<p>This section will be divided into two sub-sections. In the first sub-section, you'll learn how to create an Analytics account and how to set up your account for tracking and monitoring your website.</p>
<p>In the second sub-section, you'll learn how to configure your code to sync with Google Analytics.</p>
<h3 id="heading-how-to-set-up-google-analytics">How to Set Up Google Analytics</h3>
<p>You can follow these steps to set up Google Analytics:</p>
<h4 id="heading-step-1-account-creation-page">Step #1 – Account Creation Page</h4>
<p>The first step is to create a Google Analytics account. You can do that by visiting <a target="_blank" href="https://analytics.google.com/">the Google Analytics website</a>.</p>
<p>When the page loads, you should see something similar to this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/google-analytics-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Google Analytics home page</em></p>
<p>Click on the "Start measuring" button. This will take you to the account creation page where you'll fill in some info about your website/app. That is:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/account-creation.png" alt="Image" width="600" height="400" loading="lazy">
<em>"Create an Account" page on Google Analytics</em></p>
<p>After inputting an account name, scroll down the page and click on the "Next" button.</p>
<h4 id="heading-step-2-property-creation-page">Step #2 – Property Creation Page</h4>
<p>On the property creation page, you can create a property name, time zone, and currency.</p>
<p>A property acts as a unique identifier for your websites and apps. So it is like a container for all the data related to a specified website or app.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/property-creation.png" alt="Image" width="600" height="400" loading="lazy">
<em>"Create a Property" page on Google Analytics</em></p>
<h4 id="heading-step-3-business-details-page">Step #3 – Business Details Page</h4>
<p>On the business details page, you can specify your industry category and the business size.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/business-details.png" alt="Image" width="600" height="400" loading="lazy">
<em>"Describe your business" page on Google Analytics</em></p>
<h4 id="heading-step-4-business-objectives-page">Step #4 – Business Objectives Page</h4>
<p>The business objectives helps Analytics generate personalized reports for your business. You can select the options that are important to your website, app, or product category.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/business-objectives.png" alt="Image" width="600" height="400" loading="lazy">
<em>"Business objectives" page on Google Analytics</em></p>
<p>After selecting the options, click on the "Create" button.</p>
<h4 id="heading-step-5-data-collection-page">Step #5 – Data Collection Page</h4>
<p>On the data collection page, you can choose between different platforms to collect data from. Since we're working with a website, we'll go with the Web option.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/data-collection.png" alt="Image" width="600" height="400" loading="lazy">
<em>"Start collecting data" page on Google Analytics</em></p>
<p>Next, you'll have to create a data stream by inputting your website URL and your stream name (this can be whatever you want, but I'll recommend using a name related to your website).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/stream.png" alt="Image" width="600" height="400" loading="lazy">
<em>Page to setup a data stream on Google Analytics</em></p>
<p>In my data stream information, I used <a target="_blank" href="https://astro-article.netlify.app/">https://astro-article.netlify.app/</a> as the URL and "Astro Blog Template" as the stream name. </p>
<p>Make sure you remove the "https://" part of the link in the input box so you don't get the "Valid website URL is required" error. </p>
<p>So instead of <a target="_blank" href="https://astro-article.netlify.app/">https://astro-article.netlify.app/</a>, it should be astro-article.netlify.app/.</p>
<p>This is what mine looks like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/stream-data.png" alt="Image" width="600" height="400" loading="lazy">
<em>Example of information entered properly in data stream setup page</em></p>
<p>Go ahead and click on the "Create stream" button.</p>
<p>On the next page/prompt, you'll see your stream name, URL, ID, and measurement ID values. </p>
<p>The measurement ID will be important in our code integration so you can copy and paste it somewhere.</p>
<p>Here's what the page looks like:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/stream-details.png" alt="Image" width="600" height="400" loading="lazy">
<em>"Web stream details" page on Google Analytics</em></p>
<p>If you click on "View tag instructions", you'll see a code snippet for manual integration with code. Copy the code and paste somewhere because we'll make use of it soon.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/installation-instructions.png" alt="Image" width="600" height="400" loading="lazy">
<em>Installation instructions</em></p>
<p>Here's the code snippet if you missed it:</p>
<pre><code class="lang-js">&lt;!-- Google tag (gtag.js) --&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">async</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [];
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
  gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());

  gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'MEASUREMENT_ID'</span>);
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre>
<p>If you're copying the code above, make sure you replace the two <code>MEASUREMENT_ID</code> values with the actual value of your measurement ID.</p>
<h3 id="heading-how-to-integrate-google-analytics-and-astro">How to Integrate Google Analytics and Astro</h3>
<p>At this point, we've created a Google Analytics account and generated our project's measurement ID. The next thing to do is to sync our code to Google Analytics.</p>
<p>But first, we have to install a library called Partytown. When using third party integrations, you may run into performance issues because you're making use of third-party code.</p>
<p>Partytown allows these integrations to run as expected without reducing your site's performance. You can read more about that <a target="_blank" href="https://partytown.builder.io/how-does-partytown-work">here</a>.</p>
<h4 id="heading-step-1-install-partytown">Step #1 – Install Partytown</h4>
<p>Head to your Astro project terminal and run this command to install Partytown:</p>
<pre><code class="lang-bash">npm install @astrojs/partytown
</code></pre>
<h4 id="heading-step-2-configure-partytown">Step #2 – Configure Partytown</h4>
<p>After the installation is complete, you'll need to add the integration to your <strong>astro.config.mjs</strong> file:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { defineConfig } <span class="hljs-keyword">from</span> <span class="hljs-string">'astro/config'</span>;
<span class="hljs-keyword">import</span> mdx <span class="hljs-keyword">from</span> <span class="hljs-string">'@astrojs/mdx'</span>;
<span class="hljs-keyword">import</span> partytown <span class="hljs-keyword">from</span> <span class="hljs-string">'@astrojs/partytown'</span>

<span class="hljs-keyword">import</span> sitemap <span class="hljs-keyword">from</span> <span class="hljs-string">'@astrojs/sitemap'</span>;

<span class="hljs-comment">// https://astro.build/config</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> defineConfig({
    <span class="hljs-attr">site</span>: <span class="hljs-string">'https://astro-article.netlify.app/'</span>,
    <span class="hljs-attr">integrations</span>: [
        mdx(), 
        sitemap(),
        partytown({
            <span class="hljs-attr">config</span>: {
              <span class="hljs-attr">forward</span>: [<span class="hljs-string">"dataLayer.push"</span>],
            },
        }),
    ],
});
</code></pre>
<p>In the code above, we imported the Partytown library: <code>import partytown from '@astrojs/partytown'</code>.</p>
<p>We then added this piece of code to the <code>integrations</code> object:</p>
<pre><code class="lang-js">partytown({
      <span class="hljs-attr">config</span>: {
        <span class="hljs-attr">forward</span>: [<span class="hljs-string">"dataLayer.push"</span>],
      },
})
</code></pre>
<p>Everything else in the code came with the Astro project.</p>
<h4 id="heading-step-3-add-google-tag-to-your-pages">Step #3 – Add Google Tag to your Pages</h4>
<p>Remember the code snippet from Google Analytics? This is where we'll use it.</p>
<pre><code class="lang-js">&lt;!-- Google tag (gtag.js) --&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/partytown"</span> <span class="hljs-attr">async</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/partytown"</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [];
  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
  gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());

  gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'MEASUREMENT_ID'</span>);
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre>
<p>Note that we added the <code>type="text/partytown"</code> attribute to both <code>&lt;script&gt;</code> tags.</p>
<p>Remember to change the <code>MEASUREMENT_ID</code> values to the value of your measurement ID. Mine looks like this:</p>
<pre><code class="lang-js">&lt;!-- Google tag (gtag.js) --&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/partytown"</span> <span class="hljs-attr">async</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.googletagmanager.com/gtag/js?id=G-KM36S70L8Y"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/partytown"</span>&gt;</span><span class="javascript">
    <span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [];
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
    gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());

    gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'G-KM36S70L8Y'</span>);
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span></span>
</code></pre>
<p>Do not use the snippet above as it has my measurement ID so it's already associated with my website (not my actual website :)). Copy the first code snippet and change the <code>MEASUREMENT_ID</code> values to the value of your measurement ID.</p>
<p>To track and monitor a page, you need to paste the code snippet in that page. Copy the code and paste it in the <code>&lt;head&gt;</code> section of every page file (<strong>index.astro</strong>, <strong>BlogPost.astro</strong>, and so on) you want to track and analyze using Google Analytics.</p>
<p>Here's an example using the <strong>index.astro</strong> file in the <strong>pages</strong> directory:</p>
<pre><code class="lang-js">---
<span class="hljs-keyword">import</span> BaseHead <span class="hljs-keyword">from</span> <span class="hljs-string">'../components/BaseHead.astro'</span>;
<span class="hljs-keyword">import</span> Header <span class="hljs-keyword">from</span> <span class="hljs-string">'../components/Header.astro'</span>;
<span class="hljs-keyword">import</span> Footer <span class="hljs-keyword">from</span> <span class="hljs-string">'../components/Footer.astro'</span>;
<span class="hljs-keyword">import</span> { SITE_TITLE, SITE_DESCRIPTION } <span class="hljs-keyword">from</span> <span class="hljs-string">'../consts'</span>;
---

&lt;!doctype html&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
        <span class="hljs-comment">&lt;!-- Google tag (gtag.js) --&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/partytown"</span> <span class="hljs-attr">async</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/partytown"</span>&gt;</span><span class="javascript">
            <span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [];
            <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
            gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());

            gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'MEASUREMENT_ID'</span>);
        </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">BaseHead</span> <span class="hljs-attr">title</span>=<span class="hljs-string">{SITE_TITLE}</span> <span class="hljs-attr">description</span>=<span class="hljs-string">{SITE_DESCRIPTION}</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
... <span class="hljs-comment">&lt;!-- The rest of the HTML code --&gt;</span></span>
</code></pre>
<p>In the code above, we put the code from Google Analytics in the <code>&lt;head&gt;</code> tag. You can do this for all the pages you want to track and monitor.</p>
<p>Remember to add the  <code>type="text/partytown"</code> attribute to the <code>&lt;script&gt;</code> tags, and to change <code>MEASUREMENT_ID</code> (used in two places in the snippet) to the value of your measurement ID.</p>
<h4 id="heading-step-4-build-and-deploy-your-project">Step #4 – Build and Deploy your Project</h4>
<p>Deploy your project using your preferred process.</p>
<p>In my case, I use <code>npm run build</code> to build into the <strong>dist</strong> folder, and then push the code to GitHub. This automatically triggers a Netlify deployment.</p>
<p>You don't have to use my method, but make sure your project builds before deployment.</p>
<p>Once your website has been deployed, you may have to wait up to 48 hours to start seeing your analytics in the Google Analytics dashboard.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/pending-data-collection.png" alt="Image" width="600" height="400" loading="lazy">
<em>Pending page</em></p>
<p>You'll see this page when you click on the "Continue to Home" button:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2023/10/analytics-home.png" alt="Image" width="600" height="400" loading="lazy">
<em>Analytics dashboard</em></p>
<p>This is your Analytics dashboard. You can view and analyze your data here when there's data available.</p>
<p>And there you have it! You've successfully integrated your project with Google Analytics.</p>
<h2 id="heading-summary">Summary</h2>
<p>In this article, we saw how to add Google Analytics to an Astro project. This can be used to track and analyze traffic and events on websites and apps.</p>
<p>We saw how to create and set up an Analytics account. </p>
<p>We then saw how to integrate Google Analytics to an Astro project using code.</p>
<p>Happy coding! You can read more Astro tutorials on <a target="_blank" href="https://ihechikara.com/">my blog</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Google Search Console Explained: What is GSC and How to Use It ]]>
                </title>
                <description>
                    <![CDATA[ By Adam Naor Google Search Console is a web service by Google that lets you see the indexing and performance of your websites and webpages on Google search. At a high level, the search console is a powerful tool to confirm that your website is rankin... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/google-search-console-explained/</link>
                <guid isPermaLink="false">66d45d663a8352b6c5a2a9f9</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ metrics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ search ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 05 Jan 2021 19:01:25 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5ff3f30c7af2371468bb7980.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Adam Naor</p>
<p>Google Search Console is a web service by Google that lets you see the indexing and performance of your websites and webpages on Google search.</p>
<p>At a high level, the search console is a powerful tool to confirm that your website is ranking and that Google can access your website. </p>
<p>You can check and set the crawl rate and view statistics about where your traffic is landing and where you are acquiring traffic from.</p>
<p>The console, like many other web dev tools, is robust and powerful. If you are building your first website you should take time to understand it, play around with it, and learn to leverage it. </p>
<p>This tutorial walks you through the basics of this tool, and can be a useful guide to help you save time when learning which metrics matter for your site’s performance and how you can leverage this data to build better products.</p>
<p>I have lived in the search console for the past six months because I built a website and I care deeply about how people find the content that I write.</p>
<p>Prior to my experience building this site, I was not a regular user of the Search Console. I had to learn about this tool, including what it could do to help me better understand my users and their intent when landing on my website.</p>
<p>I have learned three important lessons about the Search Console’s Performance section and want to pass those lessons on to you.</p>
<h2 id="heading-lesson-1-know-the-source-of-your-traffic-search-vs-discover">Lesson #1: Know the source of your traffic: Search vs Discover</h2>
<p><img src="https://lh3.googleusercontent.com/zMsT6tSzNEUghosvFvS_3MHo0FE0s3GPbI_FnL29FgX-8N1qWgZw5afCRT34mzpvWfIF3owlf_DInR7cnxnxscjGj9pFaIks8F1KSU54s3ZEIkLJrMof-19VBaBmbz8zJseon3ZK" alt="Image" width="554" height="250" loading="lazy"></p>
<p>Google gives you two ways to see how people are reaching your website through Search: via Search results or via Discover.</p>
<p>“Discover” (previously known as Google Feed) is a personalized content feed created by Google that proactively serves relevant content to users. You can’t nominate your content for Discover. If Google thinks that your website is relevant to users, Google will show it to people.</p>
<p>The other type of performance metric, and one that is seemingly far larger, is “Search results”. Search results shows a webmaster four vital pieces of information:</p>
<ol>
<li>Total clicks</li>
<li>Total impressions</li>
<li>Average CTR (Click Thru Rate)</li>
<li>Average Position</li>
</ol>
<p>Discover provides the same information with the exception of Average Position because there are no relative ranking positions within this metric.</p>
<p>When learning to use the Search Console, spend time looking at traffic through the lens of Search and Discover. If you do not see Discover traffic, that means your content has not yet been shown via Discover to users.</p>
<p>When starting a website or blog, you will want users to find your content. Search and discover are the two organic ways that people will do so. Know how many people find you via each.</p>
<h2 id="heading-lesson-2-study-your-average-position">Lesson #2: Study your average position</h2>
<p>When I first started using the Search Console I was amazed (and happy) that I was getting any traffic at all! Over time, your clicks will increase if you are publishing relevant and useful content. </p>
<p>As more people find your website and the site gets more impressions, clicks will go up.</p>
<p>You might be tempted to pat yourself on the back and call it a day. Not so fast!</p>
<p>Each page that you publish on your website is eligible to appear on Google search if you want that page to be crawled and indexed. </p>
<p>Some of your pages will perform very well (that is, they'll land on the first page of Google) and others will land further down (like on the 12th page where nobody will see them).</p>
<p>Over time you will want to monitor and track your average position and find ways to increase your average position by producing higher quality and more relevant content that benefits readers.</p>
<p>Here is a simple strategy to see your average position over time: create articles of similar length, quality, and usefulness to readers. </p>
<p>Then, come back over the ensuing weeks and months and see which ones are starting to rank and what their relative positions are. This strategy is deployed by review sites, thought leadership posts, and even online coding schools.</p>
<p>When I started my first website my average position was around 60. That means that 59 other websites showed up before mine. </p>
<p>Today, that average position is 26.8. Clearly I have a long way to go but it's a step in the right direction. Be aware of this metric and spend time tracking it.</p>
<p><img src="https://lh4.googleusercontent.com/K6rw6C7I7G6D1F5tm9yP7Qu5LHZtdPgmZwv07vW_gfP_3szFEh3SbfhgOTB5E2wQX3JnbIDWy4bRjw3v2h3qJRnHImfP48IaRW9G-j0Boe0P3hohg_dSNCizQrnxP0p8SoZJQcCY" alt="Image" width="909" height="339" loading="lazy">
<em>Source: https://wfhadviser.com/</em></p>
<h2 id="heading-lesson-3-impressions-are-the-top-of-the-funnel">Lesson #3: Impressions are the top of the funnel</h2>
<p>Regardless of the type of website you have - blog, educational, e-commerce, recreational - you will want traffic. </p>
<p>Traffic is just another way of saying unique visitors. Depending on what your website has to offer, you might value certain types of traffic more than others: by region, country, age of users, device operating system, and so on.</p>
<p>But as you focus in on clicks and performance, it all starts with impressions. An impression is counted each time your webpage is shown on a search result page.</p>
<p>In other words, impressions are the top of the funnel. You will need to grow impressions first in order to grow all other metrics.</p>
<p><img src="https://lh6.googleusercontent.com/6K8ZRZ8FiIWGqHYwlCFFMb8auG7lyReNKil79J992RJlyHTpUMsIHR8JQZns6rcK6Y2cebVsubRCZpYIpe5acqK9BIW8Bh6hXm8vdRDNNDdzHE2eJ4-MSou2jUw-I_9H3xqZZa0f" alt="Image" width="906" height="373" loading="lazy"></p>
<p>A word of caution that I have discovered the hard way. If your website is on the lower part of the search results, an impression might count even if the user doesn’t scroll all the way down. </p>
<p>In other words, the way Google counts an impression is seemingly slightly different from how a person might count it. In layperson's terms (that is, not technology) an impression is when you actually see something. </p>
<p>In Google’s terms, an impression is when your website is on a results page and the user sees the results page. In short, scrolling doesn’t seem to impact impression counts.</p>
<h2 id="heading-bringing-it-all-together-know-how-your-users-reach-your-website-to-build-better-products">Bringing It All Together: Know How Your Users Reach Your Website To Build Better Products</h2>
<p>If you want to build a product, you always need to know how your users learned about your product and what they value most. Builders start with the customer and work backwards. </p>
<p>Google’s Search Console is a terrific tool to understand one aspect of the user journey to better align your product, your messaging, and your value-prop with the needs of your clients.</p>
<p>You can use the Performance section of the Search Console to obsess over customers and how they reach you. </p>
<p>Google makes it easy to test this in real time so that your feedback loop is minimal: you can review the crawled page automatically or promagically.</p>
<p><img src="https://lh3.googleusercontent.com/hFhSEp310NkJUuZ09PUzImV9f_eR04Yh6A5JWnNcRiRt_1DW4r6dwQkFGkMSKLPZ5J6ksxmEc3xm2Esi0KxJwEyXmjmsBVPr1TGp1_UjnW6-DzgzCprMwZMBtfVylmWaO0HhqPlU" alt="Image" width="1600" height="792" loading="lazy"></p>
<p>Growing SaaS, a company that notes that SEO is one of the core user acquisition strategies for companies, also convincingly argues that if you don't know where, what, how, or why to measure traffic, you will be missing guidance as to what to build and for whom. </p>
<p>If you build any product - a website, a mobile app, or a tool for Enterprises - you need to know how people hear about your product and reach you.</p>
<p>Imagine if you built a newsletter but had no idea how your email list grew over time or what your subscribers valued most? Sounds crazy, right? That is akin to building a site and not mastering the Search Console.</p>
<p>Certainly this would be a suboptimal situation for any coder or creator.</p>
<p>Builders are never done learning. </p>
<p>The Search Console gives you data and visual guidance on ways to improve your website and customer acquisition. By being curious about new possibilities and acting to explore them, you can do a better job building. </p>
<p>And Google reinforces this by helping guide you along the way. These green circles and checks confirm that the site has live pages and that are properly indexed. It's always a nice plus when the visual design helps the builders :)  </p>
<p><img src="https://lh3.googleusercontent.com/aHwRsAr_vDvLLeV8QXCWqZhKC15ZlgJ82r-xPWCRprJMvxaPzlQxmShrc4nGR-2q93PlyVl3IJKCM5yaeaXDpQkB-bDDSNtclUyfZa5wrHms0GbhXAqRj-ngUb8ll8qE6LaiSx_5" alt="Image" width="1284" height="624" loading="lazy"></p>
<p>Builders not only index on what is going well - and how to improve these trends - but what is not working so that they can course correct. Google’s search console, like other online tools, helps users see broken links and error pages, pages that need improvements, and site speed.</p>
<p>If you were looking at hundreds of pieces of paper in a book - or bulk emails - or thousands of indexed web pages, you need to leverage a tool to understand the data in front of you. </p>
<p>The Search Console is just that.</p>
<p>It is free to use and fast to deploy. It is important to use and critical to master - your product and users will be better served if you leverage it.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Quickly Track PDF Access on a Linux Web Server ]]>
                </title>
                <description>
                    <![CDATA[ Is it possible to track how many times your website's users click to download binary files like PDFs or JPGs? Yes it is possible. Is it easy? I didn't originally think so. I was wrong. The story began while I was optimizing a landing page on my Boots... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/quickly-track-pdf-access-linux-web-server/</link>
                <guid isPermaLink="false">66b9962622379234769e45f1</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ metrics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ pdf ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Wed, 02 Dec 2020 17:17:52 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/12/calculator.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Is it possible to track how many times your website's users click to download binary files like PDFs or JPGs? Yes it is possible. Is it easy? I didn't originally think so. I was wrong.</p>
<p>The story began while I was optimizing a landing page on my <a target="_blank" href="https://bootstrap-it.com/davidclinton/keeping-up">Bootstrap IT website</a> for my new book, <em>Keeping Up: Backgrounders to all the big technology trends you can't afford to miss</em>. </p>
<p>I wanted to provide access to the PDF file of a sample chapter from the book. But I also wanted some way to know how many people actually downloaded it.</p>
<p>Now let's take a step back. <a target="_blank" href="https://analytics.google.com/analytics/web/">Google Analytics</a> is a free service that uses code snippets inserted into your HTML files to collect and display data on how often your files were accessed. </p>
<p>The magic - and problem - of Google Analytics is in just how much information about your users can be revealed. I discussed some of the privacy concerns involved with the service in the Keeping Up book. I also mentioned how I feel at least a bit guilty for using the service myself on my own sites.</p>
<p>At any rate, all by itself, Google Analytics isn't able to tell you much about how your web-based PDFs are being used. Of course, there are tricks for getting around the problem. </p>
<p>Traditional approaches include setting up the <a target="_blank" href="https://marketingplatform.google.com/about/tag-manager/">Google Tag Manager</a>, customizing the syntax of the request URLs you use or, if your site uses WordPress software, working with the <a target="_blank" href="https://www.monsterinsights.com/">Monster Insights plugin</a>. Each of those can work, but will require a fairly steep learning curve.</p>
<p>But I'm a Linux sysadmin. And, as I never fail to remind the people around me, the best sysadmins are lazy. Learning curve? That sounds suspiciously like work. Not gonna happen on my watch.</p>
<p>So here's the deal. My web server, obviously, runs Linux. And, under the hood, HTTP traffic is handled by Apache. That means that everything happening to and on my websites is going to be logged by Apache. </p>
<p>Everything. All it'll take to give me what I need to know about what my PDF sample chapter has been up to, is a single line of Bash run from my local workstation:</p>
<pre><code>echo <span class="hljs-string">"cd /var/log/apache2 &amp;&amp; grep -nr KeepingUpSampleChapter"</span> \
   | ssh -i PrivateKey.pem LoginName@bootstrap-it.com
</code></pre><p>Let's break that down. The first of the two commands in quotation marks (<code>cd /var/log/apache2</code>) will move us to the /var/log/apache2/ directory on the Linux server where Apache writes its logs. That's not rocket science.</p>
<p>There are going to be multiple files of interest in that directory. That's because messages relevant to regular access and errors are saved to different files, and because file rotation policies mean that there could be more than one version of either of those files, too. So I'll use <code>grep</code> to search all the uncompressed files for the <code>KeepingUpSampleChapter</code> string. <code>KeepingUpSampleChapter</code> is, of course, part of the filename of the PDF.</p>
<p>I then pipe that command to SSH, which will connect to my remote server and execute the command. Here's what a single entry would look like from a successful run (I've removed the requester's IP address out of privacy concerns):</p>
<pre><code>other_vhosts_access.log<span class="hljs-number">.1</span>:<span class="hljs-number">12200</span>:bootstrap-it.com:<span class="hljs-number">443</span> &lt;requester<span class="hljs-string">'s IP Address&gt; - - [01/Dec/2020:16:39:36 -0500] "GET /davidclinton/KeepingUpSampleChapter.pdf?pdf=SamplePDF HTTP/1.1" 200 65146 "https://bootstrap-it.com/davidclinton/keeping-up/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"</span>
</code></pre><p>We can see:</p>
<ul>
<li>The log file where the entry appeared (<code>other_vhosts_access.log.1</code>)</li>
<li>The requester's IP address (redacted)</li>
<li>The timestamp telling us exactly when the file was accessed</li>
<li>The relative location of the file on the server file system (<code>/davidclinton/KeepingUpSampleChapter.pdf</code>)</li>
<li>The URL from which the request was made (<code>https://bootstrap-it.com/davidclinton/keeping-up/</code>)</li>
<li>And the browser the user was running</li>
</ul>
<p>That's a lot of information. If we're just curious about how many <em>times</em> the file was downloaded, we can simply pipe the output to the <code>wc</code> command that will tell us three things about the output: the number of lines, words, and characters it contained. That command would look like this:</p>
<pre><code>echo <span class="hljs-string">"cd /var/log/apache2 &amp;&amp; grep -nr KeepingUpSampleChapter | wc"</span> \
   | ssh -i PrivateKey.pem LoginName@bootstrap-it.com
</code></pre><p>There is one possible limitation with this method. If your website is busy, the log files will roll over frequently, often more than once a day. By default, after the first rollover, the files are compressed using the <code>gz</code> algorithm, which can't be read by <code>grep</code>.</p>
<p>The <code>zgrep</code> command won't have any trouble handling such files, but the process could end up taking a very long time. You might consider writing a simple custom script to decompress each <code>gz</code> file and then run regular <code>grep</code> against its contents. That'll be your project.</p>
<p><em>There's much more administration goodness in the form of books, courses, and articles available at my <a target="_blank" href="https://bootstrap-it.com/davidclinton">bootstrap-it.com</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ 3 Privacy-Focused Open Source Google Analytics Alternatives for Your Next Project ]]>
                </title>
                <description>
                    <![CDATA[ By Leonardo Faria As a content creator, I like to know the page analytics of my website.  Overall, I am curious to know how many people are reading my content, where they came from (referrer and countries), and what the most popular pages are. 20 yea... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/3-privacy-focused-open-source-google-analytics-alternatives-for-your-next-project/</link>
                <guid isPermaLink="false">66d8516c29e30bc0ad477590</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ open source ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 04 Sep 2020 12:20:06 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/09/markus-winkler-IrRbSND5EUc-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Leonardo Faria</p>
<p>As a content creator, I like to know the page analytics of my website. </p>
<p>Overall, I am curious to know how many people are reading my content, where they came from (referrer and countries), and what the most popular pages are.</p>
<p>20 years ago, tools like <a target="_blank" href="http://www.webalizer.org/">Webalizer</a> were all that we could count on. Tools like this parsed Apache logs and created static pages with the processed data.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/webalizer.jpg" alt="webalizer screenshot" width="600" height="400" loading="lazy"></p>
<p>Another way to get page analytics was to insert an image - often invisible - on your site. By using the request headers sent to the server, people could count visitors and get a little bit more information such as origin IP, browser, and operating system. This technique is old, but services like <a target="_blank" href="https://statcounter.com/">statcounter</a> still provide this functionality.</p>
<p>In 2005 Google launched Google Analytics after acquiring <a target="_blank" href="https://en.wikipedia.org/wiki/Urchin_(software)">Urchin</a>, a company which also analyzed server logs. Its presence has been growing since the early days and it has far more usage than any of its competitors. But, there are a few reasons <a target="_blank" href="https://plausible.io/blog/remove-google-analytics">why you should stop using Google Analytics on your website</a>: </p>
<p>1) It is owned by Google, which uses analytics for their own benefit
2) It affects site speed by adding 45KB to page requests
3) It is too invasive, collecting lots of personal data that you don't need
4) It is blocked by many plugins and browsers, creating inaccurate data</p>
<p>With all this in mind, I want to share a few open source alternatives I have been looking at for the last few months.</p>
<h2 id="heading-fathom">Fathom</h2>
<p><a target="_blank" href="https://usefathom.com/">Fathom</a> (<a target="_blank" href="https://app.usefathom.com/share/sqqvo/chimp+essentials">demo</a>) is a light Golang app to collect analytics. </p>
<p>They have different paid plans which start at $14/month. They also have a lite version that you can install on your server or Heroku for free.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/fathom.jpg" alt="Fathom screenshot" width="600" height="400" loading="lazy"></p>
<p>The lite version uses cookies and it gives you information about unique visitors, page views, average time on site, bounce rate, top pages, and top referrers. Fathom stores data in SQLite, MySQL, or Postgresql databases.</p>
<h2 id="heading-umami">umami</h2>
<p><a target="_blank" href="https://umami.is/">umami</a> (<a target="_blank" href="https://app.umami.is/share/ISgW2qz8/flightphp.com">demo</a>) is a solution created with Next.js, making it very easy to deploy. In my case, used Vercel.</p>
<p>On top of unique visitors, page views, average time on site, bounce rate, top pages, and top referrers, umami also shows you information about countries, browsers, OS and device data.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/umami.jpg" alt="umami screenshot" width="600" height="400" loading="lazy"></p>
<h2 id="heading-plausible">Plausible</h2>
<p>I think I first heard about <a target="_blank" href="https://plausible.io/">Plausible</a> (<a target="_blank" href="https://plausible.io/plausible.io">demo</a>) in the "<a target="_blank" href="https://changelog.com/podcast/396">De-Google-ing your website analytics</a>" Changelog podcast. From a product perspective, it is nice to see a <a target="_blank" href="https://plausible.io/roadmap">public roadmap</a> out in the wild so customers can learn what is coming next.</p>
<p>Their plans start at $6/month and go up according to your page views - like Fathom. They also have an <em>alpha</em> self-hosted option, but I didn't have a chance to test it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/09/plausible.jpg" alt="plausible" width="600" height="400" loading="lazy"></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>There are alternatives out there, and you don't need to worry about a big corp looking at you or your users with these options. Each service's setup time is very similar, and once you're done, you can add multiple sites just like you would with Google Analytics.</p>
<p>I don't have a favorite. Feature-wise, umami provides all the basic information you would want to know for free. It's also very easy to set up on services like Vercel or Netlify. </p>
<p>Both Fathom and Plausible offer free trials so you can easily test their solutions before deciding.</p>
<p><em>Do you know another minimalist, open source alternative to Google Analytics? Let me know in the <a target="_blank" href="https://leonardofaria.net/2020/09/01/three-privacy-focused-open-source-google-analytics-alternatives/">comments</a> section of my blog.</em></p>
<p>If you liked this article, follow me on <a target="_blank" href="https://twitter.com/leozera">Twitter</a> and <a target="_blank" href="https://github.com/leonardofaria">GitHub</a>. </p>
<p>Cover photo by <a target="_blank" href="https://unsplash.com/photos/IrRbSND5EUc">Markus Winkler/Unsplash</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Why Site Speed is Critical for SEO – and How to Speed Up Your Site ]]>
                </title>
                <description>
                    <![CDATA[ By Adam Naor No one likes to wait for a site to load. I don’t. You don’t. And search engines really don’t.  While UX, keyword density, and site structure (among other things) dominate SEO and ranking-related conversations, site speed should play a mo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/why-site-speed-is-critical-for-seo-and-how-to-speed-up-your-site/</link>
                <guid isPermaLink="false">66d45d93cc7f04d2549a3716</guid>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ user experience ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ux design ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 20 Aug 2020 20:59:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/08/site-speed-thumb-1024x640.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Adam Naor</p>
<p>No one likes to wait for a site to load. I don’t. You don’t. And search engines really don’t. </p>
<p>While UX, keyword density, and site structure (among other things) dominate SEO and ranking-related conversations, site speed should play a more prominent role.</p>
<p>I have been working to build my own website and have learned valuable lessons about site speed along the way. </p>
<p>I want to pass these lessons on to you.</p>
<h2 id="heading-google-made-a-site-speed-specific-algorithm-update">Google Made a Site Speed-Specific Algorithm Update</h2>
<p>Everyone knows that site speed has a place in SEO talk. </p>
<p>But, did you know that in 2018 Google published a site speed-specific change to their algorithm? Called “the speed update,” the changes made a mobile site’s speed play a more prominent role in search as well as ads.</p>
<p>The update was necessary as well. At the time of its release, Google’s research showed that the chances of bounce increased 32% if site load time went up from one second to three seconds. </p>
<p>Bounce rate chances also increased to 90% if it went up to five seconds and 123% at 10 seconds or more. </p>
<p><img src="https://lh6.googleusercontent.com/vdM-PAyY1-_zy5TQLs8CxHjGM8sGQr0pd9bOccyOqY05-3FPJN1zL5IpsRCz9nSpAt2yqq4aloCxQ42iTe-P6Vurb8NaXLkLmmLpoeGfM2xlWWVwMPk3RfDK2i1FA8-applKB3ND" alt="Image" width="1600" height="920" loading="lazy"></p>
<p>The change certainly had a positive impact on the online user experience. User-centric performance metrics improved by 15% to 20%, and cart abandonment went down by 20% within a few months after the update was released. </p>
<p>So, what does it all mean?</p>
<p>Essentially: those with well-optimized pages will rank higher in search engines for their target keywords.</p>
<p>Conduct a keyword gap analysis, a process defined by Loganix as "identifying valuable keywords that your competitors rank well for, but you do not.”</p>
<p>When you find valuable keywords your competitors do not rank for, focus heavily on optimizing these pages for speed to increase the gap even further.</p>
<h2 id="heading-site-speed-affects-purchase-intent">Site Speed Affects Purchase Intent</h2>
<p>The importance of site speed goes beyond rankings alone. Google conducted a thorough review of mobile site speed’s impact on consumer willingness to spend. </p>
<p>Their report, called <strong>Milliseconds Make Millions</strong>, showed a massive ripple effect down the buyer journey from even a 0.1 second change in load time. </p>
<p><img src="https://lh3.googleusercontent.com/FaluCKDR9mmsQ96Pkptvsf60tR7ABiWf3CW5vH8ysR2dqsDZreWgQtScHtQl0kYFsMPXUolKK8fX_Gri8MAio0bb1BQsdNBm8rCapjKSa-AMHPlUPpUiCc863IZLCj78KcyTJBol" alt="Image" width="600" height="400" loading="lazy"></p>
<p>For example, a 0.1% decrease in a retail site’s load time caused a 9.2% increase in online spending. </p>
<p>For luxury brands, a similar increase in performance led to a 40% increase in site browsing and items being added to the cart. </p>
<p>Similar studies have found the same relationship between consumer activity and site load times. Google has said that two seconds is the ideal maximum site load time for an e-commerce site.</p>
<h2 id="heading-better-site-speed-is-a-hidden-competitive-advantage">Better Site Speed Is a (Hidden) Competitive Advantage</h2>
<p>So, we have established that Google loves a fast loading site, as do users. And yet most webmasters aren’t really paying attention. </p>
<p>You should.</p>
<p>A survey of 5.2 million mobile and desktop website pages found that most site load times were woefully inadequate. </p>
<p><img src="https://lh5.googleusercontent.com/CBPv4zNxOZTFT1gmr6aTMHRGj8h2XyPCRNJniB2gpfC5Y6QBFDdgWv0xE4s0s6wI2nssXZEz9nw-RvZmBVQ45mFTaTS0PKwcI0uxNqSk_0PykD7wqXqqx7K55PnXWxY3UqTQr_Kk" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://backlinko.com/page-speed-stats">Image Source</a></em></p>
<p>For example, the average load time for a desktop page in this study was 10.3 seconds, while that of a mobile webpage was 27.3 seconds. </p>
<p>The average web page also takes 87.4% longer to load on mobile than desktop. </p>
<p>This is a huge opportunity for anyone who’s reading this. You can easily out-flank your competition simply by improving your site speed. </p>
<p>Not only will doing so increase your SERP presence, but it can bring down your bounce rate while increasing traffic too. </p>
<p>Reducing your site load time isn’t really all that difficult either. Here are three ways to do just that.</p>
<h2 id="heading-optimize-your-sites-file-size">Optimize Your Site’s File Size</h2>
<p>A website consists of various HTML, JavaScript, and CSS files which dictate how it will appear and function. These files also take up a lot of space, especially if they are coded inefficiently. </p>
<p><img src="https://lh4.googleusercontent.com/WvFv6Po5-WtGCdqRcgH6yxakunfod12jiTSZsueFwSq4nD5BLq7FOYj46ELR9rVYzgQ5pFXd0rJWGZo-hKx27afB15mGgO1TL_NdChJgWtKjMXi-XPd5fSSWiCtGAv0DX29zHCih" alt="Image" width="690" height="537" loading="lazy">
<em><a target="_blank" href="https://blog.hubspot.com/marketing/reduce-http-requests">Image Source</a></em></p>
<p>The first step here will be to reduce the number of requests your website files are causing. </p>
<p>An HTTP request is generated by each on-page element. The more elements your site has, the more requests it generates. Alas, this leads to slower site loads.</p>
<p>You can use Google Chrome’s <strong>Network Panel</strong> to find the number of HTTP requests a page is generating. Make a note of unnecessary requests and take them out. </p>
<p>An easier way here will be to simply combine similar HTML, JavaScript, and CSS files. So, instead of having multiple HTML files, copy all the code into one file. </p>
<p>Repeat for JavaScript and CSS. Fewer files will generate fewer HTTP requests, thereby decreasing your site load time.</p>
<p>Minifying your site code will also greatly help. Look for removable pieces of code, line breaks, and whitespace in your website’s files. While minification can be done manually, there are tools available as well:   </p>
<ul>
<li>Terser is a very popular JavaScript compression tool.</li>
<li>HTMLMinifier is ideal for dealing with HTML files.</li>
<li>CSSNano can be used to compress CSS files. </li>
</ul>
<p>If you have interactive elements of your website, these can often slow things down. </p>
<p>What is defined as interactive? Well, here is a great example from Preply:  </p>
<p><img src="https://lh4.googleusercontent.com/FFWhKZzfgJioV4_2LfRlRRDw8CE2q_arkefolqq-I5i2T--Y0kZ0dfOzEzeX7IPt2gZVMXYbYYW90gCYgFL6pfAmE3gkMpVdX7tLSs3Mlgu-mRR_hDt9hCArhDssozz7jXw0ZJ29" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Each time you click on the world map, it pulls more information. </p>
<p>If not correctly optimized and cached, this can slow load times dramatically.</p>
<p>Work with a developer to ensure your code is minimal and efficient.</p>
<h2 id="heading-optimize-your-site-images">Optimize Your Site Images</h2>
<p>While images are essential to a good online experience, they can quickly eat into your site load time. This is especially true for e-commerce sites that use a lot of images, like Sleep Junkie, pictured here.</p>
<p><img src="https://lh4.googleusercontent.com/1LxMPTbdolG0Y--IJoChRjRs3ddWqLVzyI6TuO5_mPtsyadjJYf98qrlW1jXjeUhQZHHxz66vZxqyd1HvWaUx_GAHzaQS1ZxvsDRgAopx9SYQ_JCAbzVJmi2qPKlIBFL8DA_RFOi" alt="Image" width="534" height="725" loading="lazy">
<em><a target="_blank" href="https://www.sleepjunkie.org/sleep-health/">Image Source</a></em></p>
<p>Even though most web pages weigh in at a hefty 2 MB these days, Google recommends keeping them under 500 KB. Of course this presents a challenge since images are usually the heaviest on-page component.</p>
<p>Compressing images is also a fine balancing act, since it reduces image quality. The best place to start will be selecting an appropriate image format. </p>
<ul>
<li>PNG images are high quality, but tend to be heavier so are ideal for simple drawings and text images.</li>
<li>JPEG uses lossy compression and allows for better quality-size ratios, so can be used for regular photographs and complex graphics.</li>
<li>Finally, Gifs are simple, low-resolution repeating images.</li>
</ul>
<p>There are several ways you can use high quality images without adding to your site’s load time. A Content Delivery Network like AWS Cloudfront can be used to offload your images which can be served on demand. </p>
<p>Secondly, you can also set up your CMS to scale images site-wide. This way you can create a template for thumbnail images and how their full versions are displayed. </p>
<p>If you use WordPress, consider using the Imsanity plugin to setup image compression.</p>
<p>Alternatively, you can also use free web-based image compressors like Jpeg-Optimizer, Optimizilla, and Kraken to manually compress your site images.</p>
<h2 id="heading-optimize-your-sites-videos">Optimize Your Site’s Videos</h2>
<p>Videos are usually the single biggest files your website can have.</p>
<p>So, even if you do keep the number of videos down, even a single file can slow down load time considerably. Like images, however, you have several options to compress video files to manageable limits. </p>
<p>It’s also best to move to an HTML5 video format like MP4 or WebM. Both are supported by most browsers and allow for acceptable compression-quality ratios. </p>
<p>You can use a video compression tool like Handbrake to reduce your video file sizes without sacrificing (much) quality too. Also, consider removing audio from videos that are muted. </p>
<p>A CDN can again be used to serve videos on demand here. While auto playing videos are best avoided, they should be set to play once the webpage has loaded completely. </p>
<p>Alternatively, you can simply embed your videos using a video streaming service like YouTube or Wistia.</p>
<p>This allows your site to send small chunks of content to the user, speeding up load times. </p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Site load times are only going to become more important moving forward. </p>
<p>Embed that learning into your technical learnings today. Change how you design and build.</p>
<p>It’s best to make these learnings an integral part of your digital strategy. </p>
<p>Alternatively, you can have a SEO agency take care of it for you. Since image optimization is part of SEO, a targeted campaign can help you create a properly formatted site right from the get go.</p>
<p>The choice is yours and your users – like Search Engines – will reward this attention to detail.   </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to set up and track YouTube Channel performance with Google Analytics ]]>
                </title>
                <description>
                    <![CDATA[ Managing a YouTube channel is a lot of work. It includes content experimentation which can make or break your SEO effectiveness for your channel. How can we track our channel’s performance to see what works? Why is SEO important? How is SEO importan... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-up-and-track-youtube-channel-performance-with-google-analytics/</link>
                <guid isPermaLink="false">66b8e36893a17625e9eef10f</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #content marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Wed, 18 Mar 2020 13:27:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/03/youtube-analytics-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Managing a YouTube channel is a lot of work. It includes content experimentation which can make or break your SEO effectiveness for your channel. How can we track our channel’s performance to see what works?</p>
<ul>
<li><a class="post-section-overview" href="#heading-why-is-seo-important">Why is SEO important?</a></li>
<li><a class="post-section-overview" href="#heading-how-is-seo-important-to-youtube">How is SEO important to YouTube?</a></li>
<li><a class="post-section-overview" href="#heading-and-what-is-google-analytics">And what is Google Analytics?</a></li>
<li><a class="post-section-overview" href="#heading-how-do-i-connect-my-channel">How do I connect my channel?</a></li>
<li><a class="post-section-overview" href="#heading-what-will-i-be-able-to-see">What will I be able to see?</a></li>
<li><a class="post-section-overview" href="#heading-what-wont-i-be-able-to-see">What won’t I be able to see?</a></li>
<li><a class="post-section-overview" href="#heading-what-else-can-i-do-with-youtube-and-google-analytics">What else can I do with YouTube and Google Analytics?</a></li>
</ul>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/P8wv4ylc_-s" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-why-is-seo-important">Why is SEO important?</h2>
<p><a target="_blank" href="https://moz.com/learn/seo/what-is-seo">SEO, or Search Engine Optimization</a>, is the practice of writing and organizing content in a way that search engines like Google can crawl and ultimately understand what your website or YouTube channel is about.</p>
<p>Using this information, Google and others make decisions with their algorithms to determine which content is of higher quality, more relevant, and more likely to answer the question you’re looking for on their search engine in the first place. With that information, the search engines rank this content and display their results ordered by those rankings.</p>
<h2 id="heading-how-is-seo-important-to-youtube">How is SEO important to YouTube?</h2>
<p>Just like any other website, YouTube gets crawled by Google and other search engines. Additionally, YouTube has its own internal search that will take these same things into consideration when deciding how to display results on a YouTube search.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/searching-for-code-channels-on-youtube.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Searching for "code" channels on YouTube</em></p>
<p>This means, depending on how well you create your descriptions, manage your keywords, or name your videos, it could impact how well your videos rank in the results. And this can impact how many views your videos get.</p>
<p>This also applies to your channel. You have opportunities to experiment with effectiveness through the content you feature, your channel description, and the name of your channel.</p>
<h2 id="heading-and-what-is-google-analytics">And what is Google Analytics?</h2>
<p>Google Analytics is a <a target="_blank" href="https://analytics.google.com/analytics/web/">free analytics tool</a> from Google that will allow you to gain better insights into your traffic. I previously wrote about <a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/">what is Google Analytics and how you can make sense of it</a> which provides a more in depth view. So if you want to learn a little more before diving in, I highly recommend starting there.</p>
<h2 id="heading-how-do-i-connect-my-channel">How do I connect my channel?</h2>
<h3 id="heading-setting-up-a-new-tracking-code">Setting up a new tracking code</h3>
<p>To start, we’ll need a tracking code from Google Analytics. Google has some great up to date resources on how to do this, so I'm not going to try to re-explain here:</p>
<ul>
<li><a target="_blank" href="https://support.google.com/analytics/answer/1042508">Setting up a new property</a></li>
<li><a target="_blank" href="https://support.google.com/analytics/answer/1008080?hl=en">Getting your Tracking ID</a></li>
</ul>
<p>Though some say you can use your website’s property and create a filtered View, I recommend starting with a separate property. That way you don’t have to worry about any data crossover or setting up complicated filters.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-tracking-id.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Tracking ID in Google Analytics</em></p>
<p>Your tracking ID will be in the following format: <code>UA-######-#</code>. Once you have that, we're ready to go.</p>
<h3 id="heading-adding-your-tracking-code-to-youtube">Adding your tracking code to YouTube</h3>
<p>There are a few steps we have to navigate through to find where we can set up our Google Analytics account. If you want to skip to the right place, you can visit <a target="_blank" href="https://www.youtube.com/advanced_settings">youtube.com/advanced_settings</a>.</p>
<p>To take the long route, which will also help you get a little more familiar with your YouTube account, first head over to the <strong>Settings</strong> section from within your <strong>YouTube Studio</strong> page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/youtube-studio-channel-settings.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Finding Settings on your YouTube Studio dashboard</em></p>
<p>Once selected, find the <strong>Advanced channel settings</strong> link by visiting <strong>Channel</strong>, <strong>Advanced Settings</strong>, and then scrolling down to the bottom.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/youtube-advanced-channel-settings.jpg" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Advanced channel settings</strong> on YouTube</em></p>
<p>Finally, scroll down to the bottom of the page again, find the <strong>Google Analytics property tracking ID</strong> field, enter the tracking ID you created, and hit save.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/youtube-advanced-channel-settings-google-analytics-property-1.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Setting the Google Analytics property tracking ID for your YouTube channel</em></p>
<h3 id="heading-sit-back-and-wait">Sit back and wait</h3>
<p>Google Analytics will only show your website traffic from the point it was set up and through the future. Unfortunately we can’t check out that weekend your video first went viral if you didn’t have Google Analytics set up then, but at least we’re prepared for the next time!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/friends-recline-chair.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Joey and Chandler reclining their chairs</em></p>
<p>That said, now's the time to continue working hard on your channel since you have the ability to track how that hard work is paying off as people visit your channel.</p>
<h3 id="heading-optional-setting-up-site-search">Optional: Setting up Site Search</h3>
<p>Setting up <a target="_blank" href="https://support.google.com/analytics/answer/1012264?hl=en">Google Analytic’s Site Search</a> feature gives us an easy way to separate out search usage to make it easier to gain insight into how people are searching our channel.</p>
<p>To enable Site Search, we want to go to the <strong>Admin</strong> section of our Google Analytics property and then navigate over to <strong>View Settings</strong>. Once there, under the <strong>Site Search</strong> settings at the bottom, first click the button to toggle on <strong>Site search Tracking</strong>, then type “query” into the <strong>Query parameter</strong> input.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-site-search-tracking.jpg" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Site search Tracking</strong> in Google Analytics</em></p>
<p>Optionally, though recommended, you can select to strip query parameters out of your URL. This means that in your main content view, you will see all traffic as /search instead of many instances of /search?query=[keyword], which can be more cumbersome to analyze.</p>
<p><em>Note: before you set this up, it’s <a target="_blank" href="https://www.e-nor.com/blog/google-analytics/best-practices-views-google-analytics">generally recommended to have more than one view for your property</a>. I would recommend having at least 2 views, a Raw Data view and Main view. You would only apply the Site Search feature to your Main view. This will help to make sure you can always see the unfiltered Raw Data view if you want.</em></p>
<h2 id="heading-what-will-i-be-able-to-see">What will I be able to see?</h2>
<h3 id="heading-how-many-people-visited-my-channel">How many people visited my channel?</h3>
<p>The first thing we get immediately with our new data when we open up our Google Analytics property is how many people visited our site.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-home.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Analytics Home</em></p>
<p>The default here is in the past 7 days, but you can change the time range in the bottom left corner of the panel.</p>
<p>What this also provides is a quick insight into how the number of people has changed since the previous period (the 7 days before in this example). As we can see here, the number of people this week has increased by 13.9% which is awesome news for freeCodeCamp’s YouTube channel, proving whatever they did is working.</p>
<h3 id="heading-how-are-people-finding-our-channel">How are people finding our channel?</h3>
<p>So how do we figure out if the strategies we’re using (like SEO) to get people to our channel are effective? By analyzing our organic search traffic.</p>
<p>By navigating to the <strong>Source/Medium</strong> report by visiting <strong>Acquisition</strong>, <strong>All Traffic</strong>, then <strong>Source/Medium</strong>, we can see what sources are providing our YouTube channel the most traffic.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-source-medium-report.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Source/Medium report in Google Analytics</em></p>
<p>By clicking in to <strong>google / organic</strong>, we can also see how this has changed over time.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-organic-google-referral-report.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Organic Google traffic report in Google Analytics</em></p>
<p>While analyzing a single week isn’t the most effective, being able to tell how your organic traffic has changed over multiple weeks will be able to tell you if your strategy is working.</p>
<h3 id="heading-what-websites-and-pages-are-people-coming-from">What websites and pages are people coming from?</h3>
<p>Navigating to the <strong>Referrals</strong> report by going to <strong>Acquisition</strong>, <strong>All Traffic</strong>, and then <strong>Referrals</strong>, we can see that most of the referral traffic for the <a target="_blank" href="https://www.youtube.com/channel/UC8butISFwT-Wl7EV0hUK0BQ">freeCodeCamp YouTube</a> is from <a target="_blank" href="https://www.freecodecamp.org/">freeCodeCamp.org</a> itself.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-freecodecamp.org-referral-traffic.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Referral traffic showing freecodecamp.org as highest referrer in Google Analytics</em></p>
<p>But say we want to see what pages those referrals are coming from. We can find this out by clicking on the <strong>freecodecamp.org</strong> link in the view above where we can see a full breakdown of which pages are giving the channel the most traffic.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-referring-pages-from-freecodecamp.org.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>freecodecamp.org referral pages on Google Analytics</em></p>
<h3 id="heading-what-are-people-searching-for-on-my-channel">What are people searching for on my channel?</h3>
<p>After setting up <a target="_blank" href="https://support.google.com/analytics/answer/1012264?hl=en">Site Search</a> on your Google Analytics account, you’ll be able to get better insight into how people are actually searching your site.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-search-terms.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Search Terms report in Google Analytics</em></p>
<p>Here we can see what keywords people want to see the most, meaning we can tailor our content and future videos to those keywords, making our channel more effective.</p>
<h3 id="heading-more-insights">More insights</h3>
<p>By default, you’ll get a lot of other cool insights from Google Analytics that are baked in like where your visitors are physically located and whether they’re visiting on a desktop or mobile device.</p>
<p>To learn more about what you can see, check out <a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/">my article on making sense of Google Analytics</a>.</p>
<h2 id="heading-what-wont-i-be-able-to-see">What won’t I be able to see?</h2>
<p>While the information you’ll discover through Google Analytics is important, it’s not all inclusive. There are many points you’ll need to dive into YouTube’s own Analytics tool to see.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/youtube-studio-analytics-dashboard.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Analytics dashboard in YouTube Studio</em></p>
<h3 id="heading-video-analytics">Video analytics</h3>
<p>Video states and actions aren’t going to be visible in Google Analytics, which includes things like Play, Pause, and time watched.</p>
<p>However, by using the <strong>Engagement</strong> tab in the <a target="_blank" href="https://studio.youtube.com/">YouTube Studio</a> <strong>Analytics</strong> section, we can see how long people are watching our videos and a graph of the <strong>Audience retention.</strong> This will help us determine how the content of our videos is performing.</p>
<h3 id="heading-subscribers">Subscribers</h3>
<p>You’re not going to be able to gain insights into how the visitors on your channel are subscribing.</p>
<p>The good news is you can find this by visiting the the <strong>Analytics</strong> section in your YouTube Studio page, then clicking the <strong>Audience</strong> tab at the top.</p>
<h3 id="heading-dig-in-to-youtube-studio-analytics">Dig in to YouTube Studio Analytics</h3>
<p>There’s a whole lot you can find out if you dig around YouTube Studio Analytics. Take the time to poke around both Analytics report solutions and learn what information is most useful to providing an impactful experience for your channel.</p>
<h2 id="heading-what-else-can-i-do-with-youtube-and-google-analytics">What else can I do with YouTube and Google Analytics?</h2>
<h3 id="heading-track-links-from-youtube-to-your-website">Track links from YouTube to your website</h3>
<p>If you have a website outside of your YouTube channel and have Google Analytics set up on it, you can build custom URLs that will allow you to see your YouTube traffic as a campaign. This is useful not only for YouTube, but any other source you’re directing traffic to your website from.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/03/google-analytics-campaign-url-builder.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Building campaign URLs <a target="_blank" href="https://ga-dev-tools.appspot.com/campaign-url-builder/">Campaign URL Builder</a></em></p>
<p>Google Analytics provides this capability using URL parameters attached to the links. You can learn more about the setup and what you need to do with <a target="_blank" href="https://support.google.com/analytics/answer/1033863?hl=en">Google’s Analytics Help site</a>.</p>
<p>It should also be noted that you don’t really need to set up your YouTube channel with Google Analytics to make use of this feature.</p>
<h3 id="heading-track-how-videos-are-watched-when-embedded-on-your-website">Track how videos are watched when embedded on your website</h3>
<p>YouTube provides an <a target="_blank" href="https://developers.google.com/youtube/iframe_api_reference">API</a> that developers can use to write custom JavaScript and track usage of embedded videos on a given website.</p>
<p>Using this, we can send custom events based on time references or video actions (like play and pause) to get a better idea of how the videos on our site are being used.</p>
<p>To be clear – this is only for videos embedded on your website and will probably track usage with your website's Google Analytics property unless you configure it otherwise.</p>
<p>Check out <a target="_blank" href="https://developers.google.com/youtube/iframe_api_reference">YouTube iFrame Player API</a> for more info.</p>
<h3 id="heading-pretty-much-anything-google-analytics-provides-by-default">Pretty much anything Google Analytics provides by default</h3>
<p><a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/">There’s a whole lot you can do with Google Analytics</a>, whether it’s getting better visibility into where people are coming from or where they’re physically located. And by connecting your YouTube channel you automatically get those insights.</p>
<h2 id="heading-the-more-resources-the-more-insight-you-can-gain">The more resources, the more insight you can gain</h2>
<p>Though there are benefits to both YouTube Analytics and Google Analytics, having more information will ultimately help you make better judgement calls about how you manage your channel and content. Use these tools to help launch yourself to inevitable YouTube stardom!</p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to use Google Tag Manager to maintain Google Analytics and other marketing tags ]]>
                </title>
                <description>
                    <![CDATA[ Managing code snippets and pixels on your website or app to measure traffic can be a little bit stressful, especially if you have a marketing team that constantly needs to make changes. Luckily, there are tools out there like Google Tag Manager that ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-google-tag-manager-to-maintain-google-analytics-and-other-marketing-tags/</link>
                <guid isPermaLink="false">66b8e377c9bc6d235bb126b0</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #content marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Digital Marketing  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ front end ]]>
                    </category>
                
                    <category>
                        <![CDATA[ frontend ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ google tag manager ]]>
                    </category>
                
                    <category>
                        <![CDATA[ marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #reporting ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ website development, ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Wed, 20 Nov 2019 16:04:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/11/take-control-of-your-marketing-tags.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Managing code snippets and pixels on your website or app to measure traffic can be a little bit stressful, especially if you have a marketing team that constantly needs to make changes. Luckily, there are tools out there like Google Tag Manager that will make them a little easier to wrangle.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/giphy.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Sandy wrangling</em></p>
<h2 id="heading-what-is-google-tag-manager"><strong>What is Google Tag Manager?</strong></h2>
<p>If you’ve ever worked with any kind of analytics software, or you have worked with a marketing team before, you’ve probably heard the word pixel thrown around. A pixel is literally what it sounds like: a 1x1 image that sends information to a server through an image request.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-analytics-pixel-request.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Analytics pixel request</em></p>
<p>Though pixels are still common, many teams have moved towards small javascript snippets that sit right along side the rest of your HTML. They will allow software like Google Analytics to run their own scripts on your page, sometimes even with a pixel backup, in the event that a browser doesn't run JavaScript.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/crazy-egg-tracking-snippet.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Crazy Egg snippet</em></p>
<p>These pixels and snippets work great. But when you’re dealing with a bunch of them and they all use the same data, it might seem like you’re just adding to an unmanageable mess of single use code snippets that never feel like they’re in the right place.</p>
<p>Google Tag Manager, or GTM, is a software solution to manage these pixels and snippets for you. To start, GTM works pretty much like any of those other code snippets, as it’s a code snippet itself. But where it shines is that you get to manage the rest of those pixels and snippets along with the flow of data inside GTM, leaving it to be the only snippet to manage within your code.</p>
<h2 id="heading-why-do-i-want-to-use-it"><strong>Why do I want to use it?</strong></h2>
<h3 id="heading-fewer-code-changes-fewer-deploys"><strong>Fewer code changes, Fewer deploys</strong></h3>
<p>Most of the time, if you’re managing these snippets in your code, each change will require another merge request and another deploy to get the changes out. Not only does this add more risk, as you need to make yet another change to the code, but this is additional time spent dealing with your deploy pipeline and making sure everything is working as it should be. </p>
<p>GTM allows you to break outside of that flow, giving you more flexibility to get changes out that could give some needed insight into fixing some UI errors or could add a few bucks to the bottom line.</p>
<h3 id="heading-more-manageable-data-flow"><strong>More manageable data flow</strong></h3>
<p>Wrangling all the different variables throughout your application, making sure they’re all available in the right spot, and keeping up with avoiding breaking any changes can prove to be challenging. This also makes your code more fragile and prone to breaking. </p>
<p>Google Tag Manager utilizes what they call a <code>dataLayer</code>, which essentially functions like an array of events that it listens to. This allows you to push or seed new data to make available within GTM itself. And it means you’re funneling all of your variables to one spot in the code. This lets whoever manages GTM do the rest – they can use that data with peace of mind, knowing that your data flow won’t break after forgetting to update 1 out of 10 spots.</p>
<h3 id="heading-ability-to-give-marketers-a-little-more-access"><strong>Ability to give marketers a little more access</strong></h3>
<p>This is an opportunity to free up some of your time by letting the marketing team deal with tag changes themselves rather than you being the middle man for them. Perhaps they need to adjust the ID for your analytics software or maybe they want to add <a target="_blank" href="https://www.crazyegg.com/">Crazy Egg</a>. With the right permissions (explained later), they can do all of the work and send the changes to you for review before publishing them.</p>
<h2 id="heading-how-does-this-relate-to-google-analytics"><strong>How does this relate to Google Analytics?</strong></h2>
<p>There is no direct relation. But along with Google Analytics, GTM is another tool in the Google Marketing Platform and gives you the immediate ability to more easily manage your Google Analytics installation. GA comes with prebuilt tags inside GTM that make it a breeze to set up.</p>
<h2 id="heading-what-else-can-i-use-this-for"><strong>What else can I use this for?</strong></h2>
<p>Google Analytics is just one of many code snippets this can be used for. Ideally, you’re not going to write your entire site here. But you have the ability to pretty much do whatever you want on your own site as long as <a target="_blank" href="https://support.google.com/tagmanager/answer/6328489?hl=en">Google doesn’t deem it malware</a>.</p>
<p>Some other use cases include:</p>
<ul>
<li>Traffic visualization with <a target="_blank" href="https://www.crazyegg.com/">Crazy Egg</a> or <a target="_blank" href="https://www.hotjar.com/">Hot Jar</a></li>
<li>Conversion and remarketing pixels with <a target="_blank" href="https://ads.google.com/home/">Google Ads</a></li>
<li>A/B Testing with <a target="_blank" href="https://marketingplatform.google.com/about/optimize/">Google Optimize</a> or <a target="_blank" href="https://www.abtasty.com/">AB Tasty</a></li>
<li><a target="_blank" href="https://support.google.com/tagmanager/answer/7679411?hl=en">Client side error</a> tracking (and logging them)</li>
<li>GDPR compliance management</li>
</ul>
<p>There are many baked-in like the examples above, meaning you don’t even need to mess with code. Just add the IDs or settings and go. But for whatever custom solution or tag you need, you can always set up the HTML manually.</p>
<h2 id="heading-anything-i-need-to-know-before-jumping-in"><strong>Anything I need to know before jumping in?</strong></h2>
<p>Before jumping right in, let’s familiarize ourselves with a few key terms that will make this ride a little easier.</p>
<h3 id="heading-tags"><strong>Tags</strong></h3>
<p>Tags in GTM are your pixels or code snippets. A tag includes a single instance of a contained piece of code that is used for one function.</p>
<p><em>Example:</em> your Google Analytics snippet will be one tag and if you add Crazy Egg, that will be another tag.</p>
<h3 id="heading-variables"><strong>Variables</strong></h3>
<p>A variable is a name that you give a predetermined or dynamic value. The variable can be based on a variety of different things, hence the name “variable”. But it will function as a single name that you can give and reference that will never change when using it.</p>
<p><em>Example:</em> we’ll set up your Google Analytics ID as a variable, meaning you’ll use that variable within the GA tag itself. If you ever need to update that ID, you won’t need to modify the tag or any other tags that use the variable – you’ll only need to update the variable itself.</p>
<h3 id="heading-triggers"><strong>Triggers</strong></h3>
<p>Triggers are the event or action that make your tag fire or load. This can happen in a variety of ways, such as when all or a specific page loads, when something is clicked, or when you have a <a target="_blank" href="https://support.google.com/tagmanager/answer/7679219?hl=en">completely custom event</a> you fire with Javascript.</p>
<p><em>Example:</em> when we set up Google Analytics, our trigger will be when any page loads.</p>
<h3 id="heading-container"><strong>Container</strong></h3>
<p>GTM allows you to manage multiple “containers” or groups of tags within your organization. This is helpful when you have one company with a few different website properties.</p>
<p><em>Example:</em> you’re a small company under a parent company. The parent company wants to maintain one organization, but each smaller company gets their own container, as they have their individual needs for tags and code snippets.</p>
<h2 id="heading-how-do-i-get-set-up"><strong>How do I get set up?</strong></h2>
<h3 id="heading-getting-your-account-set-up"><strong>Getting your account set up</strong></h3>
<p>The first thing you’ll need to do is get your account set up. After getting to the <a target="_blank" href="https://tagmanager.google.com/">tag manager homepage</a>, you’ll probably want to use your preexisting Google account. If you’re in an organization setting it up for the organization, you most likely want to use your business email, otherwise your personal account works okay too.</p>
<p>Next, create a new GTM account:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-new-account.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager new account</em></p>
<p>Once there, fill out the form appropriately. The Account Name should represent the top level of your hierarchy and the container name should represent the specific installation instance.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-new-account-container.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager new account container</em></p>
<p>As for the target platform, choose whichever makes sense. If it’s a website or web app, Web makes the most sense here.</p>
<h3 id="heading-finding-and-installing-your-snippet"><strong>Finding and installing your snippet</strong></h3>
<p>As soon as you accept the terms and hit create, you’ll be presented with a snippet in a little modal. You'll want to do exactly what it says and install the snippets per the instructions.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-install-snippet.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager install snippet</em></p>
<p>Didn’t get the screen or accidentally exited out? You can find your snippet again by navigating to Admin in the top navbar and then click Install Google Tag Manager under Container to the right.</p>
<h3 id="heading-testing-that-its-working"><strong>Testing that it’s working</strong></h3>
<p>To make sure it’s working, let’s verify a few things:</p>
<ul>
<li>We created our account</li>
<li>We created our container</li>
<li>We installed the Google Tag Manager snippets on our page and the change are live</li>
</ul>
<p>Once all of those things are true, go ahead and click the Preview button in the top right of the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-preview.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager preview</em></p>
<p>If successful, you’ll now see an orange banner at the top of the page that says you’re in Preview Mode:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-preview-mode.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager preview mode</em></p>
<p>Now wander over to the website that you installed GTM on and you should now see a banner at the bottom of the page. This will serve as your Debugger for working with GTM’s Preview.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-debugger.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager debugger</em></p>
<p>You should see something similar to that, which means it worked! ?</p>
<p>Note: if you have an ad blocker on, similar to GA, you may need to disable it on the page you’re installing on in order to see it working.</p>
<h2 id="heading-cool-its-working-what-about-google-analytics"><strong>Cool, it’s working, what about Google Analytics?</strong></h2>
<p>Now that we have a basic installation of GTM working, let’s set up Google Analytics. First we'll want to do some prep, so let's jump back over to the Tag Manager dashboard.</p>
<h3 id="heading-create-a-settings-variable"><strong>Create a settings variable</strong></h3>
<p>Navigate to Variables in the left sidebar and then click New beside User-Defined Variables.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-new-variable.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager new variable</em></p>
<p>For the name, enter “GA Settings” and under Variable Type, click through and select Google Analytics Settings. Enter your Google Analytics Tracking ID (or Property ID) in the appropriate field, and finally click Save, at which point you have your new settings variable.</p>
<h3 id="heading-create-a-new-ga-tag"><strong>Create a new GA tag</strong></h3>
<p>Navigate to Tags in the left sidebar and then click New beside Tags.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-new-tag.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager new tag</em></p>
<p>For the name, enter “GA - All Pages”. Under Tag Type, click and select Google Analytics: Universal Analytics in the panel that pops out from the right.</p>
<p>After selecting the tag type, under Google Analytics Settings, select your variable from the previous step, which if you followed along will be called “GA Settings”.</p>
<p>Next, click in the middle of the Triggering box, which should open a new UI to select a trigger.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-trigger.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager trigger</em></p>
<p>Select All Pages, which should be the only Trigger there if you’re in a new account. It will take you back to the New Tag UI with your newly selected trigger.</p>
<p>Once the above is done, click Save in the top right of the UI which will then save and create your new Google Analytics tag.</p>
<h3 id="heading-test-that-gtm-is-working"><strong>Test that GTM is working</strong></h3>
<p>Similar to when we installed GTM to begin with, let’s go back to the Workspace home by clicking Overview in the left sidebar. Then click Preview at the top right.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-debugger-google-analytics.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager debugger with Google Analytics</em></p>
<p>Open up your page GTM is installed on and you should once again see your Debugger, but this time with the Google Analytics Tag loading.</p>
<h2 id="heading-are-we-done-yet"><strong>Are we done yet?</strong></h2>
<p>Not quite. Although we have GA working, we need to tweak the configuration to make sure GA and GTM work correctly together.</p>
<h3 id="heading-updating-the-page-snippet"><strong>Updating the page snippet</strong></h3>
<p>Let’s dig into the code one more time to update our Google Analytics and Google Tag Manager snippets.</p>
<p>The issue with the installation that we set up here is that we installed GA through the GA instructions and GA inside GTM. This means we have GA installed twice. In practice, GA may send 1 pageview from your default installation and then another via GTM. To avoid this, we want to remove the pageview from the default GA snippet.</p>
<p>If you just have a super basic default installation, I did the work for you and you can go ahead and copy the snippet below. Replace <code>[YOUR GA PROPERTY ID]</code> with your GA Property ID and <code>[YOUR GTM CONTAINER ID]</code> with your GTM Container ID, and swap it out for your existing GA and GTM installation on your page.</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-comment">// Set up an initial dataLayer configuration</span>
<span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [{
  <span class="hljs-string">"gaPropertyId"</span>: <span class="hljs-string">"[YOUR GA PROPERTY ID]"</span>
}];

<span class="hljs-comment">// Configure gtag and your GA ID</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());
gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'[YOUR GA PROPERTY ID]'</span>);

<span class="hljs-comment">// Google Tag Manager snippet</span>
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">w,d,s,l,i</span>)</span>{w[l]=w[l]||[];w[l].push({<span class="hljs-string">'gtm.start'</span>:
<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime(),<span class="hljs-attr">event</span>:<span class="hljs-string">'gtm.js'</span>});<span class="hljs-keyword">var</span> f=d.getElementsByTagName(s)[<span class="hljs-number">0</span>],
j=d.createElement(s),dl=l!=<span class="hljs-string">'dataLayer'</span>?<span class="hljs-string">'&amp;l='</span>+l:<span class="hljs-string">''</span>;j.async=<span class="hljs-literal">true</span>;j.src=
<span class="hljs-string">'https://www.googletagmanager.com/gtm.js?id='</span>+i+dl+<span class="hljs-string">'&amp;gtm_cookies_win=x'</span>;f.parentNode.insertBefore(j,f);
})(<span class="hljs-built_in">window</span>,<span class="hljs-built_in">document</span>,<span class="hljs-string">'script'</span>,<span class="hljs-string">'dataLayer'</span>, <span class="hljs-string">'[YOUR GTM CONTAINER ID]'</span>);
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>This should REPLACE your current Google Analytics snippet if you have one. If you don't, this should go as far in the top of your <code>&lt;head&gt;</code> tag as you can, but under the <code>charset</code> meta tag.</p>
<p>For more advanced users, just make sure you’re not sending duplicate pageviews or duplicate events between the page snippet and any GTM tag you create.</p>
<h3 id="heading-test-that-ga-is-working"><strong>Test that GA is working</strong></h3>
<p>Follow the steps above to make sure GA is showing up with the debugger.</p>
<p>The final thing you’ll want to do is make sure your installation is working using <a target="_blank" href="https://chrome.google.com/webstore/detail/tag-assistant-by-google/kejbdjndbnbjgmefkgdddjlbokphdefk?hl=en">Google’s Tag Assistant extension</a>. Once you install the extension, go back to your page and click Enable in the Extension’s UI.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-assistant-record.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Assistant enable recording</em></p>
<p>Refresh the page and you should see 2 tags, GA and GTM.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-assistant-results.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Assistant results</em></p>
<p>If you notice, my GA tag is blue and yours may be too. Click in to Google Analytics for more info.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-assistant-implementation.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Assistant non-standard implementation</em></p>
<p>As you can see, we have a healthy 1 Pageview Request and a note that says Non-standard implementation (hence the blue) This is because we installed it with GTM instead of the default on page.</p>
<h2 id="heading-publish-and-deploy"><strong>Publish and Deploy!</strong></h2>
<p>We’re there! Last step is to Publish your Container and make the changes live.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-submit.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager submit version</em></p>
<p>Click Submit in the Overview UI, enter a name and description.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/google-tag-manager-version-configuration.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Google Tag Manager version configuration</em></p>
<p>Finally click Publish and your changes will be live on your site!</p>
<h2 id="heading-what-else-do-i-need-to-know"><strong>What else do I need to know?</strong></h2>
<p>There’s plenty more to talk through, but that’s for a different day. There are a ton of resources online to get you started with adding your own new tags and exploring the capabilities of Google Analytics, but here are a few points to keep in mind with GTM.</p>
<h3 id="heading-permissions"><strong>Permissions</strong></h3>
<p>You most likely don’t want every marketer on your 1,000 person team to have publish access to your GTM container. It’s best to have one or a few people responsible for managing the container, reviewing, and publishing while keeping everyone else to a lower access role. This will help prevent accidental changes or abuse within a bigger team.</p>
<h3 id="heading-security"><strong>Security</strong></h3>
<p>Permissions are your first step towards maintaining a secure installation. But Google takes this an extra step and performs some actions for you, such as checking for code errors and <a target="_blank" href="https://support.google.com/tagmanager/answer/6328489?hl=en">scanning for malware</a>. While this is great, it’s still important to keep an active review cycle of tags getting published, just like any other pieces of code, to make sure the site integrity and health remain in tact.</p>
<h3 id="heading-conventions"><strong>Conventions</strong></h3>
<p>I highly recommend starting early with naming conventions and best practices when configuring your tags, variables, triggers, and really anything within GTM. The different ways to name things can spiral out of control really quickly, depending on how many people are working in there. This will make your work difficult to find, so it’s best to agree with the team on a convention to use early and get off on the right foot.</p>
<h3 id="heading-single-page-apps"><strong>Single Page Apps</strong></h3>
<p>This doesn’t account for the impact single page apps have on a GTM and GA setup. The trigger we set up here will fire when any page loads, which is defined by a new page load by the browser. Single page apps don’t actually load a new page – rather, the JavaScript within the app makes it appear that a new page loads, so the trigger here will only fire the first pageview. Though it doesn’t include information directly usable in GTM, the GA documentation has <a target="_blank" href="https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications">some good information</a> about tracking these types of apps.</p>
<h3 id="heading-gdpr"><strong>GDPR</strong></h3>
<p>While GTM alone does not (currently) violate GDPR, you still need to be cognizant of how any of the tags you use impact your standing. This guide doesn’t touch this, so please make sure to do your homework.</p>
<h3 id="heading-exiting-out-of-debugger"><strong>Exiting out of Debugger</strong></h3>
<p>Stuck? One way is to clear your cookies, but you should always be able to go to the GTM Overview page and hit "Leave Preview Mode” right under the orange Preview Mode banner at the top of the page.</p>
<h2 id="heading-whats-next"><strong>What's next?</strong></h2>
<p>From here, you can start managing your tags and pixels through GTM, which allows you to have a single source of consistent data flow into those tags. Experiment and use the debugger to play around, as it opens the door for a lot of new ways to work with the marketing side of things.</p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>

<p><em>Originally published at <a target="_blank" href="https://www.colbyfayock.com/2019/11/how-to-use-google-tag-manager-to-maintain-google-analytics-and-other-marketing-tags">https://www.colbyfayock.com/2019/11/how-to-use-google-tag-manager-to-maintain-google-analytics-and-other-marketing-tags</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Make Sense of Google Analytics and the Traffic to Your Website ]]>
                </title>
                <description>
                    <![CDATA[ Google Analytics is a powerful web service that gives you insights into your website. But exactly can it help you? I’m going to cover a few things here. If you’re already familiar with the basics, feel free to skip around: What is Google Analytics? ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/</link>
                <guid isPermaLink="false">66b8e38047c23b7ae1ad0bdd</guid>
                
                    <category>
                        <![CDATA[ analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #reporting ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SEO ]]>
                    </category>
                
                    <category>
                        <![CDATA[ user experience ]]>
                    </category>
                
                    <category>
                        <![CDATA[ website development, ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Wed, 04 Sep 2019 14:32:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/09/making-sense-of-google-analytics.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://marketingplatform.google.com/about/analytics/">Google Analytics</a> is a powerful web service that gives you insights into your website. But exactly can it help <em>you</em>?</p>
<p>I’m going to cover a few things here. If you’re already familiar with the basics, feel free to skip around:</p>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/#what-is-google-analytics">What is Google Analytics?</a> (A quick overview)</li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/#okay-so-where-do-i-start">Okay, so where do I start?</a> (Quick start install guide)</li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/#what-are-some-quick-insights">What are some quick insights?</a> (Basic out of the box reports)</li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/making-sense-of-google-analytics-and-the-traffic-to-your-website/#bonus-advanced-insights">Bonus: Advanced Insights</a> (Custom Dimensions)</li>
</ul>
<p>So let’s start from the top.</p>
<h2 id="heading-what-is-google-analytics"><strong>What is Google Analytics?</strong></h2>
<blockquote>
<p>Google Analytics gives you the tools you need to better understand your customers. You can then use those business insights to take action, such as improving your website, creating tailored audience lists, and more. - <a target="_blank" href="https://marketingplatform.google.com/about/analytics/">Google's official documentation</a></p>
</blockquote>
<p>More simply put, Google Analytics (GA) is a web analytics service provided by Google on the <a target="_blank" href="https://marketingplatform.google.com/about/">Google Marketing Platform</a>. It allows you to track and measure your website’s traffic with powerful insights and reports.</p>
<p>GA can work a few different ways, but the most common is <a target="_blank" href="https://support.google.com/analytics/answer/1008080?hl=en">using a quick drop-in JavaScript snippet</a> that goes on every page of your website (typically the <code>&lt;head&gt;</code>).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-37.png" alt="Image" width="600" height="400" loading="lazy">
<em>Google Analytics lets you measure user interaction with websites.</em></p>
<p>The base version of Google Analytics is free. You have the option of upgrading to the 360 suite, which will open up some feature limits, but most of you probably don’t need this as it is more geared towards high traffic websites.</p>
<h3 id="heading-why-do-i-need-google-analytics"><strong>Why do I need Google Analytics?</strong></h3>
<p>You don’t <em>need</em> it. But you can get an incredible amount of insight from GA with even a basic out of the box setup. </p>
<p>GA is helpful if you're a developer trying to get more traffic out of your blog, or a business trying to optimize your sales funnel. </p>
<p>GA helps you answer simple questions like:</p>
<ul>
<li>Where is my traffic coming from?</li>
<li>What pages get the most traffic?</li>
<li>What are the most popular devices people visit on?</li>
</ul>
<p>Not only can this help you make better-educated decisions with your website. It can also help you unveil user experience concerns, or save money due to site issues by keeping an eye on traffic trends and user interactions.</p>
<h2 id="heading-okay-so-where-do-i-start"><strong>Okay, so where do I start?</strong></h2>
<p>Google makes it’s fairly easy for any developer to jump in and get started. The only real prerequisite is that you set up an account. Google themselves offers a great <a target="_blank" href="https://support.google.com/analytics/answer/1008015?hl=en">step-by-step and constantly updated guide</a>, so I’ll leave it to them.</p>
<h3 id="heading-getting-the-tag-on-your-page"><strong>Getting the tag on your page</strong></h3>
<p>Once you’re logged into the Google Analytics Dashboard, go to the Admin section, which you can find on the left hand side of the page:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-42.png" alt="Image" width="600" height="400" loading="lazy">
<em>Admin link in the Google Analytics Dashboard</em></p>
<p>Once in the admin section, you can navigate to Tracking Info then Tracking code under the property you want to track.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-43.png" alt="Image" width="600" height="400" loading="lazy">
<em>Tracking code link in the Google Analytics Admin</em></p>
<p>Finally, you can find the JavaScript snippet that you can throw in the head of your website. Remember, this should be on ALL pages.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-44.png" alt="Image" width="600" height="400" loading="lazy">
<em>Google Analytic tracking code snippet</em></p>
<h3 id="heading-let-the-traffic-flow"><strong>Let the traffic flow</strong></h3>
<p>From here you just have to give it time. Google Analytics won’t have historical data, it will only have the the new traffic that hit your page once the snippet was installed. </p>
<p>You can check it’s working by visiting the Realtime Report and either hitting the page in another tab or seeing your visitors hit the page.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-45.png" alt="Image" width="600" height="400" loading="lazy">
<em>Google Analytics Realtime Report</em></p>
<h3 id="heading-more-settings-more-configuration"><strong>More settings, more configuration</strong></h3>
<p>Google Analytics is a complex machine and can do a lot. Start slow and try to understand what’s happening before moving too fast turning every different switch. </p>
<p>Once you're comfortable, there are a lot of <a target="_blank" href="https://www.google.com/search?q=google+analytics+tips">great guides out there</a> for beginners and advanced users alike to unleash the full power of your reporting capabilities.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/super-saiyan.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Goku going Super Saiyan</em></p>
<h2 id="heading-what-are-some-quick-insights"><strong>What are some quick insights?</strong></h2>
<p>Cool, so you have GA installed, you see your traffic, and you’re ready to get started looking at your reports, but where to begin?</p>
<h3 id="heading-what-pages-get-the-most-traffic"><strong>What pages get the most traffic?</strong></h3>
<p>Let’s start with a simple one. Which pages of my website are getting the most traffic? To find this out we’ll want to view the Behavior Overview, which we can find by visiting Behavior then Overview.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-46.png" alt="Image" width="600" height="400" loading="lazy">
<em>Finding top page on Google Analytics Behavior Overview Report</em></p>
<p>Above we’re looking at the full month of August, which you can change with the date picker in the top right of the report. We can see overall, we had 3,853,265 total pageviews and 121,187 of them were to /news, the freeCodeCamp News homepage, which was our most popular page of the month.</p>
<h3 id="heading-where-is-my-traffic-coming-from"><strong>Where is my traffic coming from?</strong></h3>
<p>A common question is: “where are people coming from?” How are people actually finding my website? This is a 2 parter, let’s start with overall traffic.</p>
<p>A good way to start is by finding the Acquisition Overview page. You can navigate there by selecting Acquisition than Overview.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-47.png" alt="Image" width="600" height="400" loading="lazy">
<em>Finding top traffic source on Google Analytics Acquisition Overview Report</em></p>
<p>Shown above, the majority of traffic comes from organic searches on Google, a little over 75% in fact. That’s some good <a target="_blank" href="https://moz.com/beginners-guide-to-seo">SEO</a>!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-48.png" alt="Image" width="600" height="400" loading="lazy">
<em>Outstanding Move</em></p>
<p>But what if we wanted to see how people are getting to a particular post? This involves a little more work, but let’s dive in.</p>
<p>Let’s go back to Behavior in the sidebar, then Site Content, and finally Landing Pages. Once there, you can use the search to find your post as shown below and select it.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-49.png" alt="Image" width="600" height="400" loading="lazy">
<em>Searching for a page on the Google Analytics Landing Page Report</em></p>
<p>After you found your post, we’re going to add a Secondary dimension. In particular, we’ll want to find and select “Source / Medium” in the Secondary dimension dropdown.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-50.png" alt="Image" width="600" height="400" loading="lazy">
<em>Adding a Secondary dimension on the Google Analytics Landing Page Report</em></p>
<p>Finally we’ll have an idea of where people are coming from to visit our post.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-51.png" alt="Image" width="600" height="400" loading="lazy">
<em>Finding the top Source / Medium on the Google Analytics Landing Page Report</em></p>
<p>It seems like this is following the trend of great Organic SEO. If you notice though, we have “(direct) / (none)” as the second highest source / medium. </p>
<p>Unfortunately, it’s not always that easy. And if Google Analytics can’t figure out where the user came from, it will mark it as “(direct) / (none)”. <a target="_blank" href="https://moz.com/blog/guide-to-direct-traffic-google-analytics">While that’s solvable</a>, and sometimes actually means something, we can see the majority comes from simple searches on Google itself.</p>
<h3 id="heading-what-are-the-most-popular-devices-people-visit-on"><strong>What are the most popular devices people visit on?</strong></h3>
<p>Understanding what devices your visitors are using is an incredibly helpful tool for optimizing User Experience, as well as maximizing potential revenue by making sure your site works. </p>
<p>In a perfect world, your website would work in all browsers. But we may be able to safely rule out certain older browsers.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-52.png" alt="Image" width="600" height="400" loading="lazy">
<em>Internet Explorer behind a tree</em></p>
<p>To get started, find your way to Audience then Overview. Once there, select Browsers in the list as shown below.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-53.png" alt="Image" width="600" height="400" loading="lazy">
<em>Finding the top browser in the Google Analytics Acquisition Report</em></p>
<p>We can see that luckily, our top browsers are dominated by modern ones, with Chrome carrying a cool 76.42%. </p>
<p>But wait, Internet Explorer is pulling 1.06% or 22,499, which isn’t something to bat an eye at. So let’s dig in a little more by clicking on Internet Explorer.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-54.png" alt="Image" width="600" height="400" loading="lazy">
<em>Finding the traffic for Internet Explorer versions in the Google Analytics Acquisition Browser Report</em></p>
<p>Phew, I think we’re safe. Now we can see how many people visit each version of Internet Explorer and luckily almost 99% of THAT traffic is IE9 or above. While we should be as inclusive as we can, this can help us determine priority and make decisions on <a target="_blank" href="https://caniuse.com/">what browser versions to officially support</a>.</p>
<p>Real talk: 5 people on IE5? ?</p>
<h2 id="heading-bonus-advanced-insights"><strong>Bonus: Advanced Insights</strong></h2>
<p>Out of the box, Google Analytics is powerful, but with some customization and deeper integration with your web data, you can give your analytics dashboard extra superpowers.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/darkwing-duck-lets-get-dangerous.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Darkwing Duck Let's Get Dangerous</em></p>
<h2 id="heading-custom-dimensions"><strong>Custom Dimensions</strong></h2>
<p><a target="_blank" href="https://support.google.com/analytics/answer/2709829?hl=en">Custom Dimensions</a> are what Google specifies as “non-standard data.” Really, they’re just additional data points that we can configure to get a better understanding of what makes our website unique.</p>
<p>For the sake of this article (maybe a later one), I’m not going to go into how to add Custom Dimensions, but Google provides a <a target="_blank" href="https://support.google.com/analytics/answer/2709828?hl=en">great guide to get an in depth understanding</a> and a <a target="_blank" href="https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets">developer guide to go with it</a>. What I’ll go over here is how to explore our reports once some Custom Dimensions are already set up.</p>
<h3 id="heading-what-are-our-custom-dimensions"><strong>What are our Custom Dimensions?</strong></h3>
<p>To start, we’ll talk about 2 specific Custom Dimensions: Author and Page Category. </p>
<p>Author is what it sounds like, it’s the person who wrote the article. Page Category in our case is the primary, top-level category that represents the post. </p>
<p>On freeCodeCamp News, you can specify as many categories as you want (do so responsibly), but the first one in the list is consider your “primary” category and is used when you see your post in listing views such as the homepage.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-55.png" alt="Image" width="600" height="400" loading="lazy">
<em>Post on freeCodeCamp News Homepage</em></p>
<h3 id="heading-what-can-we-do-with-these"><strong>What can we do with these?</strong></h3>
<p>The great thing is when we set these up, we attribute them to a page view. Once that page view is collected by Google Analytics, we can use it to search on, which is really what makes it powerful. Let’s start with Author.</p>
<h3 id="heading-finding-all-posts-from-a-specific-author"><strong>Finding all posts from a specific Author</strong></h3>
<p>If we wanted to search for any post written by Quincy Larson, we’ll want to navigate back to <strong>Behavior</strong>, then <strong>Site Content</strong>, and finally <strong>All Pages</strong>.</p>
<p>Once there, we’ll want to add a <strong>Secondary dimension</strong>, similar when we added Source / medium, but now we’ll want to search for and select <strong>Author</strong>, which you’ll also find nested under the Custom Dimensions heading of that dropdown.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-56.png" alt="Image" width="600" height="400" loading="lazy">
<em>Selecting Author as a Secondary dimension on the Google Analytics Behavior Report</em></p>
<p>From there, we’ll want to select Advanced on the right (highlighted below), add our author’s name, and finally hit the Apply button.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-57.png" alt="Image" width="600" height="400" loading="lazy">
<em>Searching for an Author in Advanced Search of Google Analytics Behavior Report</em></p>
<p>After hitting apply, we now have all the stats we could ever dream of for the articles written by our author, Quincy Larson.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-58.png" alt="Image" width="600" height="400" loading="lazy">
<em>All posts from an Author in Google Analytics Behavior Report</em></p>
<h3 id="heading-you-can-also-just-type-a-query-into-the-google-analytics-search-bar">You can also just type a query into the Google Analytics Search Bar.</h3>
<p>Google Analytics has a search bar at the top, and you can just type natural language queries like this one:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/Analytics.png" alt="Image" width="600" height="400" loading="lazy">
<em>The results of a query for "articles by quincy larson past 30 days" shows the number of views each of Quincy's articles has gotten over the past 30 days.</em></p>
<h3 id="heading-which-categories-are-doing-the-best"><strong>Which categories are doing the best?</strong></h3>
<p>This is a trickier one. There are a lot of questions we may be able to answer with the basic reports like we did with Author, such as “out of all of the JavaScript posts, what has the most traffic?”, but maybe we want to know generally what category is the most popular on the site.</p>
<p>To do this we need to get our hands dirty with Custom Reports. This is too advanced to try to tackle in this post, but <a target="_blank" href="https://support.google.com/analytics/answer/1151300?hl=en">Google does a great job at outlining it in detail</a>.</p>
<p>For now, I’ve done you a favor and set up a report that you can easily import to your account and use right away. So first thing’s first, let’s import the report: <a target="_blank" href="https://analytics.google.com/analytics/web/template?uid=4fHol2S_TZqcQACAwfcmfg">https://analytics.google.com/analytics/web/template?uid=4fHol2S_TZqcQACAwfcmfg</a></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-59.png" alt="Image" width="600" height="400" loading="lazy">
<em>Importing a Custom Report in Google Analytics</em></p>
<p>Here you should see a screen like the above that asks us 2 things: where should we apply the report and what do we want to call it? If you’re an author of freecodecamp.org with access to GA and want to view this, you would select the All Web Site Data view under the freeCodeCamp News property.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-60.png" alt="Image" width="600" height="400" loading="lazy">
<em>Selecting a Property and View when importing a Custom Report in Google Analytics</em></p>
<p>Once selected, name the report what you’d like, such as “Top Primary Categories”, and click Create.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/image-61.png" alt="Image" width="600" height="400" loading="lazy">
<em>Custom Report showing top Primary Categories in Google Analytics</em></p>
<p>After it’s done, you’ll then land on the newly imported custom report where you can immediately see the most popular categories on the site, which for August is JavaScript!</p>
<h2 id="heading-breakdown"><strong>Breakdown</strong></h2>
<p>This was a lot!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/09/galaxy-quest-alan-rickman-tired.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Alan Rickman in Galaxy Quest sinking in chair</em></p>
<p>But this is just the tip of the data iceberg. Even with just the above, you can see there’s a lot going on and a lot of configuration to make the most out of Google Analytics for your specific needs.</p>
<p>If this interests you, I encourage you to do some research on your own, <a target="_blank" href="https://support.google.com/analytics/answer/1009714?hl=en">add a new view</a> (particularly <a target="_blank" href="https://www.e-nor.com/blog/google-analytics/best-practices-views-google-analytics">a Test View</a> to play around with), and get your hands dirty poking around the different reports. Otherwise, keep an eye out for more of my GA posts covering advanced installation and deeper insights.</p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>

<p><em>Originally published at <a target="_blank" href="https://www.colbyfayock.com/2019/09/making-sense-of-google-analytics-and-the-traffic-to-your-website">https://www.colbyfayock.com/2019/09/making-sense-of-google-analytics-and-the-traffic-to-your-website</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to set up performance and user tracking in React with Google Analytics ]]>
                </title>
                <description>
                    <![CDATA[ By Mohammad Iqbal Keeping track of your users and your app performance is a very crucial part of modern web development. You may have seen reports of companies increasing revenues by simply decreasing the load time of their app by a few hundred milli... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/performance-and-user-tracking-in-react-with-google-analytics/</link>
                <guid isPermaLink="false">66d45f3e3a8352b6c5a2aa83</guid>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ web performance ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 31 Jul 2019 18:37:30 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/07/guillaume-fischer--JPCZcxeqzM-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Mohammad Iqbal</p>
<p>Keeping track of your users and your app performance is a very crucial part of modern web development. You may have seen reports of companies increasing revenues by simply decreasing the load time of their app by a few hundred milliseconds. </p>
<p>Keeping track of your user behavior is also crucial. This will allow you to modify and build your app according to your users' preferred way of interacting with your app, resulting in happier users and more traffic to your site.  </p>
<p>Here is the completed project: </p>
<p><a target="_blank" href="https://github.com/iqbal125/react-hooks-google-analytics">https://github.com/iqbal125/react-hooks-google-analytics</a></p>
<p>In this guide I'll give you a complete foundational guide to tracking both performance and user behavior. By the end of the tutorial you will have everything you need to build complex user and performance tracking setups. </p>
<blockquote>
<p>Follow Me on Twitter for more tutorials in the future: <a target="_blank" href="https://twitter.com/iqbal125sf">https://twitter.com/iqbal125sf</a></p>
</blockquote>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li>Intro</li>
<li>Google Analytics</li>
<li>Tracking Pages Views</li>
<li>Tracking Load Performance</li>
<li>Tracking Rendering Performance</li>
<li>Tracking Paint</li>
<li>Tracking Scroll</li>
<li>Tracking Events</li>
<li>Quick Performance Tips and Heuristics</li>
</ol>
<h2 id="heading-intro">Intro</h2>
<p>I will show you the performance metrics for the development build of react to keep this tutorial concise. But in a real world situation do not test the dev version, because it contains a lot of error handling code and lack of optimizations that will give you highly skewed results. </p>
<p>For this reason it is better to test on the build production version to establish some baseline metrics. </p>
<p>Also, for the sake of brevity I will just refer to Google Analytics as GA. </p>
<p>GA also doesn't work with local host. To get a simulation of what you might be sending to GA without actually sending it and messing up your analytics, you can just substitute a console.log wherever you plan on putting your GA hit. </p>
<p><code>ReactGA</code>  is the global function and is known as the command queue because it does not execute commands immediately but adds commands to a queue and then sends them asynchronously. This does not tie up the main thread and does not lead to your tracking code harming your app performance. </p>
<p>A hit is when a GA tracker sends data to Google Analytics. </p>
<p>We will mainly be focusing on the React code in this tutorial, there are far better other tutorials to learn how to use GA.  </p>
<p>There are 3 main functions we will use when sending hits to GA. You should know there are more but we will just focus on these 3 for the purposes of this tutorial. </p>
<p><code>GAReact.pageview()</code>: will pass in a string that contains the route. </p>
<p><code>GAReact.timing()</code>: Will take an object as a parameter. Will contain information related to our performance metrics which we will see below. The fields will be <code>category</code>, <code>variable</code>, <code>value</code> and <code>label</code>. Notice that only the value property will be coming from our app the rest of the properties are user defined.</p>
<p><code>GAReact.event()</code>: Will take an object as a parameter. Will contain data about events that take place in the app (form submit, button click, etc.)  Will have fields of <code>category</code>, <code>action</code>, <code>label</code> and <code>value</code>. Note that only the value is going to come from the app, the rest of the properties are user defined.</p>
<p><strong>Synthetic testing vs RUM</strong><br>You might be wondering why go through all this trouble of setting up Performance Observer metrics if you can just use a tool like Lighthouse or Webpage speed test and get these metrics by just entering in the url. </p>
<p>Tools like those are important but they are what’s known as synthetic testing since the test will be done on your device and the test will not actually reflect what your users are experiencing. You can throttle the CPU or network when making these tests but they are still simulations. </p>
<p>Using GA with Performance Observer metrics will give us real numbers from our actual end users, devices and networks. This is known as RUM or Real User Monitoring. </p>
<p>Synthetic testing tools. Simply enter the URL of your app to run the synthetic tests. </p>
<ul>
<li><a target="_blank" href="https://www.webpagetest.org/">https://www.webpagetest.org/</a></li>
<li><a target="_blank" href="https://www.thinkwithgoogle.com/feature/testmysite">https://www.thinkwithgoogle.com/feature/testmysite</a></li>
<li><a target="_blank" href="https://developers.google.com/speed/pagespeed/insights/">https://developers.google.com/speed/pagespeed/insights/</a></li>
<li><a target="_blank" href="https://www.uptrends.com/tools/website-speed-test">https://www.uptrends.com/tools/website-speed-test</a></li>
<li><a target="_blank" href="https://tools.pingdom.com/">https://tools.pingdom.com/</a></li>
</ul>
<h2 id="heading-google-analytics">Google Analytics</h2>
<p><strong>Setup</strong><br>If you already have Google Analytics setup on your app, feel free to skip this section there is nothing new here. </p>
<p>To setup GA go on the dashboard and click on the admin tab on the side drawer. Then click add property. Fill out the required info. </p>
<p>If you are reading this tutorial I'm going to assume your smart enough to setup Google Analytics with just those 3 lines of instruction. If not, here is a handy guide by Google. </p>
<p><a target="_blank" href="https://support.google.com/analytics/answer/1042508?hl=en">https://support.google.com/analytics/answer/1042508?hl=en</a></p>
<p>After you're done setting up, you will get a tracking id at the top, which we will use in our React App.</p>
<p><strong>Setup in react</strong><br>We dont have to re-invent the wheel here, we can use a helper library made by the Mozilla Foundation to help us with the React setup. </p>
<p>To install the library simply run</p>
<p><code>npm install react-ga</code></p>
<p>Then just import the ReactGA object where ever you want to use it</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> ReactGA <span class="hljs-keyword">from</span> <span class="hljs-string">'react-ga'</span>;
</code></pre>
<p>You will also need to initialize it in the root component with the tracking id from google analytics.  </p>
<pre><code class="lang-javascript">...
ReactGA.initialize(<span class="hljs-string">'UA-00000-1'</span>);
...
</code></pre>
<p><strong>Observers</strong><br><code>ReactGA</code> cant do anything besides send data to the Google Analytics website. To actually get performance metrics to send, we will use the Performance Observer browser API. This Performance Observer API has nothing to do with GA or even React, it is a browser API that is available in most modern browsers </p>
<p>How the PerformanceObserver and related APIs work exactly is a fairly big topic and is far out of the scope of this tutorial. See the Further Reading section for more info and links to tutorials. </p>
<p>The basic idea of how they work is they "observe" something and then send that data asynchronously at the time of the browsers choosing. This keeps the main thread free for critical app functionality and related tasks, therefore tracking events does not affect your app performance. </p>
<p>Before observers you would have to add an event listener and fire it synchronously every time something happened, this resulted  in noticeable performance issues if too many events were being fired at once. So this is the problem observers are looking to solve. </p>
<h2 id="heading-track-page-views">Track Page Views</h2>
<p>Tracking page views in a single page app like react may seem like it would be complicated but its relatively simple thanks to react-router and history libraries. </p>
<pre><code class="lang-javascript">history.listen(<span class="hljs-function">(<span class="hljs-params">location</span>) =&gt;</span> {
    ReactGA.set({ <span class="hljs-attr">page</span>: location.pathname });
    ReactGA.pageview(location.pathname)
  }
);
</code></pre>
<p><code>history.listen()</code> allows you to fire a callback on route changes which in our case happens to be the GA hit. The route is contained in the <code>pathname</code> property of <code>location</code>.  But there are a couple of things to note such as: </p>
<p><strong>Handling the intial load</strong><br>History is listening for page changes but it doesn’t cause a hit on the initial page load.</p>
<p>There are a few ways to handle the initial load. I found a simple way to do it that I think requires the least amount of code and complexity and it is just to have an initial load variable and save it to the global state. In the home page just use a conditional to check if it is false then set it to true after the hit. </p>
<p>Context variable in the parent component</p>
<pre><code class="lang-javascript">... 

const [initialLoad, setInitialLoad] = useState(<span class="hljs-literal">false</span>)

...
      &lt;Context.Provider
            <span class="hljs-comment">//Initial Load</span>
            <span class="hljs-attr">initialLoadProp</span>: initialLoad,
            <span class="hljs-attr">setInitialLoadProp</span>: <span class="hljs-function">() =&gt;</span> setInitialLoad(<span class="hljs-literal">true</span>),
       &gt;
      &lt;/Context.Provider&gt;
</code></pre>
<p>Then the <code>useEffect()</code> in the home child component </p>
<pre><code class="lang-javascript">...   
useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">if</span>(!context.initialLoadProp) {
      ReactGA.pageview(props.location.pathname);  
      context.setInitialLoadProp(<span class="hljs-literal">true</span>)
    }
  }, [])
...
</code></pre>
<p>There are other implementations and discussions you can find here:</p>
<p><a target="_blank" href="https://github.com/react-ga/react-ga/wiki/React-Router-v4-withTracker">https://github.com/react-ga/react-ga/wiki/React-Router-v4-withTracker</a>  </p>
<p><strong>Tracking pages with User ids</strong><br>Another thing you might want to know is how many users are visiting their private profile pages. Just using the pageviews would give you a unique url for every hit and will not work. </p>
<p>Say you have the following URLs with user ids:</p>
<p>user/4543456/messages<br>user/4543456/account<br>user/3543564/messages<br>user/3543564/replytomessage<br>user/3543564/account</p>
<p>These will all give you a unique page hit. A simple fix is to just check with a conditional and then remove the unique id. You can also use a conditional to make sure you dont send these pages to google analytics. </p>
<pre><code class="lang-javascript">...

 history.listen(<span class="hljs-function">(<span class="hljs-params">location</span>) =&gt;</span> {
   <span class="hljs-keyword">if</span>(location.pathname.includes(<span class="hljs-string">'/user'</span>)) {
     <span class="hljs-keyword">let</span> rootURL = location.pathname.split(<span class="hljs-string">'/'</span>)[<span class="hljs-number">1</span>]
     <span class="hljs-keyword">let</span> userPage = location.pathname.split(<span class="hljs-string">'/'</span>)[<span class="hljs-number">3</span>]

     <span class="hljs-keyword">let</span> pageHit = <span class="hljs-string">`/<span class="hljs-subst">${rootURL}</span>/<span class="hljs-subst">${userPage}</span>`</span>
     ReactGA.pageview(pageHit)
   } <span class="hljs-keyword">else</span> {
     ReactGA.set({ <span class="hljs-attr">page</span>: location.pathname });
     ReactGA.pageview(location.pathname)
   }
});

...
</code></pre>
<p>We are simply just parsing out the user id and then concatenating the route again before sending the hit. </p>
<p>This would probably not be true for forum posts since having a unique URL for each post would be correct, since you would like to know how many people visited each post. </p>
<h2 id="heading-tracking-load-performance">Tracking Load Performance</h2>
<p>Getting the load performance is relatively easy. All the load performance data is under the <code>navigation</code> entry which is part of the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Navigation_timing_API">navigation timing API</a>. </p>
<p>The Performance Observer Can be setup like so in the root parent component. </p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> callback = <span class="hljs-function"><span class="hljs-params">list</span> =&gt;</span> {
    list.getEntries().forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
      ReactGA.timing({
        <span class="hljs-attr">category</span>: <span class="hljs-string">"Load Performace"</span>,
        <span class="hljs-attr">variable</span>: <span class="hljs-string">"Some metric"</span>,  
    <span class="hljs-attr">value</span>: <span class="hljs-string">"Value of Metric"</span>
      })
  })
}

<span class="hljs-keyword">var</span> observer = <span class="hljs-keyword">new</span> PerformanceObserver(callback);
observer.observe({<span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'navigation'</span>] })
</code></pre>
<p>First we define a function to be called for each entry. Then we pass this callback into our <code>PerformanceObserver</code> and finally we call the <code>.observe()</code> method on our observer and pass in <code>navigation</code> as an entryType.  </p>
<p>This will give you the following entry:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/07/image-76.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This is a very large amount of information but really we need only 3 properties to track the main load performance: </p>
<p><code>requestStart</code>: when the browser issues a request to get the webpage from the server</p>
<p><code>responsesStart</code>: when the first byte of the website arrives</p>
<p><code>responseEnd</code>: When the last byte of the website arrives</p>
<p>There are a few things that happen before the requestStart such as DNS lookup and the TLS handshake. Use this data and see if you can combine it with other properties to make new metrics. </p>
<p>With the above three properties we can create 3 important metrics. Simply substitute in the <code>variable</code> and <code>value</code> properties for the respective metric. </p>
<pre><code><span class="hljs-keyword">const</span> callback = <span class="hljs-function"><span class="hljs-params">list</span> =&gt;</span> {
    list.getEntries().forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
      ReactGA.timing({
        <span class="hljs-attr">category</span>: <span class="hljs-string">"Load Performace"</span>,
        <span class="hljs-attr">variable</span>: <span class="hljs-string">'Server Latency'</span>,
        <span class="hljs-attr">value</span>: entry.responseStart - entry.requestStart 
      })
  })
}
</code></pre><p>Server latency:<br><code>entry.responseStart - entry.requestStart</code></p>
<p>Download time:<br><code>entry.responseEnd - entry.responseStart</code></p>
<p>Total app load time:<br><code>entry.responseEnd - entry.requestStart</code></p>
<p><strong>Time to Interactive</strong><br>This metric is essentially how long it takes for a user to be able to interact with your site.</p>
<p>Until a native TTI metric is available through the browser api we can use this handy polyfill npm module for now. This module is created by Google. </p>
<p><code>npm install tti-polyfill</code></p>
<p>Then we can use the polyfill like so. </p>
<pre><code class="lang-javascript">... 

import ttiPolyfill <span class="hljs-keyword">from</span> <span class="hljs-string">'tti-polyfill'</span>;


ttiPolyfill.getFirstConsistentlyInteractive().then(<span class="hljs-function">(<span class="hljs-params">tti</span>) =&gt;</span> {
  ReactGA.timing({
    <span class="hljs-attr">category</span>: <span class="hljs-string">"Load Performace"</span>,
    <span class="hljs-attr">variable</span>: <span class="hljs-string">'Time to Interactive'</span>,
    <span class="hljs-attr">value</span>: tti 
  })
});

...
</code></pre>
<p>We are simply sending a hit inside of our function with a chained <code>.then()</code> statement since we will retrieve this metric asynchronously. </p>
<h2 id="heading-tracking-rendering-performance">Tracking Rendering Performance</h2>
<p>Now we can discuss Rendering Performance, which is how long it takes for React to construct the tree of DOM nodes. We can track rendering performance with the <code>mark</code> and <code>measure</code> entries. </p>
<p><code>mark</code> is used to "mark" a point in time you want to keep track of. Just pass in a string as the name of the mark on the exact line you want mark for tracking. </p>
<pre><code class="lang-javascript">performance.mark(<span class="hljs-string">"name of mark"</span>)
</code></pre>
<p><code>measure</code> is the difference between the 2 marks. Just set the name of the measure and pass in start and end marks, which will give you the difference between the marks in milliseconds. </p>
<pre><code class="lang-javascript">performance.measure.(<span class="hljs-string">"name of mark"</span>, startingMark, EndingMark)
</code></pre>
<p>Thankfully React comes pre-bundled with these marks and measures, which saves us from having to open up the React Source and having to write them ourselves. Simply pass in <code>mark</code> and <code>measure</code> for the entry types and you're done. </p>
<pre><code class="lang-javascript">...

var observer = <span class="hljs-keyword">new</span> PerformanceObserver(callback);
observer.observe({<span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'mark'</span>, <span class="hljs-string">'measure'</span>] })

...
</code></pre>
<p>This will give you the time it takes for root parent component and all child components to render in milliseconds. You will get entries that look something like this: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/07/image-73.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You will also get the time it takes for the lifecycle methods to execute. There is a wealth of information here, simply pick what you want to track and send it to GA by checking for the name in a conditional statement. </p>
<pre><code class="lang-javascript">...
const callback = <span class="hljs-function"><span class="hljs-params">list</span> =&gt;</span> {
    list.getEntries().forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
      <span class="hljs-keyword">if</span>(entry.name.includes(<span class="hljs-string">'App'</span>) ) {
        ReactGA.timing({
          <span class="hljs-attr">category</span>: <span class="hljs-string">"App Render Performace"</span>,
          <span class="hljs-attr">variable</span>: entry.name,
          <span class="hljs-attr">value</span>: entry.duration
        })
      }
  })
}
...
</code></pre>
<h2 id="heading-tracking-paint-performance">Tracking Paint Performance</h2>
<p>Now we can track paint which is when the pixels are drawn (or "painted") to the screen after the DOM tree is rendered.  </p>
<p>Tracking paint performance comprises 3 metrics: First Paint, First Contentful Paint and First Meaningful paint. </p>
<p><strong>First Paint</strong>: First time anything besides a blank white page is present. </p>
<p><strong>First Contentful Paint:</strong> When the first DOM element is present. Text, image etc. </p>
<p>First Paint and First Contentful Paint will be given automatically by the API. Simply do the following:</p>
<pre><code>...

const callback = <span class="hljs-function"><span class="hljs-params">list</span> =&gt;</span> {
    list.getEntries().forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
       ReactGA.timing({
          <span class="hljs-attr">category</span>: <span class="hljs-string">"Paint"</span>,
          <span class="hljs-attr">variable</span>: entry.name,
          <span class="hljs-attr">value</span>: entry.startTime
     })
  })
}

<span class="hljs-keyword">var</span> observer = <span class="hljs-keyword">new</span> PerformanceObserver(callback);
observer.observe({<span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'paint'</span>] })
</code></pre><p>The entries will look like this</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/07/image-74.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It is entirely possible that both these metrics are exactly the same, down to the millisecond. Even if they are not the same there can be an irrelevant difference between them. For this reason another more flexible metric is used, called: </p>
<p><strong>First Meaningful Paint</strong>: When something “meaningful” is painted to the screen. “meaningful” is kept intentionally vague, allowing the developer to decide themselves what they want to test for.  </p>
<p>According to Google, the First Paint and First Contentful paint answer the question of “Is it happening” and First Meaningful Paint answers “Is it useful”. “Is it useable” is answered by Time to Interactive. </p>
<p>A common way to use First Meaningful paint is to test for the hero element. Which is the main element on the page. </p>
<p>An example for youtube would be the video player. Suggested videos and comments would all then be non hero secondary elements. Tracking when the video player has finished painting would be the First Meaningful Paint in this case. </p>
<p>A common hero element on the homepage is a background image near the header that gives the value proposition or theme of the website. Knowing this, we can use the resource timing api to measure when our image has finished loading and make this our First Meaningful paint metric. </p>
<p>If your hero element is an image then you can simply look at the resource timing API and then look at <code>responseEnd</code> property and use that as your FMP. </p>
<pre><code class="lang-javascript">...
const callback = <span class="hljs-function"><span class="hljs-params">list</span> =&gt;</span> {
    list.getEntries().forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
        ReactGA.timing({
          <span class="hljs-attr">category</span>: <span class="hljs-string">"First Meaningful Paint"</span>,
          <span class="hljs-attr">variable</span>: entry.name,
          <span class="hljs-attr">value</span>: entry.responseEnd
        })
  })
}

<span class="hljs-keyword">var</span> observer = <span class="hljs-keyword">new</span> PerformanceObserver(callback);
observer.observe({<span class="hljs-attr">entryTypes</span>: [<span class="hljs-string">'resource'</span>] })
...
</code></pre>
<p>Entire resource timing response.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/07/image-75.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Since the loaded image doesn't technically mean its painted you can also try to set the marks manually. </p>
<pre><code>

<span class="hljs-comment">//jsx </span>

{performance.mark(<span class="hljs-string">'start'</span>) 
&lt;img /&gt;
{performance.mark(<span class="hljs-string">'end'</span>)
{performance.measure(<span class="hljs-string">'diff'</span>, <span class="hljs-string">'start'</span>, <span class="hljs-string">'end'</span>)
</code></pre><p>Again there is a lot of flexibility in this metric, really consider your use case and what your trying to measure.</p>
<h2 id="heading-track-scroll"><strong>Track Scroll</strong></h2>
<p>Tracking the scroll position of your user is a fairly important part of analytics. You can for example see how many users scrolled past a certain image or section of text. Having this information you can then tweak your content and increase your conversion. </p>
<p>You would have seen older implementations use <strong>getBoundingClientRect()</strong> but this would tie up the main thread and therefore tracking the scroll would actually decrease performance. You can execute the scroll events asynchronously with <code>IntersectionObserver</code>.  </p>
<p>The <code>IntersectionObserver</code> is different than the <code>PerformanceObserver</code> we have been working with in the last sections. </p>
<p>The <code>IntersectionObserver</code> takes 2 arguments a callback and a options object. The options object will have 3 properties</p>
<p><code>root</code>: The element you are trying to test the intersection against. In most cases this will be the viewport which will be the value of <code>null</code>. </p>
<p><code>rootMargin</code>: The margins around the root element. ex: "10px"</p>
<p><code>threshold</code>: How much of the element is visible before <code>isIntersecting</code> is true. ex: 0.5 means <code>isIntersecting</code>  is true when 50% of the element is visible. 0 means the very top of the element and 1.0 means the entire element. </p>
<p>The entry will return an object like so: </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/07/image-78.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><code>isIntersecting</code>:  Essentially used to determine if the element is visible which would be true when the threshold is reached.</p>
<p>And now the code: </p>
<pre><code class="lang-javascript"><span class="hljs-comment">//Get the element you want to track with useRef</span>
<span class="hljs-keyword">const</span> intersectTarget = useRef(<span class="hljs-literal">null</span>)

<span class="hljs-comment">//Use the observer inside the component you want to track scroll</span>
  useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-keyword">const</span> opts = {
            <span class="hljs-attr">root</span>: <span class="hljs-literal">null</span>,
            <span class="hljs-attr">rootMargin</span>: <span class="hljs-string">'0px'</span>,
            <span class="hljs-attr">threshold</span>: <span class="hljs-number">0</span>
    }
    <span class="hljs-keyword">const</span> callback = <span class="hljs-function"><span class="hljs-params">list</span> =&gt;</span> {
      list.forEach(<span class="hljs-function"><span class="hljs-params">entry</span> =&gt;</span> {
        <span class="hljs-keyword">if</span>(entry.isIntersecting) {
            ReactGA.event({
              <span class="hljs-attr">category</span>: <span class="hljs-string">'Scroll'</span>,
              <span class="hljs-attr">action</span>: <span class="hljs-string">'Scrolled to heading 2'</span>,
              <span class="hljs-attr">value</span>: entry.intersectionRatio
            })
          }
       })
    }
    <span class="hljs-keyword">const</span> observerScroll = <span class="hljs-keyword">new</span> IntersectionObserver(callback, opts)

    observerScroll.observe(intersectTarget.current)
  }, [])

<span class="hljs-comment">//jsx</span>
  &lt;h1 ref={intersectTarget}
      id=<span class="hljs-string">"heading2"</span>
        &gt;
     Second Heading
  &lt;/h1&gt;
</code></pre>
<p>The main idea here is to first initialize the <code>useRef</code> hook. Then use the ref on the element you want to track for scroll. The callback and observer will be called in the <code>useEffect</code> hook and the element can be passed to the <code>.observe()</code> method with the name of the ref and the <code>.current</code> property. </p>
<p><strong>Note</strong>: The intersection observer will fire on the initial page load even if the element is not visible. This is normal and you will see that the <code>isIntersecting</code> property is false. </p>
<p><strong>Note also:</strong> At the time of this writing there is also an <code>isVisible</code> property on the entry, but it does not function as its name suggests. It stays false even when the element visible. It is not documented anywhere so I cant comment on its purpose, but I would suggest using <code>isIntersecting</code>   property instead.     </p>
<h2 id="heading-track-events">Track Events</h2>
<p>The basic idea to tracking events is to send GA hits inside of the function call attached to an event handler. There really isn’t much more to it than that. </p>
<p>One thing to note is if your user is submitting a form you can specify the     <code>transport: beacon</code> property in your event hit, which will let you reliably send the hit even if the page is reloaded to another page. This isn't so much of an issue in a single page app like React, but if you did want to do this, just know this option is available. </p>
<p>See the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon">navigator beacon</a> for more info </p>
<p>I will show you how to track a form submit, but this pattern will work with basically any event. Again you are simply sending the hit in a function attached to the event handler.</p>
<pre><code class="lang-javascript">
  ...
  const handleSubmit = <span class="hljs-function">(<span class="hljs-params">event</span>) =&gt;</span> {
    event.preventDefault();
    ReactGA.event({
     <span class="hljs-attr">category</span>: <span class="hljs-string">'Form'</span>,
     <span class="hljs-attr">action</span>: <span class="hljs-string">'Form Submit'</span>,
     <span class="hljs-attr">transport</span>: <span class="hljs-string">'beacon'</span>
   });
    apiCall(<span class="hljs-string">'/apicall'</span>, event.target.value)
  };

  ...

  &lt;form onSubmit={handleSubmit}&gt;
  ...
  &lt;/form&gt;

  ...
</code></pre>
<p><strong>Quick Performance Tips and Heuristics</strong>  </p>
<p>Biggest area for improvement I see for a lot of developers is to code things from scratch instead of using a library. Tree shaking reduces bloat a little bit, but there is still considerable bloat compared to coding something yourself. Which will allow you to only write the code you need.  Try to use as little libraries as possible. Instead of using a library for a few functions, try to just look at the source code of the library and try to implement those functions yourself. Also keep in mind that most libraries have to prioritize ease of use and personalization over performance. </p>
<p>Some other ones: </p>
<ul>
<li>For event firing like scroll you will definitely need debouncing/throttling. You don't need to do this for observers.  </li>
<li>Only import functions and variables you need and let tree shaking discard unused code. </li>
<li>Do not pass in an anonymous function to events. </li>
<li>Turn your React app into a PWA allowing users to download and install your webapp locally on their device.</li>
<li>Reduce payloads with code splitting and lazy loading. </li>
<li>Decrease file size by using gzip or similar compression </li>
<li>Serve images from a CDN </li>
<li>Enable caching through your http headers on server responses. </li>
<li>Optimize images. See the google fundamentals guide for a full guide on how to do so. </li>
<li>Use the new CSS Flexbox for layout. Avoid <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing">Layout Thrashing</a> </li>
<li>Only Use transforms and opacity for css changes. So instead of changing height and width use scale X and scaleY </li>
</ul>
<p>Luckily, A lot of these optimizations, like minification and gzip, are done for automatically when you run the npm build command on a React Project.</p>
<h2 id="heading-ia"> </h2>
<p>Conclusion</p>
<p>Thanks for reading! If you found any other creative metrics or clever ways to track users, let me know in the comments. </p>
<blockquote>
<p>Follow me on twitter for more tutorials in the future: <a target="_blank" href="https://twitter.com/iqbal125sf">https://twitter.com/iqbal125sf</a> </p>
</blockquote>
<p><strong>Blog Posts:</strong><br><a target="_blank" href="https://www.searchenginejournal.com/a-technical-seo-guide-to-lighthouse-performance-metrics/292703/#close">https://www.searchenginejournal.com/a-technical-seo-guide-to-lighthouse-performance-metrics/292703/#close</a></p>
<p><a target="_blank" href="https://infrequently.org/2017/10/can-you-afford-it-real-world-web-performance-budgets/">https://infrequently.org/2017/10/can-you-afford-it-real-world-web-performance-budgets/</a></p>
<p><a target="_blank" href="https://speedcurve.com/blog/user-timing-and-custom-metrics/">https://speedcurve.com/blog/user-timing-and-custom-metrics/</a></p>
<p><a target="_blank" href="https://designsystem.digital.gov/performance/">https://designsystem.digital.gov/performance/</a></p>
<p><a target="_blank" href="https://hackernoon.com/react-performance-primer-64fe623c4821">https://hackernoon.com/react-performance-primer-64fe623c4821</a> </p>
<p><a target="_blank" href="https://reactjs.org/docs/optimizing-performance.html">https://reactjs.org/docs/optimizing-performance.html</a>  </p>
<p><strong>Observers:</strong><br><a target="_blank" href="https://css-tricks.com/paint-timing-api/">https://css-tricks.com/paint-timing-api/</a></p>
<p><a target="_blank" href="https://css-tricks.com/breaking-performance-api/">https://css-tricks.com/breaking-performance-api/</a></p>
<p><a target="_blank" href="https://hackernoon.com/tracking-element-visibility-with-react-and-the-intersection-observer-api-7dfaf3a47218">https://hackernoon.com/tracking-element-visibility-with-react-and-the-intersection-observer-api-7dfaf3a47218</a></p>
<p><a target="_blank" href="https://www.smashingmagazine.com/2018/01/deferring-lazy-loading-intersection-observer-api/">https://www.smashingmagazine.com/2018/01/deferring-lazy-loading-intersection-observer-api/</a></p>
<p><a target="_blank" href="https://www.sitepen.com/blog/improving-performance-with-the-paint-timing-api/">https://www.sitepen.com/blog/improving-performance-with-the-paint-timing-api/</a>  </p>
<p><strong>Google Based:</strong><br><a target="_blank" href="https://developers.google.com/web/fundamentals/performance/user-centric-performance-metrics">https://developers.google.com/web/fundamentals/performance/user-centric-performance-metrics</a></p>
<p><a target="_blank" href="https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/">https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing/</a></p>
<p><a target="_blank" href="https://developers.google.com/web/tools/chrome-devtools/speed/get-started">https://developers.google.com/web/tools/chrome-devtools/speed/get-started</a></p>
<p><a target="_blank" href="https://marketingplatform.google.com/about/optimize/">https://marketingplatform.google.com/about/optimize/</a></p>
<p><a target="_blank" href="https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings">https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings</a></p>
<p><a target="_blank" href="https://support.google.com/analytics/answer/1033068#Anatomy">https://support.google.com/analytics/answer/1033068#Anatomy</a></p>
<p><a target="_blank" href="https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications">https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications</a></p>
<p><a target="_blank" href="https://support.google.com/analytics/answer/1033068">https://support.google.com/analytics/answer/1033068</a></p>
<p><a target="_blank" href="https://docs.google.com/document/d/1GGiI9-7KeY3TPqS3YT271upUVimo-XiL5mwWorDUD4c/preview#">https://docs.google.com/document/d/1GGiI9-7KeY3TPqS3YT271upUVimo-XiL5mwWorDUD4c/preview#</a></p>
<p><a target="_blank" href="https://www.doubleclickbygoogle.com/articles/mobile-speed-matters/">https://www.doubleclickbygoogle.com/articles/mobile-speed-matters/</a>  </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to easily set up custom events tracking in Google Analytics ]]>
                </title>
                <description>
                    <![CDATA[ By Pankaj Singh The Growing need for Custom Event Tracking I am a technologist-turned-analytics professional since five-plus years. Recently, a friend asked me how he can set up a custom event tracking on his small business website and understand his... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-easily-set-up-custom-events-tracking-in-google-analytics-d1818e2ecdd0/</link>
                <guid isPermaLink="false">66c351db0107ba195e79f717</guid>
                
                    <category>
                        <![CDATA[ data analysis ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 19 Feb 2019 17:41:51 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*FnDrSxZXNERxjYqpHoM1mA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Pankaj Singh</p>
<h3 id="heading-the-growing-need-for-custom-event-tracking"><strong>The Growing need for Custom Event Tracking</strong></h3>
<p>I am a technologist-turned-analytics professional since five-plus years. Recently, a friend asked me how he can set up a custom event tracking on his small business website and understand his site’s user behavior better.</p>
<p>Until a few years back small businesses and personal bloggers were satisfied knowing their number of unique visitors and page views on their website. But everyone now wants to understand much more than mere page views. They want to know how many users clicked on different buttons, watched a video, checked details of a product, or clicked on third-party advertisements among other things. There’s an increasing demand to understand how different users are engaging on their digital assets.</p>
<p>There are many objectives you can use your website for, and there are as many activities to monitor on a website. While big businesses have dedicated teams, small companies usually have a single person managing both the analysis and the technical setup of their analytics account.</p>
<blockquote>
<p>"Thankfully setting up basic goals and even the advance custom goals in google analytics isn’t difficult, as long as you know the right steps. And in this article we are going to go through exactly that. I’ll walk you through the steps of setting up custom goals in the simplest way while you enjoy your coffee!" - Google's documentation</p>
</blockquote>
<h2 id="heading-overview">Overview</h2>
<p>First, for the sake of revision, let’s go over the four main types of custom goals available in your Google Analytics account. If you are already familiar with them and want to understand only the last one (the “Event” goal type), then scroll down to point 4: “Setting up an Event goal”. A glance at the screenshot below will explain to you the four main goals that you can customize in Google Analytics.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/1_jVaB9r6Kdv_fxeObzUeKXg.png" alt="Image" width="600" height="400" loading="lazy">
<em>The 4 Custom Goal Types in Your GA Goal Settings</em></p>
<p>You’ll notice that the first 3 goals are very intuitive and directly usable. Once set, they will give you an x% conversion in the past 7 days. But the last one will return a 0% conversion. Let’s first review the three simpler goals and then we’ll be able to understand the event goal in detail.</p>
<h2 id="heading-1-setting-a-destination-goal"><strong>1. Setting a Destination Goal</strong></h2>
<p>All you need for this is to give the URL of the page which you identify as a success on a page visit. For example in e-commerce websites, when a person makes a purchase and reaches a “thank-you” page, it’s a success. So visiting the thank-you page can be a goal.</p>
<p>All you need to do is enter the URL of that page as a destination, <em>www.yourexamplesite.com/thanks.html</em>. It’s possible that your website may have different query parameters, so you can use options like “URL Begins with”, “URL Ends with” or “Regex”.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/1_ijl4io4cmLAvEf1cSOOLiw.png" alt="Image" width="600" height="400" loading="lazy">
<em>Defining a ‘Destination’ Goal in Google Analytics</em></p>
<h2 id="heading-2-setting-a-duration-goal"><strong>2. Setting a Duration Goal</strong></h2>
<p>This refers to the number of minutes (or hours) spent on your website by a user. This goal’s use can vary based on the purpose of a website. Spending more time on your site may be desirable, but it doesn’t mean a sure shot conversion. It can also mean that your website is not easy enough to help users accomplish their tasks quickly.</p>
<p>However, for content-oriented websites such as that of newspapers, bloggers, magazines or video content, a duration goal can be important. So based on your site’s purpose, it might be a good idea to set different time duration goals.</p>
<p>As you can see below, you can enter a time duration for this goal and you’ll be set to track all users who cross that mark.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/1_oTaECRqhsaVI8eL1P0Y6_Q.png" alt="Image" width="600" height="400" loading="lazy">
<em>Defining ‘Duration’ goal in Google Analytics</em></p>
<h2 id="heading-3-pagesscreens-per-session"><strong>3. Pages/screens per session</strong></h2>
<p>This is the number of pages viewed in a single session or visit. If a visitor closes the website and then returns the next day, or after a gap of 30 minutes on the same day, it’s called a new session.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/1_LCkKm70Q-_vwKR3gOEpAMQ.png" alt="Image" width="600" height="400" loading="lazy">
<em>Defining ‘Page Per Session’ in Google Analytics</em></p>
<h2 id="heading-4-setting-a-custom-event-goal-type"><strong>4. Setting a Custom Event Goal Type</strong></h2>
<p>An ‘event’ is any action taken by a user that marks an interaction with your website after landing on any of its pages. The simplest example is when they click on a button like “Buy Now”, or “Learn More”. It can also be used for options like downloading a PDF or E-book, among other actions.</p>
<p>Clicking on a button is typically referred to as a CTA, short for “Call to Action”. When you choose this option in your custom goals setting, you’ll see this window open up with four options:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/1_A0292cpFgkeBgN_nJb2g5Q.png" alt="Image" width="600" height="400" loading="lazy">
<em>Setting Fields for Google Analytics “Event’ Goal</em></p>
<p>All four fields or parameters are simple to enter. GA needs you to define each event with these four fields so that you can easily identify them during analysis.</p>
<blockquote>
<p><em>"<strong>You can write anything in these parameters, but it’s recommended that you define them in a way that makes the most business sense for you.</strong>" - Google's documentation</em></p>
</blockquote>
<p>For example, if you are managing a store selling electronic gadgets and accessories, you may want to fill it like this :</p>
<p><strong>A. Category:</strong> Category of the product. Example, ‘Headphones’</p>
<p><strong>B. Action:</strong> Let’s say a user clicked the ‘Add To Cart’ button. Then you could write ‘AddToCartClick’ in your action. In case you have an additional button for ‘Features’ or ‘Learn More’ for that product, you can have an additional goal and define its action as ‘LearnMoreClick’ for that button.</p>
<p><strong>C. Label</strong>: Label can be anything which helps you recognize or group your events better during your analysis. It can be the name of a ‘Campaign’ or a ‘Brand’. For example, ‘CollegeCampaignSonic’.</p>
<p><strong>D. Value:</strong> This is an optional value, mostly used to set a revenue number. It can be used to set a specific number like $50, or to take a dynamic value from the revenue variable of your page, like $(“PriceVariable”). Note that $ here is a jquery identifier and not the currency dollar. Picking up an ID would depend on the price or cost variable defined in your HTML.</p>
<blockquote>
<p>"After you define your Event goal type values here, the tricky part starts. Since every other goal in GA is directly usable once defined, it’s confusing to many why the event goal doesn’t start to work right away. That’s why when you click on ‘Verify the conversion’ for this goal, you see a 0% conversion." - Google's documentation</p>
</blockquote>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/11/1_CBDM9KgwzQY-5FwcaLtWQQ.png" alt="Image" width="600" height="400" loading="lazy">
<em>Event goal is not directly usable after configuration</em></p>
<p>To correct this 0% conversion, you need to integrate the settings of this goal with the actual click event or the custom action responsible on your website, for this goal.</p>
<h1 id="heading-integrating-custom-event-tracking-with-the-html-of-your-website"><strong>Integrating custom event tracking with the HTML of your website</strong></h1>
<p>Sometimes, business users (especially non-technical ones) tend to feel anxious when anything related to coding comes up while doing their analysis. Thankfully Google has made it very simple to tie any custom event tracking need that needs to be integrated with your website. Only if you’re managing a complex e-commerce website would you need help from a developer, which in most cases you would have access to if you are working in a mid-size company.</p>
<p>For integration, Google has already set up a standard template function that it expects you to use when tracking a custom event on your page. It’s one line of code, for which you have already set values in your GA account. Marketers or coders typically refer it to as the GA-Send call which is in the below format:</p>
<pre><code>ga(‘send’, ‘event’, [eventCategory], [eventAction], [eventLabel], [eventValue]);
</code></pre><p>The actual JS function in your HTML page may be in single line or may look like this for easy readability:</p>
<pre><code>ga(<span class="hljs-string">'send'</span>, {
  <span class="hljs-attr">hitType</span>: <span class="hljs-string">'event'</span>,
  <span class="hljs-attr">eventCategory</span>: ‘Headphones<span class="hljs-string">',
  eventAction: ‘AddToCartClick'</span>,
  <span class="hljs-attr">eventLabel</span>: ‘CollegeCampaignSony<span class="hljs-string">'
});</span>
</code></pre><p>Note that the values in this function must match the values entered in your GA account while setting up the event for its respective parameters. <strong>Now you still need to tie the above GA send call with the actual action on the button<em>.</em></strong></p>
<p>For example, you want to tie the above function with the click on the ‘Add To Cart’ button. The only step you would need to add is to include this function on the ‘onClick’ action event for that button ID.</p>
<pre><code>Integrating the above cited Google Analytics Event script inside your HTML
&lt;script&gt;
$(<span class="hljs-built_in">document</span>).ready(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
  $(<span class="hljs-string">"#exampleAddNowButtonID"</span>).click(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    ga (<span class="hljs-string">'send'</span>, <span class="hljs-string">'event'</span>, <span class="hljs-string">'Headphones'</span> , <span class="hljs-string">'AddToCartClick'</span> , <span class="hljs-string">'CollegeCampaignSonic'</span>);
  });
});
&lt;/script&gt;
</code></pre><h1 id="heading-wrapping-up">Wrapping up</h1>
<p>This brings me to the end of this article. I have tried to explain with simplicity and details that I felt lacking when I was learning how to set up custom tracking for my own requirements. Hopefully, this step by step guide helps you in setting up tracking for your custom goals that best fit your needs.</p>
<p>Feel free to share your thoughts or ask any clarifying questions related to this post in the comments.</p>
<p>In case you want to take any free online courses on Google Analytics, you can visit <a target="_blank" href="http://www.quickcode.co/free/course/learn/Google-Analytics-Basics-For-Beginners-Free--2018/1071">here</a>.</p>
<p><em>Portions of this page are modifications based on work created and</em> <a target="_blank" href="https://developers.google.com/readme/policies/"><em>shared by Google</em></a> <em>and used according to terms described in the</em> <a target="_blank" href="http://creativecommons.org/licenses/by/3.0/"><em>Creative Commons 3.0 Attribution License</em></a><em>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to set up reliable and maintainable Google Analytics in Webpack ]]>
                </title>
                <description>
                    <![CDATA[ One of the messier bits of a new app setup is trying to figure out where to stash your Google Analytics initialization scripts. There are some existing options like React Helmet to manage the head of your document. You can toss it in your monolithic ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-up-reliable-and-maintainable-google-analytics-in-webpack-6b68bfde29b3/</link>
                <guid isPermaLink="false">66b8e36a68c5b9f37d1d1aed</guid>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Mon, 13 Aug 2018 14:15:37 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*cl_Y0G1UBK76g5vkRxOIoA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>One of the messier bits of a new app setup is trying to figure out where to stash your Google Analytics initialization scripts. There are some existing options like <a target="_blank" href="https://github.com/nfl/react-helmet">React Helmet</a> to manage the head of your document. You can toss it in your monolithic <code>index.html</code> file.</p>
<p>The thing is, those setups rarely work out the way you want them to. They end up as ugly blocks of HTML strings in your JavaScript. You end up having to manage that monolith of an <code>index.html</code> file I mentioned before throughout your project’s lifecycle.</p>
<h3 id="heading-why-this-matters">Why this matters</h3>
<p>Beyond how you manage your code, if analytics is crucial to you and your business, you want to make sure the setup is reliable and correctly installed.</p>
<p>Many developers assume that because it’s a JS snippet, the best practice is to toss it at the bottom of the page. The issue with this is that throwing it at the end leaves a higher risk that you’ll miss tracking a hit before a user exits the page, as Analytics won’t initialize until the rest of the page loads. That’s why Google itself recommends <a target="_blank" href="https://support.google.com/analytics/answer/1008080?hl=en">installing the snippet as high in the head as possible</a>.</p>
<p>As important as I say this is, you might not care as much if you’re more relaxed about it and want to get a general idea about how things are running on your portfolio site. However, if you expand your reach into other tools like A/B testing with Google Optimize, it’s even more critical to have GA recognize the page and the experiment running to avoid additional delays or worse, page flickering. ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/w5Vp2B34jmhaGtlwnRSkksQrrN4YlmDN2QCC" alt="Image" width="800" height="355" loading="lazy">
<em>Undesirable content flicker while running a test</em></p>
<h3 id="heading-how-well-fix-this">How we’ll fix this</h3>
<p><a target="_blank" href="https://github.com/colbyfayock/html-webpack-partials-plugin">Partials for HTML Webpack Plugin</a> is an extension of <a target="_blank" href="https://github.com/jantimon/html-webpack-plugin">HTML Webpack Plugin</a> that simplifies your partial management. Its goal is to specifically try to avoid the practice of maintaining an <code>index.html</code> file in Webpack projects and instead defer to maintainable partials simplifying your setup.</p>
<p>For now, we’re going to focus on getting Google Analytics set up, but I recommend checking out <a target="_blank" href="https://marketingplatform.google.com/about/tag-manager/">Google Tag Manager</a> for managing tags generally, which I’ll cover later in a followup post.</p>
<p><strong>TL;DR —</strong> If you want to jump straight to the solution, <a target="_blank" href="https://github.com/colbyfayock/html-webpack-partials-plugin/tree/master/examples/analytics">you can grab the code here</a>.</p>
<h3 id="heading-getting-started">Getting started</h3>
<p>We’ll want to start out with a basic Webpack setup with HTML Webpack Plugin already configured. This guide won’t walk you through that setup, but here are a couple of starting points if you’re not familiar:</p>
<ul>
<li><a target="_blank" href="https://webpack.js.org/guides/getting-started/#basic-setup">Webpack’s Getting Started guide</a></li>
<li><a target="_blank" href="https://webpack.js.org/plugins/html-webpack-plugin/">Webpack’s guide for HTML Webpack Plugin</a></li>
<li>A ton of excellent tutorials out there you can find by <a target="_blank" href="https://www.google.com/search?q=webpack+html+tutorial">Googling around a little bit</a></li>
</ul>
<p>Lastly, if you already have an <code>index.html</code> set up, I won’t judge you for now, but hopefully this inspires you to approach other snippets the same way and remove the need for a managed <code>index.html</code> file at all.</p>
<h4 id="heading-installing-partials-for-html-webpack-plugin">Installing Partials for HTML Webpack Plugin</h4>
<p>Once you already have your basic setup and HTML Webpack Plugin installed, our Partials plugin is an easy add:</p>
<pre><code>yarn add html-webpack-partials-plugin -D
</code></pre><p><em>Note: make sure to properly set up the package dependency based on your project configuration.</em></p>
<h4 id="heading-set-up-your-partial">Set up your partial</h4>
<p>Next, we’ll want to create our partial. My preference for generally managing them is to create a new directory called <code>partials</code> in the source root. For example, if your entry point lives at <code>src/main.js</code>, your partials directory would be right next to it at <code>src/partials</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/4DvDYHwNSvfIEj5lOUC5Sqg8llPLLm5HRf-H" alt="Image" width="510" height="222" loading="lazy"></p>
<p>Once you have your preferred location, let’s create an <code>analytics.html</code> file in our new partials directory. For now, let’s throw in some test code, so we know it works. In <code>analytics.html</code>:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
<span class="hljs-selector-tag">body</span> { <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#5F4B8B</span>; }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<h4 id="heading-configure-your-partial">Configure your partial</h4>
<p>Open up your <code>webpack.config.js</code> and let’s set up the partial to get included in our build.</p>
<p>First, require the plugin at the top of your config. In <code>webpack.config.js</code>:</p>
<pre><code><span class="hljs-keyword">const</span> HtmlWebpackPartialsPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">'html-webpack-partials-plugin'</span>);
</code></pre><p>Next, and this is very important, include a new instance of the plugin <em>AFTER</em> your instance of <code>HtmlWebpackPlugin()</code>. In the plugins section of <code>webpack.config.js</code>:</p>
<pre><code>...
plugins: [
  <span class="hljs-keyword">new</span> HtmlWebpackPlugin(),
  <span class="hljs-keyword">new</span> HtmlWebpackPartialsPlugin({
    <span class="hljs-attr">path</span>: <span class="hljs-string">'./path/to/src/partials/analytics.html'</span>),
    <span class="hljs-attr">location</span>: <span class="hljs-string">'head'</span>,
    <span class="hljs-attr">priority</span>: <span class="hljs-string">'high'</span>
  })
...
</code></pre><p>Now let’s first break down that config before moving on:</p>
<ul>
<li><strong>path</strong>: this is what it sounds like, the path to the partial file in our project. Make sure to update this to the right location so the plugin can find it.</li>
<li><strong>location</strong>: the HTML tag the plugin looks for.</li>
<li><strong>priority</strong>: this determines whether at compile time, our plugin adds our partial at the beginning of the specified <code>location</code> tag or the end (opening vs. closing).</li>
</ul>
<p>Like we covered earlier, we want to add this as high in the <code>&lt;he</code>ad&gt; as possible. For most HTML tags us<code>ed in lo</code>cation, Partials add it right after the opening tag if the priori<code>ty i</code>s high. But wit<code>h the</code>  tag, Partials loo<code>ks for</code> your charset meta tag and injects it immediately after, as it’s important to render that in the document first.</p>
<h4 id="heading-test-it-out">Test it out</h4>
<p>Compile Webpack, open your project in your browser, and you should now see a nice, ultraviolet background. ?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/P0Nop8w9LQIsmhFtLCkM1gAzHJBxyMGPKsSu" alt="Image" width="800" height="216" loading="lazy"></p>
<p>If you take a look at the source, you should see the snippet get added right after the <code>charset</code> tag!</p>
<h4 id="heading-now-to-analytics">Now to Analytics</h4>
<p>Let’s update our <code>analytics.html</code> file to look something like this:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">async</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-X"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
<span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [];
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());
gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'UA-XXXXXXXX-X'</span>);
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>Just make sure to update the IDs (<code>UA-XXXXXXXX-X</code>) to your match your Google Analytics property value. Your Analytics snippet may also vary depending on your setup.</p>
<p>You should now be able to recompile Webpack and see your page start to ping Google Analytics! ?</p>
<p><em>Note: you might have to load your project file from a server before GA is recognized rather than straight off of your local filesystem</em></p>
<h3 id="heading-lets-take-it-a-step-further">Let’s take it a step further</h3>
<p>This is great and all, but when dealing with Google Analytics, it’s nice to have a few different properties, such as one for development and one for production. This helps avoid polluting the production property with data from your development team (or you) poking around the application.</p>
<h4 id="heading-setting-up-partial-variables">Setting up partial variables</h4>
<p>Let’s go back to our <code>webpack.config.js</code> file and set up a variable to pass our property ID in:</p>
<pre><code>...
plugins: [
  <span class="hljs-keyword">new</span> HtmlWebpackPlugin(),
  <span class="hljs-keyword">new</span> HtmlWebpackPartialsPlugin({
    <span class="hljs-attr">path</span>: <span class="hljs-string">'./path/to/src/partials/analytics.html'</span>),
    <span class="hljs-attr">location</span>: <span class="hljs-string">'head'</span>,
    <span class="hljs-attr">priority</span>: <span class="hljs-string">'high'</span>,
    <span class="hljs-attr">options</span>: {
      <span class="hljs-attr">ga_property_id</span>: <span class="hljs-string">'UA-XXXXXXXX-X'</span>
    }
  })
...
</code></pre><p>Next, update your <code>analytics.html</code> file to recognize this value. Similar to HTML Webpack Plugin, Partials uses <a target="_blank" href="https://lodash.com/docs/#template">Lodash templating</a> to make this work. In <code>analytics.html</code>:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">async</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://www.googletagmanager.com/gtag/js?id=&lt;%= ga_property_id %&gt;"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"> <span class="hljs-built_in">window</span>.dataLayer = <span class="hljs-built_in">window</span>.dataLayer || [];
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">gtag</span>(<span class="hljs-params"></span>)</span>{dataLayer.push(<span class="hljs-built_in">arguments</span>);}
gtag(<span class="hljs-string">'js'</span>, <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>());
gtag(<span class="hljs-string">'config'</span>, <span class="hljs-string">'&lt;%= ga_property_id %&gt;'</span>);
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>Now compile again and profit!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/2Fk3qpRoO0nD5BKjjE1OItqOB6XTk66STjoT" alt="Image" width="800" height="163" loading="lazy">
<em>Google Tag Assistant showing successful pageview request</em></p>
<p>To verify your tag is appropriately set up, I recommend checking out <a target="_blank" href="https://chrome.google.com/webstore/detail/tag-assistant-by-google/kejbdjndbnbjgmefkgdddjlbokphdefk?hl=en">Google Tag Assistant</a> available on Chrome.</p>
<h4 id="heading-setting-this-up-for-different-property-ids">Setting this up for different property IDs</h4>
<p>From here, you have a few options as to how you manage your different property IDs. You can:</p>
<ul>
<li>Set up separate <a target="_blank" href="https://webpack.js.org/guides/production/">development and production Webpack configs</a></li>
<li>Create an environment config (ex: <code>env.config.js</code>) that allows you to import the settings</li>
<li>Both (recommended)</li>
</ul>
<p>Setting it up this way will give you the opportunity to run the properties dynamically between your local development and production builds. Just remember not to store your env file in git if you’re going to add sensitive data. ?</p>
<h3 id="heading-so-what-are-we-getting-out-of-this">So what are we getting out of this?</h3>
<p>The ideal scenario is you take this and run with it for the rest of your HTML living in <code>index.html</code>. This helps split your code up into more manageable pieces and lets Webpack generate the file for you rather than you trying to override and manage it yourself.</p>
<p>Specifically for Google Analytics, we have a few benefits:</p>
<ul>
<li>Ensuring the snippet is loading in a reliable location</li>
<li>Providing a more reasonable way to maintain the snippet itself</li>
<li>Managing your property ID through your Webpack config</li>
<li>And bonus: loading it as an env variable through your Webpack config</li>
</ul>
<p>To see the full solution with some example code, <a target="_blank" href="https://github.com/colbyfayock/html-webpack-partials-plugin/tree/master/examples/analytics">check out the example in the GitHub repo.</a></p>
<div id="colbyfayock-author-card">
  <p>
    <a href="https://twitter.com/colbyfayock">
      <img src="https://res.cloudinary.com/fay/image/upload/w_2000,h_400,c_fill,q_auto,f_auto/w_1020,c_fit,co_rgb:007079,g_north_west,x_635,y_70,l_text:Source%20Sans%20Pro_64_line_spacing_-10_bold:Colby%20Fayock/w_1020,c_fit,co_rgb:383f43,g_west,x_635,y_6,l_text:Source%20Sans%20Pro_44_line_spacing_0_normal:Follow%20me%20for%20more%20JavaScript%252c%20UX%252c%20and%20other%20interesting%20things!/w_1020,c_fit,co_rgb:007079,g_south_west,x_635,y_70,l_text:Source%20Sans%20Pro_40_line_spacing_-10_semibold:colbyfayock.com/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_68,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_145,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_222,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/w_300,c_fit,co_rgb:7c848a,g_north_west,x_1725,y_295,l_text:Source%20Sans%20Pro_40_line_spacing_-10_normal:colbyfayock/v1/social-footer-card" alt="Follow me for more Javascript, UX, and other interesting things!" width="2000" height="400" loading="lazy">
    </a>
  </p>
  <ul>
    <li>
      <a href="https://twitter.com/colbyfayock">? Follow Me On Twitter</a>
    </li>
    <li>
      <a href="https://youtube.com/colbyfayock">?️ Subscribe To My Youtube</a>
    </li>
    <li>
      <a href="https://www.colbyfayock.com/newsletter/">✉️ Sign Up For My Newsletter</a>
    </li>
  </ul>
</div>

<p><em>Originally published at <a target="_blank" href="https://www.colbyfayock.com/2018/08/reliable-and-maintainable-google-analytics-in-webpack">https://www.colbyfayock.com/2018/08/reliable-and-maintainable-google-analytics-in-webpack</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How (and Why) to Get Started with Google Analytics ]]>
                </title>
                <description>
                    <![CDATA[ By Julia Bourbois What is Google Analytics? Essentially, Google Analytics is the go-to solution for monitoring website usage. Though it is frequently used in conjunction with Google Adwords, for e-commerce, and in improving website user experience, i... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-and-why-to-get-started-with-google-analytics-153dc35b7812/</link>
                <guid isPermaLink="false">66c34cbea7aea9fc97bdfb59</guid>
                
                    <category>
                        <![CDATA[ Google ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 16 Mar 2018 01:07:25 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*OV9Z2nnWNUHlfeTqyZsotg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Julia Bourbois</p>
<h3 id="heading-what-is-google-analytics">What is Google Analytics?</h3>
<p>Essentially, Google Analytics is the go-to solution for monitoring website usage. Though it is frequently used in conjunction with Google Adwords, for e-commerce, and in improving website user experience, it is flexible and powerful enough to be used by any organization that has a website. Indeed, you do not need coding prowess to utilize Google Analytics.</p>
<p>So, this guide is directed principally to individuals who do not consider themselves or their principal professional responsibilities to be tech. It will touch only on the essential elements to get started with Google Analytics.</p>
<h3 id="heading-what-can-google-analytics-do-for-me">What can Google Analytics do for me?</h3>
<p>Odds are your organization has a presence on the web. Google Analytics collects and renders a tremendous amount of data. Raw data is curated into a variety of reports depending on your needs. The data-driven insights that are applicable to your organization will depend on your goals for your site and your organization. Even if your goals are not yet defined there are areas of Google Analytics that are useful for most organizations.</p>
<p>Google Analytics can also help you identify underlying issues with the site. For instance, if there are performance or usability issues for mobile users of your site.</p>
<h4 id="heading-acquisition-overview">Acquisition Overview</h4>
<p>Acquisition Overview answers questions like: How much traffic does the site receive? What is the origin or top traffic for your site? What is your goal conversation rate? What is the break down of new versus returning users?</p>
<p>This is particularly useful when examining change over time. Comparing weeks or months will give you a better idea of site performance over time.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/XoCS-GRdyo8QcF1FPoyfcUCXhGLj3tn7T-NX" alt="Image" width="800" height="356" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<h4 id="heading-behavior-overview">Behavior Overview</h4>
<p>Some pages will be more important to your organization than others. On the Behavior Overview page, individual page performance will help you identify which pages are bringing in the most traffic. It will also provide you with an overview of your site’s technical performance, such as the bounce rate.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/iS-mF9UwYzQrT13PMW8vqV1JWvPLJM-yQQcI" alt="Image" width="800" height="325" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<p>If you are working in e-commerce, pages such as the home page, product pages, search results, the shopping cart, check out, and the thank you page, will be critical pages on your site to track.</p>
<p>However, if you’re a museum you may want to track pages for education, exhibition, and programming. You may also be interested in targeting geography to get a better idea of your target audience. Museums, as well as restaurants, diners, and cafes, will want to prioritize the local search optimization.</p>
<h4 id="heading-conversion-overview">Conversion Overview</h4>
<p>For Business impact reports, it is necessary to configure goals or e-commerce transactions. Google Analytics will not automatically establish your goals for you. Goals can be established for your site in the Administration Panel under “View.” Goals are very broadly defined and can be e-commerce transactions, or lead captures from submissions or reservations.</p>
<p>Goals with a dollar value illustrate the strengths and weakness in the pages of the sites. The Conversion Overview will enable you to drill down in your goal conversions and well as learn more about your customer’s path.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/JVBW-ATllweRSBDhbLTMLntZ6syK-YbmZ7AY" alt="Image" width="800" height="357" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<h3 id="heading-how-the-basics">How — The Basics</h3>
<p>So how do you get started?</p>
<p>Create your account by logging on to <a target="_blank" href="https://www.google.com/analytics/#?modal_active=none">Google Analytics</a>. In the upper right corner, login or create an account if you don’t have one.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/g6GtKsj59vZPgGJxt0yA3krKLIaOAYeJRK2Y" alt="Image" width="800" height="295" loading="lazy">
<em>courtesy of courtesy of Google Analytics Demo Site</em></p>
<p>Then select either website or mobile app. You will provide account name — typically the name of your business. Then set up the URL. Select either <a target="_blank" href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a> or HTTPS — start with HTTP if your site switches between HTTP and HTTPS.</p>
<p>Then select an industry category. This is an important step as it enables Google to set benchmarks for your site and compare your site’s performance with others in the same industry.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hrG4KeGDDMXLz0PcLRRknqlVLMX5KDY8ZnRo" alt="Image" width="655" height="535" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<p>Then select the reporting country and time zone. While not a critical issue, consider the time zone you select to be permanent. Though it can be changed, it will not retroactively change the data. Leave everything checked as these resources can become invaluable. You can read the “ReadMore” to learn how Google uses your data.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Oz8ADgYEqBeX2zQNDqb5c-O3G45yGiqpBk3r" alt="Image" width="658" height="467" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<p>Next, select “Get Tracking ID”. Review terms and services, and select “I accept”.</p>
<p>Now you will install your tracking tag. Select “Tracking Info” and then “Tracking Code”. The tracking code is a snippet of unique code that you will need to copy and paste to every page of your site that you want to be tracked by Google Analytics.</p>
<p>Copy your tracking code just below the <code>&lt;he</code>ad&gt; on your HTML page. Then go to “Google Tag Manager.” You can select the link to learn more about this. Click on “Status”. Here Google will let you know whether you are receiving data.</p>
<p><strong>Note:</strong><br>Here’s how to install the Google Analytics tracking tag on your <a target="_blank" href="http://www.wpbeginner.com/beginners-guide/how-to-install-and-setup-google-tag-manager-in-wordpress/">Wordpress pages.</a></p>
<p>Here’s how to install the Google Analytics tracking code onto your <a target="_blank" href="https://knowledge.hubspot.com/articles/kcs_article/cos-general/how-do-i-put-my-google-analytics-code-onto-my-new-landing-pages">HubSpot pages</a>.</p>
<h4 id="heading-creating-a-view">Creating a View</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/CGGFXWaEYdCl7nfG1EeC6Nyk3uCtstcnp69Z" alt="Image" width="800" height="201" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<p>It is considered a best practice that the first “View” you create is a Master View. A Master View contains an unfiltered history of the analytics, sort of like a backup.</p>
<h4 id="heading-creating-a-filter">Creating a Filter</h4>
<p>Google applies filters to your data before it presents it to you in your reports.<br>The most important filter to start with is excluding yourself and your employees from appearing in your data. You do not want your data appearing along with that of your users.</p>
<p>Create a filter that excludes the <a target="_blank" href="https://en.wikipedia.org/wiki/IP_address">IP addresses</a> for yourself. If you do not know you IP address, simply do a Google search for “what is my IP address?”. You will need to exclude the IP address for each computer used by yourself and your employees for work. These will need to be added individually.</p>
<p>From the Admin Panel, select the “Default View”. From the drop-down menu, select “Add Filter” and give it a name (such as Exclude Employees). Next, you have the option to select from a predefined filter or a custom filter.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ZI1rnM9kVQp9Y-KbzV-xDtfLUK4G0d4-CRBh" alt="Image" width="694" height="474" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<p>A predefined filter acts as a template for what you’d like to do. Select “predefined” and choose from the drop-down menu. Select “Exclude or Include only”. In this case, you will select traffic from the IP addresses and then select the appropriate expression. Enter the data to exclude, such as an IP address. Then “Save.”</p>
<p>From this point moving forward, all of the data in the default view is going to exclude any data that is excluded by this filter, but it is not going to historically exclude data.   </p>
<p>It is very common to add multiple filters. However, filter order matters. Filter order affects the subsequent results. Filter order matters because the output of one becomes the input of the next. Explore the filters to see what is most relevant to your organization’s goals.</p>
<p><strong>Note</strong>: If you want to include/exclude two things, you are essentially creating an “or” Filter. Go to Filter Field, then filter pattern. Type the first term to exclude then the pipe symbol (|) and the second term.</p>
<h4 id="heading-output">Output</h4>
<p>Google Analytics makes printing or sharing your analytics reports very easy. In the top right corner, you have the option of printing or sharing your report. It can also be saved and edited.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/TB28LGcdSb-ips3sh60vMUBWeBMYuMCmN7gg" alt="Image" width="479" height="231" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Q1mhFsjEdDkL6cgkJepNGgWNCCEtNEieTgjx" alt="Image" width="596" height="501" loading="lazy">
<em>courtesy of Google Analytics Demo Site</em></p>
<h3 id="heading-moving-forward">Moving Forward</h3>
<p>Google Analytics offers numerous reports, as well as data segmentation options, which are beyond the scope of this article. Find the reports that most closely align with your needs.</p>
<p>With the introduction of Google Analytics 360 Suite, formerly Google Analytics for premium users, Google’s analytics is only getting more advanced. Google Analytics 360 provides analytical data that companies can be used to track return on investment (ROI) and marketing indicators.</p>
<h3 id="heading-further-reading">Further Reading</h3>
<p>For a deep dive into Google Analytics, read <a target="_blank" href="https://www.wpbeaverbuilder.com/google-analytics-web-designers-developers/">Google Analytics for Web Designers and Developers</a>.</p>
<p>For tutorials for beginners can be found on <a target="_blank" href="https://analytics.google.com/analytics/academy/course/6">Google Analytics for Beginners</a>.</p>
<p>If you are a novice to coding, I recommend <a target="_blank" href="https://www.momscancode.com/">Moms can: Code</a> and <a target="_blank" href="https://www.codenewbie.org/">CodeNewbie</a>.</p>
<p>Follow me on <a target="_blank" href="https://twitter.com/JuliaBourbois">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Google Analytics from Santa and his Elves ]]>
                </title>
                <description>
                    <![CDATA[ By Christian-Peter Heimbach The holidays are here! It’s time to grab some egg nog, kick back by a fire place, and toast to all the coding you crammed into 2016. But wait! Before you sink into a carbohydrate-induced hibernation, let me tell you about ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-google-analytics-from-santa-and-his-elves-59ea82fbd99a/</link>
                <guid isPermaLink="false">66c359adf83dfae169b2c009</guid>
                
                    <category>
                        <![CDATA[ Christmas ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google Analytics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ marketing ]]>
                    </category>
                
                    <category>
                        <![CDATA[ startup ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 20 Dec 2016 18:41:46 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*ejm2tkSklF3ReBlktCIzIw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Christian-Peter Heimbach</p>
<p>The holidays are here! It’s time to grab some egg nog, kick back by a fire place, and toast to all the coding you crammed into 2016.</p>
<p>But wait! Before you sink into a carbohydrate-induced hibernation, let me tell you about a project that’s taking the North Pole by storm.</p>
<p>Rumor has it that Santa spent his summer break reading up on data and analytics. You didn’t think his global distribution empire ran purely on magic, did you?</p>
<p>Some tech savvy elves are indulging Santa by setting up Google Analytics in time for the big night.</p>
<p>You see, Santa, his elves, and children everywhere have a secret shared website that they all use to register and review wishes. I’m sworn not to reveal the actual URL, so we’ll just call it www.wish.io.</p>
<p>On this site, children can:</p>
<ol>
<li>See the benefits of wish.io</li>
<li>Have an opportunity to register as a good kid</li>
<li>Choose a present they wish to receive</li>
<li>Review their choice</li>
<li>Submit their wish</li>
</ol>
<p>As you can imagine, Santa and the elves can learn a lot from Google Analytics as to how they can further improve wish.io. Here’s how they’re putting it to work.</p>
<h3 id="heading-setting-up-google-analytics-for-santa">Setting Up Google Analytics for Santa</h3>
<p>To get Santa’s secret page ready for tracking, the elves need a Google Analytics tracking code. This is a Javascript code snippet (also often referred to as ‘pixel’ or ‘tracking snippet’) that you get after <a target="_blank" href="https://www.google.com/analytics/analytics/">signing up</a> for Google Analytics.</p>
<p>You can set up as many as 100 <strong>accounts</strong>, which can all contain multiple <strong>properties</strong>. These properties in turn can contain multiple <strong>views</strong>. This can seem confusing at first (especially if you’re an elf) but it’s not so bad if tackled one step at a time.</p>
<p>The elves will accomplish this in the admin area of Google Analytics. Let’s take a look.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/X2vD7aDhtGFC2emUEYa8wgbuaJiij-R96Jp9" alt="Image" width="800" height="539" loading="lazy">
<em>A screenshot of the Admin area of Google Analytics</em></p>
<p>Account properties describe websites, mobile apps, or other systems, each represented by a tracking code and unique ID — called a UA code. Here you can set up the property “Santa’s wish.io”. If Santa later decides to build subdomains or separate-but-related pages — like Santa’s naughtylist.io — he can set up an additional property here to avoid mixing data about good and naughty children.</p>
<p>You can define your user management for each level, but permissions are inherited per detail (account &gt; property &gt; views).</p>
<p>The elves have to think carefully about who should be able to see and modify what. It only takes one little green user who doesn’t know what they’re doing to mess up the settings and data.</p>
<p>So Santa makes sure that all the elves read the <a target="_blank" href="https://support.google.com/analytics/answer/2884495?hl=en">Google Analytics permission guide</a> before they can add users.</p>
<p>Google Analytics offers several views that the elves can use for a variety of purposes.</p>
<p>First, they can apply <strong>filters</strong>. This is useful because the elves generate a lot of internal traffic that needs removed, so that Santa can instead focus on the session data from children who are visiting the site.</p>
<p>Second, the elves can define <strong>goals</strong> and <strong>segments</strong> at the view level, so that each team can access the data that’s most interesting for them. After all, the logistics elves want a different sort of information than the front-end elves.</p>
<p>You can configure much more here, such as automatic reports and custom calculated metrics. But that’s a job for next summer.</p>
<h3 id="heading-elf-best-practices-in-setting-up-views">Elf Best Practices in Setting Up Views</h3>
<p>Next, the elves have to set up three standard views: www wish.io (Master), www wish.io (Test), and www wish.io (Raw).</p>
<p>These three views are essential due to the way Google Analytics operates: it applies filters between the steps of data collection and data processing.</p>
<p>This means that if the elves have a faulty filter, their data will vanish. For this reason, they need to set up a Raw view and never touch it so they have a fallback for emergencies. Every elf knows that the test view is for testing, and the master one is there to work with from day to day.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/s05oj4NVhw3evphxBrt4rJ-vCgWaJLn6Phs1" alt="Image" width="758" height="552" loading="lazy">
<em>A screenshot of adding new view with Google Analytics</em></p>
<h3 id="heading-how-the-elves-track-kids">How the Elves Track Kids</h3>
<p>With the backend of Google Analytics in place, the elves add a tracking snippet e of wish.io.</p>
<p>Yes, this is a gross violation of <a target="_blank" href="https://en.wikipedia.org/wiki/Children's_Online_Privacy_Protection_Act">COPPA</a>. But Santa doesn’t care about our laws. Heck, he doesn’t even care about the laws of physics.</p>
<p>They find the tracking code in the property section of the admin panel, then paste it into their website’s layout code.</p>
<p>The elves also take the vital step of ensuring that the script is located just before the <code>&lt;/he</code>ad&gt; closing tag. Usually, developers don’t want any render-blocking scripts here, but this is a special exception. The Google Analytics script is asynchronous, and ultimately the elves want to catch all traffic. They can’t risk missing the information of children who might leave a page before all scripts are loaded.</p>
<p>The <strong>bounce rate</strong> — which tracks the proportion of visitors who drop out of a page without engaging with any of the content — is an important metric. It might show the QA and front-end elves that something is wrong with the page. It also helps the marketing elves check whether a certain activity was poorly targeted.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/u7JKtpAs0Z-z4KtZXLhQuGoMsWgLtVgDoj6v" alt="Image" width="800" height="636" loading="lazy">
<em>A screenshot of the Google Analytics tracking code section</em></p>
<h3 id="heading-navigating-google-analytics">Navigating Google Analytics</h3>
<p>With tracking integrated, the elves were set to look at the initial data. Even though Google Analytics starts collecting real time data immediately, the elves decide to give it at least 24 hours so it can gather a meaningful amount of data.</p>
<p>Now the elves have to get familiar with Google Analytics, its various menus and data it displays.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/kLdOmNPDyFYNk08BQaAM0FMToZ3WezNjf7An" alt="Image" width="800" height="705" loading="lazy">
<em>Screenshot: Google Analytics Reporting Overview (Wish.io renamed Demo Account)</em></p>
<p>The left navigation menu shows the main sections the elves can use to look at a website’s data. The most important elements are Audience, Acquisition, Behavior, and Conversions.</p>
<p>This menu is also home to the Realtime and Intelligence Events view. Intelligence Events will cease to exist in Google Analytics soon, so Santa and the elves decided not to bother with it. The Realtime view is nice to show on flat-screens in Wish Operations HQ and boost moral among the elves. But meaningful decisions demand a longer-term view.</p>
<p>So the elves head back to Google Analytics main sections to check out what other tools it offers.</p>
<h3 id="heading-audience-overview">Audience Overview</h3>
<p>When the elves open a new property’s view, they see the Audience Overview by default. Fortunately, the overview pages are all similar, making the learning process a little smoother for elf and human alike.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/A-rft19qQovXYd6NToapWzMWcIMqgxP3XG5Q" alt="Image" width="800" height="715" loading="lazy"></p>
<p>In the area marked “1” (above), the elves get the most important information about their audience. How many users came to their page, how long they spent on it, and pages they saw per session etc. All this is nicely presented in graphs, so the elves can spot peaks, lows, and overall trends.</p>
<p>Looking at annotation (2), you’ll see that it’s possible to segment these overviews. This is true for all the main sections in Analytics. Now Santa can see whether kids browsing wish.io on the mobile phones they received last year behave differently to other users. The creation of segments is an advanced topic, but can be very rewarding. Segments can unearth context from the data which is otherwise only presented in rough averages. Note: You can use <a target="_blank" href="https://support.google.com/analytics/topic/3123779?hl=en&amp;ref_topic=6175347">Google’s in-depth guide on segments</a> or check the Gallery to import popular community-made segments.</p>
<p>Below the summary values (3), the elves have quick access to more detailed information each category offers. For example, they can see more demographics by country, or the technical context of users.</p>
<p>Even more detailed insights are available in the sub-categories of the left navigation bar (4).</p>
<p>One aspect of the detailed audience data added fuel to an already hot debate the elves were having over summer: the big question of which version of Internet Explorer wish.io should be backwards compatible with.</p>
<p>You can no doubt imagine how heated <em>that</em> became. Thankfully, Google Analytics has replaced the bickering with data driven decisions. Just use the left navigation and check out: Audience &gt; Technology &gt; Browser/OS and click on “Internet Explorer” for version details.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/6sZ8kHvD5Z7C3BExOcwRl4gQr8myXIFoXEOB" alt="Image" width="572" height="416" loading="lazy">
<em>Screenshot: Internet Explorer Sessions and Visitors per Browser Version</em></p>
<p>Luckily, Google Analytics records details of a browser’s specific version. Santa and the elves are pleased that 95% of Internet Explorer visitors use version 11. They also assuming that the good kids (who are the main audience for wish.io, of course) are diligent enough to either update Internet Explorer regularly, or to just use a better browser. Of course, the browser share for visitors to the upcoming naughtylist.io site will need to be evaluated separately.</p>
<p>There are lots of more great things the elves can learn here. For example, Google can show the kids’ Gender and Interest data (activated in the property settings under the admin panel — make sure you comply with your local laws, unlike Santa). It also allows them to delve much deeper into acquisition data and benchmark audience behavior based on the different channels visitors arrived from.</p>
<h3 id="heading-acquisition">Acquisition</h3>
<p>To learn more about where visitors came from to access wish.io, Santa can look at the Acquisition Overview.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/qWUntTHp5VkP6zac29-4Hin6IXaL4bbnaFu6" alt="Image" width="800" height="692" loading="lazy">
<em>Screenshot: Acquisition View showing visitors by traffic source</em></p>
<p>This view focuses on sources of traffic.</p>
<p>Google defines nine main channels in which it aggregates these sources:</p>
<p><strong>Direct:</strong> Usually people typing the URL or using a bookmark.</p>
<p><strong>Organic Search:</strong> People using Google or Bing, and clicking an organic search result link.</p>
<p><strong>Referral:</strong> Someone following a link on another website or blog.</p>
<p><strong>Social:</strong> Visitors originating from sites listed as social (click the ‘Social’ link to see the list).</p>
<p><strong>Email:</strong> All visits coming straight from emails.</p>
<p><strong>Paid Search:</strong> People accessing pages via paid links on Google and partner sites.</p>
<p><strong>Display:</strong> People that clicked paid advertising banners.</p>
<p><strong>Affiliates:</strong> Traffic received from affiliate partners that promote wish.io</p>
<p><strong>Others:</strong> A summary of advertising traffic classed as “special.” For example, traffic bought on a cost per action rate.</p>
<p>It’s important to understand that these groupings are the result of a set of default rules stating which medium counts for which traffic group.</p>
<p>The elves can fabricate links for social or advertising purposes — so-called UTM links — which are also summed up in these groups. This way they can judge how successful an ad or blog post was.</p>
<p>For convenience, they use <a target="_blank" href="https://ga-dev-tools.appspot.com/campaign-url-builder/">Google’s Link Builder tool</a>. To prevent false counting, they need to be aware of the <a target="_blank" href="https://support.google.com/analytics/answer/3297892?hl=en&amp;ref_topic=3125765">grouping rules</a> and set ‘utm_medium’ correctly.</p>
<p>Once everything is up and running, the elves can discover lots of interesting details about their channels. They can see which social channels contributed most to wish.io, or which campaigns were most successful. They can even optimize their AdWords’ investments and see which landing pages kids usually arrive on from various sources.</p>
<p>The next logical step for Santa is to gain — and act upon — a deeper understanding of exactly how visitors to his sites behave.</p>
<h3 id="heading-tracking-kids-behavior-on-wishio">Tracking kids’ behavior on wish.io</h3>
<p>For Santa and his elves, it’s always been hard to keep up with the many millions of different wishes kids might come up with. So it’s important for them to understand trends, popular choices, evergreens, and also potential errors across their millions of pages.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/miukLIfdpehZ0UL02qadfoj3hmzJR0ePFIik" alt="Image" width="800" height="617" loading="lazy">
<em>Screenshot: Behavior View showing visitors by page</em></p>
<p>Each elf department has its own information that is of interest.</p>
<p>The front-end and QA elves should always keep a close eye on bounce rates, average time on page, and the speed score of their most important pages.</p>
<p>Every front-end elf hates the lengthy SEO meetings triggered by wish.io’s loading times getting out of hand. So it’s helpful for them to explore the Site Speed subcategory. Google delivers great insights by browser, country, and page — as well as suggestions on how to improve.</p>
<p>UX elves can get an insight into priority pages in the Behavior section. They can also look at the flow of where people enter Santa’s page, their journey, and where they exit.</p>
<p>But the most exciting topic for them is building content experiments. Basically, they can ask the front-end elves to build alternative versions of the same page, then automatically test these versions against measurable objectives.</p>
<p>For example, it might be of interest to find a page variant where kids stay longer or submit wishes at a better rate. They can set up initial experiments with the analytics tool, which has a <a target="_blank" href="https://support.google.com/analytics/topic/1745146?hl=en&amp;ref_topic=1120718">simple guide</a>. For advanced use cases, elves can carry out content experiments via the <a target="_blank" href="https://developers.google.com/analytics/devguides/collection/analyticsjs/experiments">well-documented analytics.js API</a>.</p>
<p>Finally, the Behavior tab also offers event tracking, which the marketing elves <em>love</em>. Events can be sent back to Google Analytics whenever kids initiate an important action that doesn’t trigger a new pageview.</p>
<p>For example, when kids click download buttons, submit their “I have been a good kid” forms, amend a wish, and more. Events are straightforward function calls to the analytics API. Elves add them to their Javascript event listeners and callbacks that control the interactivity of their page. All of this is described over at <a target="_blank" href="https://developers.google.com/analytics/devguides/collection/analyticsjs/events">Google’s event tracking guide</a>.</p>
<p>Marketing elves love event tracking because it puts them in a better position to configure the all-important Conversions element of Google Analytics.</p>
<h3 id="heading-conversions">Conversions</h3>
<p>Setting up the Conversion section in the admin panel took some effort from Santa and his team, but it was worth it. Conversions will help the elves to understand the “business” effects of all formerly looked at insights. This closes the loop between having a lot of data and understanding how it leads to the ultimate goal: happy kids.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/2UcYbZKhcwKbNjHqtnGtygqzpire7gXX6PsT" alt="Image" width="800" height="690" loading="lazy">
<em>Screenshot: Conversions showing goal completion by location</em></p>
<p>Goals are not set by default in Google Analytics. Users need to define them in the admin panel. Goals are defined by the underlying type of interaction. This could be either the viewing of a certain page (e.g. thankyou.html), a behavior (minimum duration on site, amount of pages per session), or when an event is recorded. You can even define a series of destinations to show as a single goal.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/SYunT2hbndHmlnUDKvz0u4n67RMMNdNn6Kjo" alt="Image" width="690" height="604" loading="lazy"></p>
<p>This is important when you want to track how many children have gone through a whole conversion “funnel.” For example, they enter the registered kids’ area, browse through the wish options, and successfully submit a wish.</p>
<p>With this funnel goal tracked, the visualization shows how children go through every step. It also reveals to what extent (and when) they drop out, and where they go from there.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ckhQRIT29LrgdccJl-CGAyha56JjcfNnYtMj" alt="Image" width="698" height="1043" loading="lazy"></p>
<p>It’s important to note that goals should be defined in a way that they don’t overlap each other. If one event generates the counting of two goals, your conversion rates can be too high.</p>
<p>In addition to using Goals, it’s possible to wire the entire Santa ecommerce system into Google Analytics. But that’s a job for the new year. Once that deep integration is up and running though, Santa &amp; Co. will gain insights down to a per-wish “order” level, and will even be able to track wish returns.</p>
<p>Another useful Google Analytics view was the Multi Channel Funnels sub-category. Before Google Analytics, the marketing elves often argued over budget allocation, and who contributed the most overall wishes submitted.</p>
<p>The brand advertising elves complained that their work not only impacted direct traffic, but search and social as well. They figured some children initially came via their social media posts, but returned later to submit wishes by typing the wish.io URL.</p>
<p>So why should the last elf involved take all the credit? They shouldn’t. Which is why every marketing meeting in the North Pole now includes a look at the Assisted Conversions and Top Conversion Paths. Here the elves can see not only their direct conversion value, but also the value of conversions they helped to close.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/tt5MyDBzDOns6gqrfVIzmPIy62TSnoRa3t4Z" alt="Image" width="800" height="879" loading="lazy">
<em>Screenshot: Assisted Conversions per traffic source</em></p>
<h3 id="heading-a-job-well-done">A job well done</h3>
<p>Thanks to his Google Analytics project, Santa has dubbed 2016 as “the year of data driven decisions.” He’s happy his elves have turned once-heated discussions into data competitions and experiments.</p>
<p>From now on, he’ll be using the power of data to encourage his team’s scientific spirit — and to find ever-optimized processes for boosting happiness.</p>
<p>Now all that remains is for me to wish you and your loved ones’ happy holidays. I hope that this little tale from the North Pole has inspired you to make your 2017 even more successful, and data driven.</p>
<p>Now, let’s all slip into our <a target="_blank" href="https://medium.freecodecamp.com/the-geekiest-ugly-sweater-ever-34a2e591483f">ugly holiday sweaters</a> and embrace the holiday spirit.</p>
<p>Special Thanks to Craig Rennie of <a target="_blank" href="https://www.draft-punk.com">Draft Punk</a> and Quincy at <a target="_blank" href="https://www.freecodecamp.com/">Free Code Camp</a> for all their editing efforts. May your holidays be extra happy!</p>
<p><strong>Disclaimer:</strong> <em>This story is written in a holiday theme for entertainment purposes only. Despite the above report about Santa, elves, and children it is important to note that Google Analytics doesn’t track or share audience information of anyone under 18.</em></p>
<p><em>All data and images are courtesy of Google. The data shown here is available for every analytics account via accessing the <a target="_blank" href="https://support.google.com/analytics/answer/6367342?hl=en">Google Analytics Demo Account</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
