<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jessica Valencia</title>
    <description>The latest articles on Forem by Jessica Valencia (@jessica000).</description>
    <link>https://forem.com/jessica000</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F476523%2Fc79e1e3a-7134-4010-b99c-d05c026f4b68.png</url>
      <title>Forem: Jessica Valencia</title>
      <link>https://forem.com/jessica000</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jessica000"/>
    <language>en</language>
    <item>
      <title>Upgrade to the next generation of Google Analytics in Gatsby project</title>
      <dc:creator>Jessica Valencia</dc:creator>
      <pubDate>Sun, 25 Oct 2020 20:32:10 +0000</pubDate>
      <link>https://forem.com/jessica000/upgrade-to-the-next-generation-of-google-analytics-in-gatsby-project-2hhg</link>
      <guid>https://forem.com/jessica000/upgrade-to-the-next-generation-of-google-analytics-in-gatsby-project-2hhg</guid>
      <description>&lt;p&gt;&lt;small&gt;Cover image produced by &lt;a href="https://storage.googleapis.com/gweb-uniblog-publish-prod/images/E02584187-Google-GMP-Future-of-Analytics-B.max-1000x1000.png"&gt;Google&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Did you know that Google has released &lt;a href="https://blog.google/products/marketingplatform/analytics/new_google_analytics/"&gt;new Google Analytics&lt;/a&gt; a couple of weeks ago?&lt;/p&gt;

&lt;p&gt;It's perfectly OK if you didn't. Until a few hours ago, I myself didn't know about it. Although I use Google Analytics everyday for my website(&lt;a href="https://casinohouse.link"&gt;카지노사이트&lt;/a&gt;) SEO. Somehow Google Analytics haven't shown me any update alerts or messages. I heard about it from some of my colleagues.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's new in updated version?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Google Analytics can now detect device switching (like when a user changes from mobile to desktop) and will show you unified and integrated web &amp;amp; app reporting.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;And &lt;a href="https://www.socialmediatoday.com/news/google-launches-updated-google-analytics-including-improved-reporting-and/587052/"&gt;much more&lt;/a&gt; that I don't understand right now&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Most importantly: &lt;a href="https://support.google.com/analytics/answer/10089681#start"&gt;It is now default experience for all Google Analytics properties and where Google is investing for future improvements.&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;As I wrote in the follwing DEV post&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/jessica000" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3qPDxoQ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/practicaldev/image/fetch/s--F9SKBPma--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/476523/c79e1e3a-7134-4010-b99c-d05c026f4b68.png" alt="jessica000 image"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/jessica000/how-i-got-perfect-google-lighthouse-score-with-gatsby-5coj" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;How I got perfect  Google Lighthouse score with Gatsby&lt;/h2&gt;
      &lt;h3&gt;Jessica Valencia ・ Sep 28 ・ 4 min read&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#showdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webperf&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#gatsby&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;my website(&lt;a href="https://casinohouse.link"&gt;카지노사이트&lt;/a&gt;) is built with Gatsby.&lt;/p&gt;

