<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adam O'Reilly</title>
    <description>The latest articles on DEV Community by Adam O'Reilly (@aor2405).</description>
    <link>https://dev.to/aor2405</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%2F873809%2F4e25124b-31a2-42e1-99b0-dc15dd59340d.png</url>
      <title>DEV Community: Adam O'Reilly</title>
      <link>https://dev.to/aor2405</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aor2405"/>
    <language>en</language>
    <item>
      <title>JavaScript: What the **** is Recursion?</title>
      <dc:creator>Adam O'Reilly</dc:creator>
      <pubDate>Wed, 06 Jul 2022 09:32:35 +0000</pubDate>
      <link>https://dev.to/aor2405/javascript-what-the-is-recursion-3770</link>
      <guid>https://dev.to/aor2405/javascript-what-the-is-recursion-3770</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;JavaScript functions are one of the fundamental building blocks to JavaScript programming. A function is simply defined as a block of code designed to perform a certain task. Generally speaking, a function normally takes in an input and returns an output. One type of function is a recursive function.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what exactly is recursion?
&lt;/h2&gt;

&lt;p&gt;In computer science, recursion is the process of a function that calls itself from within its own code. This concept is used throughout many programming languages including JavaScript. We can think of this as an alternative to iterating (for/while loops). General rule of thumb is that we use recursion to make our code more readable however, it can sometimes be less efficient than iterating. An example as to where recursion can be helpful is that it can be used for searching and sorting algorithms such as traversing through a binary search tree&lt;/p&gt;

&lt;h2&gt;
  
  
  The 4 steps of recursion:
&lt;/h2&gt;

&lt;p&gt;A recursive function is made up of 4 steps.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Identify the base case, this will avoid “Stack Overflow” (explained below)&lt;/li&gt;
&lt;li&gt;Identify the recursive cases&lt;/li&gt;
&lt;li&gt;Return where appropriate&lt;/li&gt;
&lt;li&gt;Write procedures for each case that bring you closer to your base case
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;recursiveFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// Base Case&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="c1"&gt;// Return when base case has been met&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;recursiveFunc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Recrusive Case&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each time a recursive function is called, the function itself is added to the call stack. These functions will then be popped off the call stack when the base case has been met. If we do not implement a base case, our recursive functions will infinitely be called and these functions will continue to be added to our call stack until our memory limit has been reached and our application crashes. This is known as “Stack overflow”.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use it?
&lt;/h2&gt;

&lt;p&gt;Sometimes we encounter a problem that is too complex to solve directly. We use recursion by breaking up the problem in to smaller, repetitive pieces. We can solve these smaller pieces and then build back up a solution to the entire problem.&lt;/p&gt;

&lt;p&gt;For example, when working with tree data structures, it can be useful to use recursion to traverse when you are unsure of how deep the tree is and how many loops you will need to traverse throughout it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Recursion vs iteratively(looping)
&lt;/h2&gt;

&lt;p&gt;As I explained above, recursion can be used as an alternative to looping. Recursion can always be implemented as a loop but in some situations, it is simpler to use recursion. A big benefit of using recursion is that it is more elegant than using a for loop making it easier to read and debug. It is important to note that iterating is faster and recursion can be a worse option to use if space complexity is important to you.&lt;/p&gt;

&lt;p&gt;As shown in the example below, we are implementing a function for a Fibonacci sequence using both a for loop and a recursive method. From these examples, we can see why a recursion function is a better approach to take as it is less cluttered and easier to read.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;fibonacciIterative&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;array&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;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&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;fibonacciRecursive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;n&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;fibonacciRecursive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;fibonacciRecursive&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&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;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Recursion itself can be a bit of a pain to wrap your head around but take the time to research and get comfortable with it as it really has some amazing benefits to using it.&lt;/p&gt;

&lt;p&gt;Pros:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Readability&lt;/li&gt;
&lt;li&gt;DRY&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Space complexity&lt;/li&gt;
&lt;li&gt;Risk of stack overflow&lt;/li&gt;
&lt;li&gt;Confusing concept to new developers, may cause issues if using it in your code base&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Links
&lt;/h1&gt;

