<?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[ Christmas - 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[ Christmas - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 15 Jun 2026 13:00:39 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/christmas/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Concurrency, parallelism, and the many threads of Santa Claus ? ]]>
                </title>
                <description>
                    <![CDATA[ Consider the following: Santa brings toys to all the good girls and boys. There are 7,713,468,100 people in the world in 2019, around 26.3% of which are under 15 years old. This works out to 2,028,642,110 children (persons under 15 years of age) in t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/concurrency-parallelism-and-the-many-threads-of-santa-claus/</link>
                <guid isPermaLink="false">66bd8f1effb0fc5947cc911e</guid>
                
                    <category>
                        <![CDATA[ Christmas ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computer Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ concurrency ]]>
                    </category>
                
                    <category>
                        <![CDATA[ multithreading ]]>
                    </category>
                
                    <category>
                        <![CDATA[ parallelism ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Threading ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Victoria Drake ]]>
                </dc:creator>
                <pubDate>Tue, 24 Dec 2019 01:18:11 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/12/cover-3.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Consider the following: Santa brings toys to all the good girls and boys.</p>
<p>There are <a target="_blank" href="https://en.wikipedia.org/wiki/Demographics_of_the_world#Current_population_distribution">7,713,468,100 people</a> in the world in 2019, <a target="_blank" href="https://en.wikipedia.org/wiki/Demographics_of_the_world#Age_structure">around 26.3%</a> of which are under 15 years old. This works out to 2,028,642,110 children (persons under 15 years of age) in the world this year.</p>
<p>Santa doesn’t seem to visit children of every religion, so we’ll  generalize and only include Christians and non-religious folks.  Collectively that makes up <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_religious_populations#Adherent_estimates_in_2019">approximately 44.72%</a> of the population. If we assume that all kids take after their parents, then 907,208,751.6 children would appear to be Santa-eligible.</p>
<p>What percentage of those children are good? It’s impossible to know; however, we can work on a few assumptions. One is that Santa Claus functions more on optimism than economics and would likely have prepared  for the possibility that every child is a good child in any given year. Thus, he would be prepared to give a toy to every child. Let’s assume it’s been a great year and that all 907,208,751.6 children are getting toys.</p>
<p>That’s a lot of presents, and, as we know, they’re all made by Santa’s elves at his North China Pole workshop. Given that there are 365 days in a year and one of them  is Christmas, let’s assume that Santa’s elves collectively have 364 days to create and gift wrap 907,208,752 (rounded up) presents. That works out to 2,492,331.74 presents per day.</p>
<p>Almost two-and-a-half million presents per day is a heavy workload for any workshop. Let’s look at two paradigms that Santa might employ to hit this goal: concurrency, and parallelism.</p>
<h2 id="heading-a-sequential-process">A sequential process</h2>
<p>Suppose that Santa’s workshop is staffed by exactly one, very hard working, very tired elf. The production of one present involves four  steps:</p>
<ol>
<li>Cutting wood</li>
<li>Assembly and gluing</li>
<li>Painting</li>
<li>Gift-wrapping</li>
</ol>
<p>With a single elf, only one step for one present can be happening at any instance in time. If the elf were to produce one present at a time from beginning to end, that process would be executed <em>sequentially</em>. It’s not the most efficient method for producing two-and-a-half million presents per day; for instance, the elf would have to wait around doing nothing while the glue on the present was drying before moving on to the next step.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/sequence.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-concurrency">Concurrency</h2>
<p>In order to be more efficient, the elf works on all presents <em>concurrently</em>.</p>
<p>Instead of completing one present at a time, the elf first cuts all the wood for all the toys, one by one. When everything is cut, the elf assembles and glues the toys together, one after the other. This <a target="_blank" href="https://en.wikipedia.org/wiki/Concurrent_computing">concurrent processing</a> means that the glue from the first toy has time to dry (without needing more attention from the elf) while the remaining toys are glued together. The same goes for painting, one toy at a time, and finally wrapping.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/concurrency.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Since one elf can only do one task at a time, a single elf is using the day as efficiently as possible by concurrently producing presents.</p>
<h2 id="heading-parallelism">Parallelism</h2>
<p>Hopefully, Santa’s workshop has more than just one elf. With more elves, more toys can be built simultaneously over the course of a day. This simultaneous work means that the presents are being produced in <em>parallel</em>. <a target="_blank" href="https://en.wikipedia.org/wiki/Parallel_computing">Parallel processing</a> carried out by multiple elves means more work happens at the same time.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/parallel.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Elves working in parallel can also employ concurrency. One elf can still tackle only one task at a time, so it’s most efficient to have multiple elves concurrently producing presents.</p>
<p>Of course, if Santa’s workshop has, say, two-and-a-half million  elves, each elf would only need to finish a maximum of one present per day. In this case, working sequentially doesn’t detract from the workshop’s efficiency. There would still be 7,668.26 elves left over to fetch coffee and lunch.</p>
<h2 id="heading-santa-claus-and-threading">Santa Claus, and threading</h2>
<p>After all the elves’ hard work is done, it’s up to Santa Claus to deliver the presents – all 907,208,752 of them.</p>
<p>Santa doesn’t need to make a visit to every kid; just to the one household tree. So how many trees does Santa need to visit? Again with broad generalization, we’ll say that the average number of children per household worldwide is <a target="_blank" href="https://en.wikipedia.org/wiki/Demographics_of_the_world#Total_fertility_rate">2.45, based on the year’s predicted fertility rates</a>. That makes 370,289,286.4 houses to visit. Let’s round that up to 370,289,287.</p>
<p>How long does Santa have? The lore says one night, which means one earthly rotation, and thus 24 hours. <a target="_blank" href="https://www.noradsanta.org/">NORAD confirms</a>.</p>
<p>This means Santa must visit 370,289,287 households in 24 hours (86,400 seconds), at a rate of 4,285.75 households per second, never mind the time it takes to put presents under the tree and grab a cookie.</p>
<p>Clearly, Santa doesn’t exist in our dimension. This is especially likely given that, despite being chubby and plump, he fits down a chimney (with a lit fire, while remaining unhurt) carrying a sack of toys containing presents for all the household’s children. We haven’t even considered the fact that his sleigh carries enough toys for every believing boy and girl around the world, and flies.</p>
<p>Does Santa exist outside our rules of physics? How could one entity manage to travel around the world, delivering packages, in under 24 hours at a rate of 4,285.75 households per second, and still have time for milk and cookies and kissing mommy?</p>
<p>One thing is certain: Santa uses the Internet. No other technology has yet enabled packages to travel quite so far and quite so quickly. Even so, attempting to reach upwards of four thousand households per second is no small task, even with the best gigabit internet hookup the North Pole has to offer. How might Santa increase his efficiency?</p>
<p>There’s clearly only one logical conclusion to this mystery: Santa Claus is a multithreaded process.</p>
<h2 id="heading-a-single-thread">A single thread</h2>
<p>Let’s work outward. Think of a <a target="_blank" href="https://en.wikipedia.org/wiki/Thread_(computing)">thread</a> as one particular task, or the most granular sequence of instructions that Santa might execute. One thread might execute the task, <code>put present under tree</code>. A thread is a component of a process, in this case, Santa’s process of delivering presents.</p>
<p>If Santa Claus is <a target="_blank" href="https://en.wikipedia.org/wiki/Thread_(computing)#Single_threading">single-threaded</a>, he, as a process, would only be able to accomplish one task at a time. Since he’s old and a bit forgetful, he probably has a set of instructions for delivering presents, as well as a schedule to abide by. These two things guide Santa’s thread until his process is complete.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/single.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Single-threaded Santa Claus might work something like this:</p>
<ol>
<li>Land sleigh at Timmy’s house</li>
<li>Get Timmy’s present from sleigh</li>
<li>Enter house via chimney</li>
<li>Locate Christmas tree</li>
<li>Place Timmy’s present under Christmas tree</li>
<li>Exit house via chimney</li>
<li>Take off in sleigh</li>
</ol>
<p>Rinse and repeat… another 370,289,286 times.</p>
<h2 id="heading-multithreading">Multithreading</h2>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Thread_(computing)#Multithreading">Multithreaded</a> Santa Claus, by contrast, is the <a target="_blank" href="https://dc.fandom.com/wiki/Jonathan_Osterman_(Watchmen)">Doctor Manhattan</a> of the North Pole. There’s still only one Santa Claus in the world; however, he has the amazing ability to multiply his consciousness and accomplish multiple instruction sets of tasks simultaneously. These additional task workers, or worker threads, are created and controlled by the main process of Santa delivering presents.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/cover-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Each worker thread acts independently to complete its instructions. Since they all belong to Santa’s consciousness, they share Santa’s memory and know everything that Santa knows, including what planet they’re running around on, and where to get the presents from.</p>
<p>With this shared knowledge, each thread is able to execute its set of  instructions in parallel with the other threads. This multithreaded  parallelism makes the one and only Santa Claus as efficient as possible.</p>
<p>If an average present delivery run takes an hour, Santa need only spawn 4,286 worker threads. With each making one delivery trip per hour,  Santa will have completed all 370,289,287 trips by the end of the night.</p>
<p>Of course, in theory, Santa could even spawn 370,289,287 worker threads, each flying to one household to deliver presents for all the  children in it! That would make Santa’s process extremely efficient, and also explain how he manages to consume all those milk-dunked cookies without getting full. ????</p>
<h2 id="heading-an-efficient-and-merry-multithreaded-christmas">An efficient and merry multithreaded Christmas</h2>
<p>Thanks to modern computing, we now finally understand how Santa Claus manages the seemingly-impossible task of delivering toys to good girls and boys the world-over. From my family to yours, I hope you have a wonderful Christmas. Don’t forget to hang up your stockings on the router shelf.</p>
<p>Of course, none of this explains how reindeer manage to fly.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Create your own Santa Tracker with Gatsby and React Leaflet ]]>
                </title>
                <description>
                    <![CDATA[ The Christmas season is a magical time of year. We have Santa flying around spreading cheer and Elf roaming around New York during our yearly rewatch with family and friends. Buddy the Elf waving To get in the spirit, we’re going to spin up a web ap... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/create-your-own-santa-tracker-with-gatsby-and-react-leaflet/</link>
                <guid isPermaLink="false">66b8e32047e3b55b9fb6ee41</guid>
                
                    <category>
                        <![CDATA[ Santa ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Christmas ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Gatsby ]]>
                    </category>
                
                    <category>
                        <![CDATA[ GatsbyJS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ holidays ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ leaflet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mapping ]]>
                    </category>
                
                    <category>
                        <![CDATA[ maps ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ react-leaflet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Colby Fayock ]]>
                </dc:creator>
                <pubDate>Wed, 11 Dec 2019 15:14:13 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/12/santa-tracker.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The Christmas season is a magical time of year. We have Santa flying around spreading cheer and Elf roaming around New York during our yearly rewatch with family and friends.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/elf-waving.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Buddy the Elf waving</em></p>
<p>To get in the spirit, we’re going to spin up a web app that includes a map that tracks Santa on it!</p>
<p><em>Edit 12/23: Updated the app to request directly to Santa's route, just in case the original API doesn't work as originally expected.</em></p>
<h2 id="heading-what-are-we-going-to-build"><strong>What are we going to build?</strong></h2>
<p>We’re going to work through building a mapping app that tracks Santa’s route and his current location.</p>
<p>To achieve this, we’re going to spin up a premade Gatsby starter that will give us a basic foundation for a map, utilize Google’s unofficial API to grab Santa’s route, and overlay his position and route on top of the map with Leaflet.</p>
<h2 id="heading-woah-a-mapping-app"><strong>Woah, a mapping app?</strong></h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/ay-caramba.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Ay Caramba</em></p>
<p>Yup. If you haven’t played with maps before, don’t be discouraged! It's not as bad as you probably think. If you’d rather start with mapping basics, you can <a target="_blank" href="https://www.freecodecamp.org/news/easily-spin-up-a-mapping-app-in-react-with-leaflet/">read more about how mapping works</a> first.</p>
<h2 id="heading-what-do-we-need-before-we-get-started"><strong>What do we need before we get started?</strong></h2>
<p>For this exercise, I’m going to assume you have <a target="_blank" href="https://nodejs.org/en/">node</a> or <a target="_blank" href="https://yarnpkg.com/en/">yarn</a> installed. For each example, I'll use yarn, but use the tool of your choice.</p>
<p>You’ll also want to install <a target="_blank" href="https://www.gatsbyjs.org/docs/gatsby-cli/">Gatsby’s CLI</a> globally which will allow us to use their <a target="_blank" href="https://www.gatsbyjs.org/docs/starters/">Starter tools</a>.</p>
<p>To set up Gatsby’s CLI, run the following command:</p>
<pre><code>yarn <span class="hljs-built_in">global</span> add gatsby-cli
</code></pre><p>After, you should be able to run <code>gatsby -h</code> to see the available commands, which means it’s successfully installed.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/gatsby-help-install-verify.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Running gatsby -h to verify install</em></p>
<p>For more info about the Gatsby CLI, you can <a target="_blank" href="https://www.gatsbyjs.org/docs/gatsby-cli/">check out their documentation</a>.</p>
<h2 id="heading-getting-started-with-our-map-foundation"><strong>Getting started with our map foundation</strong></h2>
<p>Once our command line tools are set up, the first thing we’ll want to do is create a new Gatsby project using <a target="_blank" href="https://github.com/colbyfayock/gatsby-starter-leaflet">a Leaflet starter</a> I put together. It provides us with a basic setup with <a target="_blank" href="https://leafletjs.com/">Leaflet</a> and <a target="_blank" href="https://react-leaflet.js.org/">React Leaflet</a>.</p>
<p>Starting in your project directory, let’s install the project:</p>
<pre><code>gatsby <span class="hljs-keyword">new</span> [directory] https:<span class="hljs-comment">//github.com/colbyfayock/gatsby-starter-leaflet</span>
</code></pre><p>Make sure to replace <code>[directory]</code> with the location you want to set up your project.</p>
<p>Once you run that command, Gatsby will clone that project without any of the git references and install the packages required to start.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/installing-gatsby-starter-leaflet.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Installing Gatsby Starter Leaflet</em></p>
<p>To make sure it works, you can now navigate to that directory, spin up your server, and test it in the browser:</p>
<pre><code>cd [directory]
yarn develop
</code></pre><p>Where you see <code>[directory]</code> above, make sure to use the same path as you did before when setting up the new Gatsby project.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/running-gatsby-starter-leaflet.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Running Gatsby Starter Leaflet</em></p>
<p>If all goes as planned, your server should start and you should now be able to see your basic mapping app in your browser!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/gatsby-starter-leaflet-in-browser.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Gatsby Starter Leaflet in the browser</em></p>
<h2 id="heading-cleaning-things-up"><strong>Cleaning things up</strong></h2>
<p>This starter comes with a quick example of how we can interact with the map. We're not going to need this at all for our purposes so we can go ahead and clean things up.</p>
<p>To start, we’re going to open up our <code>index.js</code> file, the homepage file, and get rid of everything inside of the <code>mapEffect</code> function, which leaves us with:</p>
<pre><code class="lang-js"><span class="hljs-comment">// In src/pages/index.js</span>

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapEffect</span>(<span class="hljs-params">{ leafletElement } = {}</span>) </span>{
  <span class="hljs-comment">// Get rid of everything in here</span>
}
</code></pre>
<p>Now, let’s remove the <code>Marker</code> component nested inside of our <code>Map</code>, so we end up with:</p>
<pre><code class="lang-jsx">&lt;<span class="hljs-built_in">Map</span> {…mapSettings} /&gt;
</code></pre>
<p>Now that we’re no longer using that functionality, we can get rid of the variables and references at the top of the file, so you can go ahead and remove:</p>
<ul>
<li>useRef</li>
<li>promiseToFlyTo</li>
<li>getCurrentLocation</li>
<li>Marker</li>
<li>gatsby_astronaut</li>
<li>ZOOM</li>
<li>timeToZoom</li>
<li>timeToOpenPopupAfterZoom</li>
<li>timeToUpdatePopupAfterZoom</li>
<li>popupContentHello</li>
<li>popupContentGatsby</li>
<li>markerRef</li>
</ul>
<p><a target="_blank" href="https://github.com/colbyfayock/my-santa-tracker/commit/58106bad98ff7491f56d580d01f70f1400120fce">Follow along with the commit.</a></p>
<h2 id="heading-finding-santa"><strong>Finding Santa</strong></h2>
<p>Now that we’re in a good place, let’s get our hands dirty and find Santa. To do this, we’re going to use Google’s unofficial, undocumented API. This means that it’s possible this API won’t be available the day after this get’s published, but let’s be optimistic.</p>
<p>Additionally, at the time of writing, it’s still showing last year’s destinations, so what we’re really going to be visualizing here is Santa’s previous year’s route, though the hope is this would reset on the 24th and we’ll all be merry!</p>
<p>Before we get Santa, let’s first add a line back to our <code>mapEffect</code> function:</p>
<pre><code class="lang-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapEffect</span>(<span class="hljs-params">{ leafletElement } = {}</span>) </span>{
  <span class="hljs-keyword">if</span> ( !leafletElement ) <span class="hljs-keyword">return</span>;
}
</code></pre>
<p>What this will do is prevent the rest of our code from running in the event our map isn't ready yet. The <code>mapEffect</code> function itself, as you can see in the <code>Map</code> component, runs inside of an instance of <code>useEffect</code> passing an argument of a <code>ref</code> to the map, allowing us to run some code after our component renders.</p>
<p>So once we have that line, let’s now fetch Santa’s route inside of our <code>mapEffect</code> function:</p>
<pre><code class="lang-js"><span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapEffect</span>(<span class="hljs-params">{ leafletElement } = {}</span>) </span>{
  <span class="hljs-keyword">if</span> ( !leafletElement ) <span class="hljs-keyword">return</span>;
  <span class="hljs-keyword">let</span> route, routeJson;
  <span class="hljs-keyword">try</span> {
    route = <span class="hljs-keyword">await</span> fetch(<span class="hljs-string">'https://firebasestorage.googleapis.com/v0/b/santa-tracker-firebase.appspot.com/o/route%2Fsanta_en.json?alt=media&amp;2018b'</span>);
    routeJson = <span class="hljs-keyword">await</span> route.json();
  } <span class="hljs-keyword">catch</span>(e) {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Failed to find Santa!: <span class="hljs-subst">${e}</span>`</span>);
  }
  <span class="hljs-built_in">console</span>.log(‘routeJson’, routeJson);
}
</code></pre>
<p>Let’s break this down:</p>
<ul>
<li>We grab Santa’s route via the API endpoint</li>
<li>Once we have his route, we grab the response in a JSON format to make it easier to work with</li>
<li>This is all wrapped in a try/catch so we can safely handle any response errors</li>
<li>Finally, we just <code>log</code> out our response for now</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/santas-route-object.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Santa's route object in the web console</em></p>
<p>Now we have Santa and his route, which means we can see all the destinations in his route. If you dig in the response a little bit, you can see some fun things like how many presents were delivered to each location and the weather at the time!</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-santa-tracker/commit/f42c48fb0f0d70b4d20f1c2a1410bde1a4f27e84">Follow along with the commit.</a></p>
<h2 id="heading-put-a-pin-in-his-location"><strong>Put a pin in his location</strong></h2>
<p>We found Santa! ? Now let’s put him on the map.</p>
<p>For our purposes, we’ll need to find the latitude and longitude of Santa. The problem is, we don’t get this exact value defined anywhere, we just get his destinations.</p>
<p>Since we don’t have his location specified anywhere, we can utilize his last known location where presents were delivered. Add the following after our last snippet inside the <code>mapEffect</code> function:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> { destinations = [] } = routeJson || {};
    <span class="hljs-keyword">const</span> destinationsVisited = destinations.filter(<span class="hljs-function">(<span class="hljs-params">{arrival}</span>) =&gt;</span> arrival &lt; <span class="hljs-built_in">Date</span>.now());
    <span class="hljs-keyword">const</span> destinationsWithPresents = destinationsVisited.filter(<span class="hljs-function">(<span class="hljs-params">{presentsDelivered}</span>) =&gt;</span> presentsDelivered &gt; <span class="hljs-number">0</span>);
<span class="hljs-keyword">const</span> lastKnownDestination = destinationsWithPresents[destinationsWithPresents.length - <span class="hljs-number">1</span>]
</code></pre>
<p>Below our request code, we:</p>
<ul>
<li>Destructure <code>routeJson</code> to grab <code>destinations</code> into a constant, adding a fallback to an empty object</li>
<li>Filter the results to only find the destinations that he's visited, using the arrival time from the route object</li>
<li>Filter the results to find only the locations with presents</li>
<li>And finally grab the last item from the array, which shows his last known location</li>
</ul>
<p>At this point in time, 12/23, we don't actually have any destinations, as Santa is still at the North Pole. At any time, we can test this out to simulate a future date by replaceing <code>Date.now()</code> in <code>destinationsVisited</code> with a future date, such as <code>1577188980000</code> which would be around 7pm Eastern on 12/24. With that change, we can see what Santa's route actually looks like!</p>
<h2 id="heading-handle-a-missing-santa">Handle a missing Santa</h2>
<p>Now that it's close to Christmas, Santa will still be at the North Pole, so let's handle the case where we don't have a location.</p>
<p>Above the line where we set <code>lastKnownDestination</code>, let's add:</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> ( destinationsWithPresents.length === <span class="hljs-number">0</span> ) {
  <span class="hljs-comment">// Create a Leaflet Market instance using Santa's LatLng location</span>
  <span class="hljs-keyword">const</span> center = <span class="hljs-keyword">new</span> L.LatLng( <span class="hljs-number">0</span>, <span class="hljs-number">0</span> );
  <span class="hljs-keyword">const</span> noSanta = L.marker( center, {
    <span class="hljs-attr">icon</span>: L.divIcon({
      <span class="hljs-attr">className</span>: <span class="hljs-string">'icon'</span>,
      <span class="hljs-attr">html</span>: <span class="hljs-string">`&lt;div class="icon-santa"&gt;?&lt;/div&gt;`</span>,
      <span class="hljs-attr">iconSize</span>: <span class="hljs-number">50</span>
    })
  });
  noSanta.addTo( leafletElement );
  noSanta.bindPopup( <span class="hljs-string">`Santa's still at the North Pole!`</span> );
  noSanta.openPopup();
  <span class="hljs-keyword">return</span>;
}
</code></pre>
<p>Okay so what are we doing here?</p>
<ul>
<li>First, we’re checking if we have any destinations with presents, which here we don't</li>
<li>We first create a LatLng of the center of the map</li>
<li>We create a Leaflet marker, using that center, with a custom Icon of Santa</li>
<li>Next we add that Santa marker to the leafletElement, which is our map</li>
<li>To show a message, we first bind a popup with a custom message and open it</li>
<li>Finally we return so the rest of the code doesn’t run, as we don’t have Santa at this point</li>
</ul>
<p>This was a section added after published to handle the API resetting, but you can still follow along with the code I added in context of the rest of the rest of the code.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-santa-tracker/blob/master/src/pages/index.js#L40">Follow along in the code.</a></p>
<h2 id="heading-pinning-santa">Pinning Santa</h2>
<p><em>Edit 12/23: This section was originally written with the previous year's API, but this is still a good example of what you'll expect on the response, so you can follow right along.</em></p>
<p>And as we can see, since we’re looking at last year’s data, Santa is back home at the North Pole.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/santas-last-known-destination-object.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Santa's last known location in the web console</em></p>
<p>With his location, we can pull that apart, set up a Leaflet marker instance, and add our old friend to the map. Add the following after our last snippet inside the <code>mapEffect</code> function:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> santaLocation = <span class="hljs-keyword">new</span> L.LatLng( lastKnownDestination.location.lat, lastKnownDestination.location.lng );

<span class="hljs-keyword">const</span> santaMarker = L.marker( santaLocation, {
  <span class="hljs-attr">icon</span>: L.divIcon({
    <span class="hljs-attr">className</span>: ‘icon’,
    <span class="hljs-attr">html</span>: <span class="hljs-string">`&lt;div class=“icon-santa”&gt;?&lt;/div&gt;`</span>,
    <span class="hljs-attr">iconSize</span>: <span class="hljs-number">50</span>
  })
});

santaMarker.addTo(leafletElement);
</code></pre>
<p>Here we:</p>
<ul>
<li>Create a Leaflet LatLng instance with his location</li>
<li>Create a Marker instance with our newly created LatLng instance</li>
<li>Add our new Marker to the map</li>
</ul>
<p>If we refresh our page, you’ll have to zoom out and pan up a little bit, but we'll see Santa on the map!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/santa-on-the-map.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Santa on the map</em></p>
<p>Before we move on, let’s give Santa a little holiday cheer to make him easier to find. Find your <code>application.scss</code> file and toss these styles in:</p>
<pre><code class="lang-scss"><span class="hljs-comment">// In src/assets/stylesheets/application.scss</span>

<span class="hljs-selector-class">.icon</span> {

  &amp; &gt; <span class="hljs-selector-tag">div</span> {

    <span class="hljs-attribute">display</span>: flex;
    <span class="hljs-attribute">justify-content</span>: center;
    <span class="hljs-attribute">align-items</span>: center;
    <span class="hljs-attribute">overflow</span>: hidden;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">100%</span>;
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">3px</span> <span class="hljs-number">4px</span> rgba(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,.<span class="hljs-number">4</span>);
    <span class="hljs-attribute">border</span>: none;
    <span class="hljs-attribute">transition</span>: all .<span class="hljs-number">2s</span>;

    &amp;<span class="hljs-selector-pseudo">:hover</span> {
      <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">0</span> <span class="hljs-number">4px</span> <span class="hljs-number">8px</span> rgba(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,<span class="hljs-number">0</span>,.<span class="hljs-number">6</span>);
    }

  }

}

<span class="hljs-selector-class">.icon-santa</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">50px</span>;
  <span class="hljs-attribute">font-size</span>: <span class="hljs-number">3em</span>;
  <span class="hljs-attribute">background</span>: white;
}
</code></pre>
<p>This just adds a white circle around him, a little drop shadow, and increases the size a bit to make him a little easier to find on the map.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/santa-styled-on-the-map.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Santa styled on the map</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-santa-tracker/commit/1b636107078fce64068ce661903892c095cb4668">Follow along with the commit.</a></p>
<h2 id="heading-drawing-his-route"><strong>Drawing his route</strong></h2>
<p>The last thing we’re going to do here is draw a path on the map showing his route so we can follow along.</p>
<p>To get started, let’s update our code and add this last bit after our last snippet in the <code>mapEffect</code> function:</p>
<pre><code class="lang-js"><span class="hljs-comment">// Create a set of LatLng coordinates that make up Santa's route</span>

<span class="hljs-keyword">const</span> santasRouteLatLngs = destinationsWithPresents.map(<span class="hljs-function"><span class="hljs-params">destination</span> =&gt;</span> {
  <span class="hljs-keyword">const</span> { location } = destination;
  <span class="hljs-keyword">const</span> { lat, lng } = location;
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> L.LatLng( lat, lng );
});

<span class="hljs-comment">// Utilize Leaflet's Polyline to add the route to the map</span>

<span class="hljs-keyword">const</span> santasRoute = <span class="hljs-keyword">new</span> L.Polyline( santasRouteLatLngs, {
  <span class="hljs-attr">weight</span>: <span class="hljs-number">2</span>,
  <span class="hljs-attr">color</span>: <span class="hljs-string">'green'</span>,
  <span class="hljs-attr">opacity</span>: <span class="hljs-number">1</span>,
  <span class="hljs-attr">fillColor</span>: <span class="hljs-string">'green'</span>,
  <span class="hljs-attr">fillOpacity</span>: <span class="hljs-number">0.5</span>
});

<span class="hljs-comment">// Add Santa to the map!</span>

santasRoute.addTo(leafletElement);
</code></pre>
<p>What we’re doing:</p>
<ul>
<li>Creating an array of Leaflet LatLng instances that make up Santa’s route</li>
<li>Creating a Leaflet Polyline (a multi-point line) using that routes array</li>
<li>Make that Polyline green</li>
<li>Add our Polyline to the map</li>
</ul>
<p>What we get… is a bunch of squiggly lines!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/santas-route-on-the-map.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Santa's route on the map</em></p>
<p>This is expected. This gets technical really fast, but Leaflet by default can only understand 1 “portion” of the map as it wraps around in our browser. What this realistically means, is instead of drawing a line around a globe, the coordinates think it goes from one side of the world to the other as it hits the International Dateline. This is a bit out of scope for this tutorial, but you can check out <a target="_blank" href="https://github.com/briannaAndCo/Leaflet.Antimeridian">Leaflet.Antimeridian</a> to learn more and see if you can implement the solution to it.</p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-santa-tracker/commit/3b0c08f066212ff32c82d3df2a13d1419da8ac41">Follow along with the commit.</a></p>
<h2 id="heading-a-few-quick-style-tweaks"><strong>A few quick style tweaks</strong></h2>
<p>One last thing! And this is completely optional. Let’s make the map a little bit bigger, set the background color to match our oceans, and zoom out a little bit. So let’s make a few changes:</p>
<pre><code class="lang-js"><span class="hljs-comment">// In src/pages/index.js</span>

<span class="hljs-keyword">const</span> DEFAULT_ZOOM = <span class="hljs-number">1</span>;
</code></pre>
<p>We’re setting our default zoom to <code>1</code> instead of <code>2</code> to allow the map to be zoomed out a bit.</p>
<pre><code class="lang-scss"><span class="hljs-comment">// In src/assets/stylesheets/pages/_home.scss</span>

<span class="hljs-selector-class">.page-home</span> {

  <span class="hljs-selector-class">.map</span>,
  <span class="hljs-selector-class">.map-base</span> {
    <span class="hljs-attribute">height</span>: <span class="hljs-number">80vh</span>;
  }

}
</code></pre>
<p>We’re setting our map to a height of <code>80vh</code> instead of <code>50vh</code> to make it take up a little more of our screen.</p>
<pre><code class="lang-scss"><span class="hljs-comment">// In src/assets/stylesheets/components/_map.scss</span>
<span class="hljs-selector-class">.map</span> {

  &amp;,
  <span class="hljs-selector-class">.map-base</span> {
    <span class="hljs-attribute">background</span>: <span class="hljs-number">#acd3de</span>;
  }

}
</code></pre>
<p>We’re setting the background color of our map to <code>#acd3de</code> instead of <code>$blue-grey-50</code> which allows us to match the color of the oceans on our map.</p>
<p>What this achieves is being able to see Santa’s full route and Santa on the first view. Additionally, since the map only covers part of the screen, setting the background color of the map allows us to not have a little bit of a weird cutoff.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/santas-route-zoomed-out.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Santa's route zoomed out</em></p>
<p><a target="_blank" href="https://github.com/colbyfayock/my-santa-tracker/commit/882ea5c0b1b48da86d81494b8b4ad5db7bc1bae6">Follow along with the commit.</a></p>
<h2 id="heading-want-a-challenge"><strong>Want a challenge?</strong></h2>
<p>To take this 1 step further, follow along with both how we added the routes and Santa to the map and try to see if you can add a marker to each destination location to show where all of the stops are. Bonus, add a popup to each one that says how many presents were delivered to that location!</p>
<p>To see the answer with some code organization and how I added the gift markers, check out the final version of the <a target="_blank" href="https://github.com/colbyfayock/santa-tracker">Santa Tracker demo</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/final-santa-tracker-demo.jpg" alt="Image" width="600" height="400" loading="lazy">
<em>Final Santa Tracker demo</em></p>
<p>While you’re there, you can also see how I utilized Leaflet.Antimeridian to fix our map's route.</p>
<h2 id="heading-what-did-we-learn"><strong>What did we learn?</strong></h2>
<p>Building basic apps with a map isn’t nearly as bad as we thought! We learned how to fetch some data from an API, grab the data we need, and draw representations of that data on a map.</p>
<p>Next time you want to add a map widget to your landing page, try Leaflet. Share what you create on <a target="_blank" href="https://twitter.com/colbyfayock">Twitter</a>! Would love to see what you come up with.</p>
<p>I hope you and your family have a fantastic holiday season!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/12/happy-holidays-dunder-mifflin.gif" alt="Image" width="600" height="400" loading="lazy">
<em>Happy Holidays from Dunder Mifflin</em></p>
<h2 id="heading-want-to-learn-more-about-maps">Want to learn more about maps?</h2>
<p>You can check out a few of my other resources to get started:</p>
<ul>
<li><a target="_blank" href="https://www.colbyfayock.com/2020/03/anyone-can-map-inspiration-and-an-introduction-to-the-world-of-mapping">Anyone Can Map! Inspiration and an introduction to the world of mapping</a></li>
<li><a target="_blank" href="https://www.colbyfayock.com/2020/03/how-to-create-a-coronavirus-covid-19-dashboard-map-app-with-gatsby-and-leaflet">How to create a Coronavirus (COVID-19) Dashboard &amp; Map App in React with Gatsby and Leaflet</a></li>
<li><a target="_blank" href="https://www.colbyfayock.com/2020/04/how-to-set-up-a-custom-mapbox-basemap-style-with-react-leaflet-and-leaflet-gatsby-starter/">How to set up a custom Mapbox basemap style with React Leaflet and Leaflet Gatsby Starter</a></li>
<li><a target="_blank" href="https://www.colbyfayock.com/2020/03/how-to-create-a-summer-road-trip-mapping-app-with-gatsby-and-leaflet">How to Create a Summer Road Trip Mapping App with Gatsby and Leaflet</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/easily-spin-up-a-mapping-app-in-react-with-leaflet/">How to build a mapping app in React the easy way with Leaflet</a></li>
</ul>
<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>Want to read some of my other articles? Check out my blog: <a target="_blank" href="https://www.colbyfayock.com/2019/12/create-your-own-santa-tracker-with-gatsby-and-react-leaflet/">https://www.colbyfayock.com/2019/12/create-your-own-santa-tracker-with-gatsby-and-react-leaflet/</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Twas the Night Before Christmas — A Coder’s Dream ]]>
                </title>
                <description>
                    <![CDATA[ By Brad Harr Twas the night before Christmas, in a Developer’s placeI had just finished writing, a brand new code baseWith VSCode humming I then pulled up Git,Then I hit up Github with my final commit; With eyes that were heavy and circles so deep,I ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/twas-the-night-before-christmas-a-coders-dream-b0fc0c6d23b/</link>
                <guid isPermaLink="false">66c363bcef766eb77cd78802</guid>
                
                    <category>
                        <![CDATA[ Christmas ]]>
                    </category>
                
                    <category>
                        <![CDATA[ coding ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Developer ]]>
                    </category>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 22 Dec 2018 05:06:19 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*1ANazAUq9SFVVzx4U7vyZA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Brad Harr</p>
<p>Twas the night before Christmas, in a Developer’s place<br>I had just finished writing, a brand new code base<br>With VSCode humming I then pulled up Git,<br>Then I hit up Github with my final commit;</p>
<p>With eyes that were heavy and circles so deep,<br>I thought to myself, I must have some sleep<br>With Hactoberfest stickers all over the back,<br>I closed my laptop, and grabbed a quick snack;</p>
<p>With my head on my pillow, hoping for sleep,<br>Envisioning my code and rewards I would reap<br>But my eyes would not shut, I had a slight jitter,<br>Too much caffeine so I thought I’d check Twitter;</p>
<p>When what to my wondering eyes should appear,<br>but tweet after tweet, saying my code was inferior,<br>The recursion is wrong and the code base is sloppy,<br>No one will use it, it’s not worth a copy;</p>
<p>I thought to myself, I have to debug,<br>So I jumped out of bed, but slipped on the rug,<br>Out cold on my floor, but not for too long,<br>A few moments later, I woke to a song;</p>
<p>As my eyes regained focus, but what did I see,<br>Good ol’ St. Nick, coming down my chimney,<br>With a rip on his coat, it was in a slight tatter,<br>He looked down at me and asked what was the matter</p>
<p>My code was all wrong, I just don’t have the knack<br>He just laughed a deep laugh as he put down his sack,<br>Don’t be confused, I may look like a Gramps,<br>But over the years, I attended code camps;</p>
<p>He opened my laptop, and first installed Node<br>Who knew that old Santa had learned how to code,<br>His fingers were flying, his typing was quick,<br>How will I ever, repay ol’ St. Nick</p>
<p>When he was finished, my code was brand new,<br>He said I should practice, mistakes were not few,<br>As he left, I was thinking, I know that he’s right,<br>So I pulled up a browser and freeCodeCamp’s site</p>
<p>Though I was tired, and incredibly weary<br>I was soon certified in Front End Libraries,<br>I looked out the window, and saw a faint light<br>Merry Christmas to all, I just coded all night!</p>
<p>by <a target="_blank" href="https://www.freecodecamp.org/news/twas-the-night-before-christmas-a-coders-dream-b0fc0c6d23b/undefined">Brad Harr</a> | Twitter: @bradsharr</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>