&lt;p&gt;In Gatsby.js, you install legacy (well, not yet but if you know what I mean) Google Analytics with &lt;a href="https://www.gatsbyjs.com/plugins/gatsby-plugin-google-analytics/"&gt;gatsby-plugin-google-analytics&lt;/a&gt;. Like this way:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;gatsby-config.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gatsby-plugin-google-analytics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;trackingId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UA-1*******0-2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;head&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;defer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problem is, you cannot install newer version of Google Analytics in this way. And as far as I know, there is not a gatsby plugin for newer version yet. :(&lt;/p&gt;

&lt;h2&gt;
  
  
  Goal
&lt;/h2&gt;

&lt;p&gt;For updated version, you need to add measurement ID that looks like &lt;code&gt;G-**********&lt;/code&gt; and need to&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Copy and paste this code as the first item into the &lt;/p&gt; of every webpage you want to measure.&lt;br&gt;

&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- Global site tag (gtag.js) - Google Analytics --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;async&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.googletagmanager.com/gtag/js?id=G-**********"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;gtag&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;
  &lt;span class="nx"&gt;gtag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

  &lt;span class="nx"&gt;gtag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;config&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;G-**********&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Get GA4 stream measurement ID
&lt;/h3&gt;

&lt;h4&gt;
  
  
  First, log in to your &lt;a href="https://analytics.google.com/"&gt;Google Analytics&lt;/a&gt; account and click "Admin" button.
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7nagoxT3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ign8dqizhrgweknv39cx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7nagoxT3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ign8dqizhrgweknv39cx.png" alt="GA4 upgrade step1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Next, click "Create Property" button.
&lt;/h4&gt;

&lt;p&gt;Just ignore "Upgrade to GA4" here. It will take you to create property screen anyway.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z3M7fB3k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n4zedi3ae40xf6z6fpsx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z3M7fB3k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n4zedi3ae40xf6z6fpsx.png" alt="GA4 upgrade step2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Configure your property. Do as you like.&lt;/p&gt;

&lt;h4&gt;
  
  
  Then, select created property and click "Data Stream" tab, then click "Add stream" -&amp;gt; Web.
&lt;/h4&gt;

&lt;p&gt;If you already have a Web stream, just click to see its details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ls4iN8gy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n953jcc8rcq1y4m5tw5b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ls4iN8gy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n953jcc8rcq1y4m5tw5b.png" alt="GA4 upgrade step3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  In detail page, you can get your measurement ID and gtag script:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k0IXJU0k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7fkiofx0aroclkedsahn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k0IXJU0k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7fkiofx0aroclkedsahn.png" alt="GA4 upgrade step4"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Install acquired gtag in Gatsby project
&lt;/h3&gt;

&lt;p&gt;My approach is a workaround but it will do its work before gatsby plugin update. I customized &lt;code&gt;html.js&lt;/code&gt; as described in this &lt;a href="https://www.gatsbyjs.com/docs/custom-html/"&gt;article&lt;/a&gt;. FYI, &lt;code&gt;html.js&lt;/code&gt; is what Gatsby uses to server render &lt;code&gt;head&lt;/code&gt; tag and other components that React cannot touch.&lt;/p&gt;

&lt;h4&gt;
  
  
  First, copy &lt;code&gt;.cache/default-html.js&lt;/code&gt; to &lt;code&gt;html.js&lt;/code&gt;.
&lt;/h4&gt;

&lt;p&gt;If you already have &lt;code&gt;html.js&lt;/code&gt;, you can skip this step.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; .cache/default-html.js src/html.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;html.js&lt;/code&gt; will look like the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;htmlAttributes&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;charSet&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;httpEquiv&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"x-ua-compatible"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ie=edge"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt;
          &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1, shrink-to-fit=no"&lt;/span&gt;
        &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headComponents&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bodyAttributes&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Edit &lt;code&gt;head&lt;/code&gt; tag like the following:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;
        &lt;span class="na"&gt;async&lt;/span&gt;
        &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://www.googletagmanager.com/gtag/js?id=G-**********"&lt;/span&gt;
    &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;
        &lt;span class="na"&gt;dangerouslySetInnerHTML&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;__html&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="err"&gt;
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', 'G-**********');
        &lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;charSet&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt; &lt;span class="na"&gt;httpEquiv&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"x-ua-compatible"&lt;/span&gt; &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"ie=edge"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;meta&lt;/span&gt;
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt;
        &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1, shrink-to-fit=no"&lt;/span&gt;
    &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headComponents&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;head&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Deploy your project.
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Go to your Google Analytics and check if it works.
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HW4vEbK3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3r40udylm6jw4yq28h3f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HW4vEbK3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3r40udylm6jw4yq28h3f.png" alt="카지노사이트 바카라사이트 https://casinohouse.link"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can uninstall legacy tracking code and gatsby plugin after successful upgrade.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;That's all folks!&lt;/p&gt;

&lt;p&gt;If you find anything wrong in my post or have a better idea, please leave a comment to let me know.&lt;/p&gt;

&lt;p&gt;If you're good at Gatsby.js, please come visit my &lt;a href="https://casinohouse.link"&gt;website&lt;/a&gt; and share your idea. Any suggestion is welcome!&lt;/p&gt;

</description>
      <category>gatsby</category>
      <category>react</category>
      <category>seo</category>
      <category>webmaster</category>
    </item>
    <item>
      <title>How I got perfect  Google Lighthouse score with Gatsby</title>
      <dc:creator>Jessica Valencia</dc:creator>
      <pubDate>Mon, 28 Sep 2020 21:09:59 +0000</pubDate>
      <link>https://forem.com/jessica000/how-i-got-perfect-google-lighthouse-score-with-gatsby-5coj</link>
      <guid>https://forem.com/jessica000/how-i-got-perfect-google-lighthouse-score-with-gatsby-5coj</guid>
      <description>&lt;p&gt;A few weeks ago, I got assigned a project to open a website for SEO. Targeted keyword is &lt;code&gt;casino know-hows&lt;/code&gt; and &lt;code&gt;online casino website&lt;/code&gt;, which are very competitive in local.&lt;/p&gt;

&lt;p&gt;I have used &lt;a href="https://wordpress.org" rel="noopener noreferrer"&gt;WordPress&lt;/a&gt; and &lt;a href="https://wix.com" rel="noopener noreferrer"&gt;Wix&lt;/a&gt; for my SEO projects before. But this time, I decided to use &lt;a href="https://gatsbyjs.com" rel="noopener noreferrer"&gt;Gatsby&lt;/a&gt; because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It should be blazingly fast for more competitive power&lt;/li&gt;
&lt;li&gt;The website will be purely static&lt;/li&gt;
&lt;li&gt;I wanted to have source code under my control&lt;/li&gt;
&lt;li&gt;I wanted to challenge a new technique&lt;/li&gt;
&lt;li&gt;And of course, it's React, so why not?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It took me 8 days for me to build a website from scratch and deploy to a server. The website &lt;a href="https://casinohouse.link" rel="noopener noreferrer"&gt;카지노&lt;/a&gt; has 46 pages. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://casinohouse.link" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcasinohouse.link%2Fimg%2Fog-image.jpg" alt="카지노 | 바카라 | 먹튀 검증 - 카지노 하우스"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google lighthouse and gtmetrix score is fairly high.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc90qejwmxzmap1sux7qi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fc90qejwmxzmap1sux7qi.png" alt="카지노 사이트 추천 먹튀 검증 카지노 하우스 casinohouse.link google lighthouse score"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff1kz14ynwg973e5n0qv4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ff1kz14ynwg973e5n0qv4.jpg" alt="바카라 사이트 온라인 카지노 사이트 모음 카지노 하우스 casinohouse.link gtmetrix score"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;* Lighthouse score may vary according to locations and browsers&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;I'd like to share my experience passing google lighthouse audits:&lt;/p&gt;

&lt;h2&gt;
  
  
  Serve images in next-gen formats
&lt;/h2&gt;

&lt;p&gt;You may have seen this message almost every time optimizing your website performance.&lt;/p&gt;

&lt;p&gt;Google lighthouse really likes webp but webp images are notorious for not working with iOS browsers. There are workarounds like using &lt;code&gt;&amp;lt;picture&amp;gt;&lt;/code&gt; tag, but it's a repetitive and dull work. I'm sure many developers give up with webps and just stick to jpg images.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://gatsbyjs.com/plugins/gatsby-image" rel="noopener noreferrer"&gt;gatsby-image&lt;/a&gt;, you won't have this headache ever again.&lt;/p&gt;

&lt;p&gt;For example, I use graphQL queries like this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight graphql"&gt;&lt;code&gt;&lt;span class="k"&gt;query&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;BlogPostByID&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;!)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="n"&gt;markdownRemark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;fields&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;description&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;tag&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;featuredimage&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;publicURL&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="n"&gt;childImageSharp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="n"&gt;fluid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;maxWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;quality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="n"&gt;GatsbyImageSharpFluid_withWebp&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in my component, I render like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Img&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gatsby-image&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Img&lt;/span&gt; &lt;span class="nx"&gt;fluid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;childImageSharp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fluid&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in my html, I get element like this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3q3op9j35jl0lje2gsiv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3q3op9j35jl0lje2gsiv.jpg" alt="바카라 사이트 모음 카지노 사이트 추천 안전놀이터 카지노 하우스 casinohouse.link webp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that there is an &lt;code&gt;img&lt;/code&gt; tag with base64 encoded source. It is the blurred version of the original image. It's first shown before high-quality image is fully loaded. &lt;code&gt;gatsby-image-sharp&lt;/code&gt; will crop and resize your images and generate thumbnails when you build your pages. All images are sized correctly and much network payload is saved.&lt;/p&gt;

&lt;p&gt;It was like magic!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gotcha&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Please notice that I set webp quality as 64. &lt;a href="https://help.shortpixel.com/article/102-why-the-resulting-webp-images-are-bigger-than-the-original-png-files" rel="noopener noreferrer"&gt;It is known&lt;/a&gt; that lossless (or with 100% quality) webp compression will increase the size by 30%.&lt;/p&gt;

&lt;p&gt;In other words, if you set quality to 100, webp image size will be bigger than your original image size.&lt;/p&gt;

&lt;h2&gt;
  
  
  Serve static assets with an efficient cache policy
&lt;/h2&gt;

&lt;p&gt;Lighthouse requires you to return &lt;code&gt;Cache-Control&lt;/code&gt; HTTP response header like this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Cache-Control: max-age=31536000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find how to set &lt;code&gt;Cache-Control&lt;/code&gt; header in nginx and apache in &lt;a href="https://www.tezify.com/how-to/serve-static-assets-with-an-efficient-cache-policy/" rel="noopener noreferrer"&gt;this artice&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gotcha&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;31536000 actually means 365 days or a year. I tried to reduce this value to 10 days(or 864000) but the warning message did not disappear. So I think you should leave it as it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enable text compression
&lt;/h2&gt;

&lt;p&gt;Gzip compression greatly reduces network bytes by compressing text-based resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://varvy.com/pagespeed/enable-compression.html#:~:text=The%20ideal%20way%20to%20enable,Gzip%20options%20that%20are%20nearby." rel="noopener noreferrer"&gt;Here&lt;/a&gt; you can find how to enable gzip compression in apache and nginx.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background and foreground colors have a sufficient contrast ratio
&lt;/h2&gt;

&lt;p&gt;I've seen many websites fail this audit. You might have to change your color palette if you want to pass this one. &lt;/p&gt;

&lt;p&gt;According to lighthouse:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text that is 18pt, or 14pt and bold, needs a contrast ratio of 3:1,&lt;/li&gt;
&lt;li&gt;All other text needs a contrast ratio of 4.5:1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can put Chrome DevTools's color picker to good use to check your contrast ratio:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwebdev.imgix.net%2Fcolor-contrast%2Fcolor-picker.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwebdev.imgix.net%2Fcolor-contrast%2Fcolor-picker.png" alt="color picker"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gotcha&lt;/strong&gt;&lt;br&gt;
If the background uses an image or animated css, lighthouse may not decide contrast ratio. In this case, the audit will be failed although it has enough contrast to the human eyes.&lt;/p&gt;

&lt;p&gt;For example, &lt;a href="https://casinohouse.link" rel="noopener noreferrer"&gt;casinohouse.link&lt;/a&gt; footer uses css animation. I couldn't persuade lighthouse that the footer had enough contrast ratio. As a workaround, I added another background color to links. And it looked better in that way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frkbnoci8ke8wpqe6sm70.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frkbnoci8ke8wpqe6sm70.jpg" alt="2020 한국 1위 카지노 커뮤니티 먹튀검증업체 메이저업체 카지노 하우스"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Use HTTP/2 for all of its resources
&lt;/h2&gt;

&lt;p&gt;My hosting web server uses CentOS and apache. Unfortunately, it uses HTTP1.1. I found out that &lt;a href="https://stackoverflow.com/questions/40720703/how-to-enable-http2-on-centos7" rel="noopener noreferrer"&gt;it was not that easy to make it use http2&lt;/a&gt;. As a workaround, I enabled &lt;a href="https://support.cloudflare.com/hc/en-us/articles/201720164-Creating-a-Cloudflare-account-and-adding-a-website" rel="noopener noreferrer"&gt;cloudflare&lt;/a&gt; for my domain. Then, the problem solved within a minute. And it was even FREE!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;All the other audits were already handled by Gatsby. It was really convinient. Although this was the first time I used a Static Site Generator, I got satisfying result and I think my selection was perfect. &lt;/p&gt;

&lt;p&gt;Please take a look around of my &lt;a href="https://casinohouse.link" rel="noopener noreferrer"&gt;website&lt;/a&gt; and feel free to suggest any ideas and further optimizations.&lt;/p&gt;

&lt;p&gt;Thanks for reading!&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>webperf</category>
      <category>gatsby</category>
    </item>
  </channel>
</rss>