&lt;p&gt;linkedIn — &lt;a href="https://linkedin.com/in/adam-o-reilly-js"&gt;https://linkedin.com/in/adam-o-reilly-js&lt;/a&gt;&lt;br&gt;
portfolio - &lt;a href="https://www.adamoreilly.com/"&gt;https://www.adamoreilly.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>recursion</category>
      <category>webdev</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>The beauty of Google Analytics</title>
      <dc:creator>Adam O'Reilly</dc:creator>
      <pubDate>Wed, 22 Jun 2022 10:47:04 +0000</pubDate>
      <link>https://dev.to/aor2405/the-beauty-of-google-analytics-1gdg</link>
      <guid>https://dev.to/aor2405/the-beauty-of-google-analytics-1gdg</guid>
      <description>&lt;h2&gt;
  
  
  Why?
&lt;/h2&gt;

&lt;p&gt;I recently completed and deployed my first portfolio site. After this, I sat back and thought about how cool it would be to be able keep track of page views in order to see how many people where clicking into my site. After searching through reddit posts and blogs, I kept seeing mention of Google Analytics.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Google analytics?
&lt;/h2&gt;

&lt;p&gt;Google analytics is a free analytics tool that allows you to analyse in great detail about your websites traffic. By gathering this data, we can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See the total number of users to the site&lt;/li&gt;
&lt;li&gt;See the split between new and previously viewed users&lt;/li&gt;
&lt;li&gt;The average number of pages a user views in your website&lt;/li&gt;
&lt;li&gt;The average for how long a user spends on your site&lt;/li&gt;
&lt;li&gt;Which countries/cities a user used to view your website&lt;/li&gt;
&lt;li&gt;Which operating system/browser a user used to view your website&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Your NextJs project&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;a href="https://analytics.google.com"&gt;google analytics&lt;/a&gt; account&lt;/li&gt;
&lt;li&gt;Google analytics measurement ID (can be found in admin/data streams/the stream you just set up&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1
&lt;/h2&gt;

&lt;p&gt;Inside your .env located in the root folder, we can add our Google ID as shown below. You could skip this step by inserting the Google ID directly into the code in step 2 but I prefer to put ID such as this in an .env file for protection.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1H9yRCzT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lnhmmiwyx5bw1sz0rdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1H9yRCzT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8lnhmmiwyx5bw1sz0rdw.png" alt=".env file" width="880" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2
&lt;/h2&gt;

&lt;p&gt;Create a _document.js file in the root directory. This will be where we place the monitoring code for google analytics. Copy and paste the code below to your file.&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;Document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Html&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Head&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NextScript&lt;/span&gt; &lt;span class="p"&gt;}&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;next/document&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CustomDocument&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Document&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;getInitialProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;initialProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getInitialProps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;initialProps&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Html&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;en-US&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;
            &lt;span class="k"&gt;async&lt;/span&gt;
            &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`https://www.googletagmanager.com/gtag/js?id=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEXT_PUBLIC_GOOGLE_ANALYTICS&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&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;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;
            &lt;span class="nx"&gt;dangerouslySetInnerHTML&lt;/span&gt;&lt;span class="o"&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;`
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', '&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NEXT_PUBLIC_GOOGLE_ANALYTICS&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;', {
              page_path: window.location.pathname,
            });
            `&lt;/span&gt;&lt;span class="p"&gt;,&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;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Head&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;NextScript&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/body&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Html&lt;/span&gt;&lt;span class="err"&gt;&amp;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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;CustomDocument&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3
&lt;/h2&gt;

&lt;p&gt;Now on to the final step, testing. At this point you can deploy your project and head over the Google analytics website. Unfortunately it takes Google analytics 24–48 hours to populate the data, however, we can take a look the Real-time tab which will give you an insight to the active users on your site over the past 5 minutes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GUhq-Lk9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j2id1z1je2jimeyfgah.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GUhq-Lk9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5j2id1z1je2jimeyfgah.png" alt="Real-time overview" width="880" height="479"&gt;&lt;/a&gt; &lt;em&gt;Real-time overview of current users viewing the website&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After the waiting period when the data has been collected you will be able to select the Audience tab and into Overview where you can see the breakdown of your websites traffic over a selected period of time.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aa-F9Db5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9mmz3y2hunkpn4jte6c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aa-F9Db5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9mmz3y2hunkpn4jte6c.png" alt="Traffic overview" width="880" height="479"&gt;&lt;/a&gt; &lt;br&gt;
&lt;em&gt;Overview of user traffic over two days&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;Congratulations, you have now setup your project with Google analytics. At this point you should now begin to see the power of GA and how you can now use this data to monitor the overall traffic and see the strengths and weaknesses of your website.&lt;/p&gt;




&lt;h1&gt;
  
  
  Links
&lt;/h1&gt;

&lt;p&gt;Google Analytics — &lt;a href="https://analytics.google.com"&gt;https://analytics.google.com&lt;/a&gt;&lt;br&gt;
NextJs — &lt;a href="https://nextjs.org/"&gt;https://nextjs.org/&lt;/a&gt;&lt;br&gt;
linkedIn — &lt;a href="https://linkedin.com/in/adam-o-reilly-js"&gt;https://linkedin.com/in/adam-o-reilly-js&lt;/a&gt;&lt;br&gt;
portfolio - &lt;a href="https://www.adamoreilly.com/"&gt;https://www.adamoreilly.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>nextjs</category>
      <category>googleanalytics</category>
    </item>
    <item>
      <title>The beauty of Sanity</title>
      <dc:creator>Adam O'Reilly</dc:creator>
      <pubDate>Wed, 08 Jun 2022 08:21:10 +0000</pubDate>
      <link>https://dev.to/aor2405/the-beauty-of-sanity-4421</link>
      <guid>https://dev.to/aor2405/the-beauty-of-sanity-4421</guid>
      <description>&lt;p&gt;One of the most exciting aspects of web development is the seemingly endless amounts of tools that are at your fingertips. I always use the opportunity of starting a new project to explore different libraries, frameworks, platforms and tools that I have not used before.&lt;/p&gt;

&lt;p&gt;A project that I decided to recently undertake was to build my own E-commerce application. For the frontend, I decided to use NextJS. NextJs comes with some amazing features that can optimise the websites performance and makes it easier/quicker to create a website as NextJS is built upon the React library. I also decided to use TailwindCSS to style my application due to its ease of use and the ability to create beautifully styled components.&lt;/p&gt;

&lt;p&gt;While researching E-commerce sites, I came across Sanity. After reading through the Sanity documentation and watching a few videos on it, I was blown away at the capabilities of this platform. By using Sanity, I no longer needed to create a backend server using Express like I normally would have. I did not need to connect to a database such as MongoDb or Postgres. I didn’t need to create API’s in order to send and retrieve data from my database. Where it might have taken me a few days to create this backend, I managed to incorporate Sanity to my application in a couple of hours. It massively cut down my workload which is a huge plus in my books.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Sanity??
&lt;/h2&gt;

&lt;p&gt;For those of you who don’t know, Sanity is a headless CMS, basically a platform for structured content that allows you to store data for your website/applications. Being that it is ‘Headless’, simply means you can plug it into any frontend framework of your choice. The best feature that comes with Sanity is the Sanity Studio. The Sanity Studio is a dashboard that allows you the manage your content that is then used to display on your website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G7nl6xUi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w55n3y7w0mvii909huo7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G7nl6xUi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w55n3y7w0mvii909huo7.png" alt="Sanity Studio" width="880" height="464"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Example of Sanity studio&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After connecting Sanity to your application, you can create a schema that will be the structure of your data. For example, in my E-commerce application, I need to display a product that will be for sale. In my Schema, I defined this product, giving it information such as a title, an image, a price, a description and a list of features etc. After creating this schema, I can go over to the Sanity Studio. Once here, I can create a new product where I will be met with the input fields that I defined inside my Schema.&lt;/p&gt;

&lt;p&gt;Once this product has been created, I can head back over to my application and using a very simple query, can retrieve this data from Sanity and display it on my website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JYkw_Z2X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3had9ngtfxskrknz3sjp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JYkw_Z2X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3had9ngtfxskrknz3sjp.png" alt="Product example" width="880" height="600"&gt;&lt;/a&gt; &lt;em&gt;Data retrieved from Sanity and displayed on website&lt;/em&gt; &lt;/p&gt;

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

&lt;p&gt;Sanity is a fantastic and easy to use platform for both developers and admins of your website/application. After the completion of my E-commerce application, I am happy to say that I enjoyed my time using Sanity and will definitely be recommending it and using it again myself in the future.&lt;/p&gt;




&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;p&gt;Sanity — &lt;a href="https://www.sanity.io/"&gt;https://www.sanity.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NextJs — &lt;a href="https://nextjs.org/"&gt;https://nextjs.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;E-commerce website — &lt;a href="https://rye-river-electronics.vercel.app/"&gt;https://rye-river-electronics.vercel.app/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;linkedIn — linkedin.com/in/adam-o-reilly-js&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>sanity</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
