<?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: Jean-Rémy Duboc</title>
    <description>The latest articles on DEV Community by Jean-Rémy Duboc (@jeanremyduboc).</description>
    <link>https://dev.to/jeanremyduboc</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%2F494253%2F6ed9462f-75fe-4dc9-a9c4-07e42474dfd3.jpg</url>
      <title>DEV Community: Jean-Rémy Duboc</title>
      <link>https://dev.to/jeanremyduboc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jeanremyduboc"/>
    <language>en</language>
    <item>
      <title>How to use GTM in a Vue 3 TypeScript Single Page Application Part 2 - Managing Events in the dataLayer</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Mon, 22 May 2023 08:07:10 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/how-to-use-gtm-in-a-vue-3-typescript-single-page-application-part-2-managing-events-in-the-datalayer-3dpn</link>
      <guid>https://dev.to/jeanremyduboc/how-to-use-gtm-in-a-vue-3-typescript-single-page-application-part-2-managing-events-in-the-datalayer-3dpn</guid>
      <description>&lt;p&gt;In &lt;a href="https://codaille.com/gtm-vue-partie-1"&gt;the previous article&lt;/a&gt;, I showed you the basic configuration for GTM in a Vue.JS application.&lt;br&gt;
Now let's see how &lt;a href="https://github.com/gtm-support/vue-gtm"&gt;vue-gtm&lt;/a&gt; updates the datalayer on every page load. After that, we'll add a title for each page, using the Vue.JS router.&lt;br&gt;
We will also see how to register any type of event in the dataLayer with &lt;a href="https://github.com/gtm-support/vue-gtm"&gt;vue-gtm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can refer to the following GitHub project to get all the source code: &lt;a href="https://github.com/JeanRemyDuboc/vue-gtm/tree/Part-2"&gt;https://github.com/JeanRemyDuboc/vue-gtm/tree/Part-2&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  How vue-GTM Triggers a &lt;code&gt;pageview&lt;/code&gt; Event with Vue.js router
&lt;/h1&gt;

&lt;p&gt;When we initialized our application in &lt;code&gt;main.ts&lt;/code&gt;, we added the router to our configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We then configured the application with a new instance of &lt;a href="https://github.com/gtm-support/vue-gtm"&gt;vue-gtm&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;createGtm&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GTM-xxxx&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;vueRouter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once this configuration is added, vue-gtm will update the dataLayer with a new event every time a new page is showed in the browser. But how does it work ?&lt;/p&gt;

&lt;p&gt;Let's look in the &lt;a href="https://github.com/gtm-support/core"&gt;&lt;code&gt;@gtm-support/core&lt;/code&gt;&lt;/a&gt; module, which is the first building block for vue-gtm. In the file &lt;a href="https://github.com/gtm-support/core/blob/main/src/gtm-support.ts"&gt;&lt;code&gt;/src&lt;br&gt;
/gtm-support.ts&lt;/code&gt;&lt;/a&gt;, a function called &lt;code&gt;trackView()&lt;/code&gt; is used to track page views. It has two parameters: page name (&lt;code&gt;screenName&lt;/code&gt;) and path (&lt;code&gt;path&lt;/code&gt;).&lt;br&gt;
Later in the function, we retrieve the &lt;code&gt;dataLayer&lt;/code&gt; object from context &lt;code&gt;window&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dataLayer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DataLayerObject&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we trigger the &lt;code&gt;dataLayer.push&lt;/code&gt; function with the necessary parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;dataLayer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;additionalEventData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trackViewEventProperty&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content-view&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content-view-name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;screenName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;trackView()&lt;/code&gt; is triggered in &lt;code&gt;@gtm-support/vue-gtm/index.js&lt;/code&gt;, in the &lt;code&gt;afterEach()&lt;/code&gt; method of the router. For more information on the &lt;code&gt;afterEach()&lt;/code&gt; function, see &lt;a href="https://router.vuejs.org/api/interfaces/Router.html#Methods-afterEach"&gt;the Vue.js router documentation&lt;/a&gt;.&lt;br&gt;
Note the addition of &lt;code&gt;additionalEventData&lt;/code&gt;, which we can use to add custom properties in each route (documentation here: &lt;a href="https://github.com/gtm-support/vue-gtm#sync-gtm-with-your-router"&gt;https://github.com/gtm-support/vue-gtm#sync-gtm-with-your-router&lt;/a&gt;) .&lt;/p&gt;

&lt;p&gt;It's as if we were writing the following code manually, each time a Vue.js "route" is triggered:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content-view&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="na"&gt;name&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;chemin&lt;/span&gt; &lt;span class="nx"&gt;de&lt;/span&gt; &lt;span class="nx"&gt;la&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="na"&gt;name&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;nom&lt;/span&gt; &lt;span class="nx"&gt;de&lt;/span&gt; &lt;span class="nx"&gt;la&lt;/span&gt; &lt;span class="nx"&gt;route&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the name of the event added to the datalayer is "content-view" by default. It can be changed in our configuration with the &lt;code&gt;trackViewEventProperty&lt;/code&gt; parameter, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nx"&gt;createGtm&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GTM-T3BRZPM&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;vueRouter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;trackViewEventProperty&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;page-load&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this new configuration, when we navigate to the &lt;code&gt;/about&lt;/code&gt; page the triggered code will be equivalent to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;dataLayer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;page-load&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/about&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;view&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;About&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Updating Page Titles with the Vue.JS Router
&lt;/h1&gt;

&lt;p&gt;While navigating in the Vue application, note that the &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; tag does not change when changing pages. This tag is hard coded in &lt;code&gt;index.html&lt;/code&gt;. Without a distinct title, it will be difficult to identify each page on Google Analytics, and for the user it is better to have an explicit title for each page.&lt;br&gt;
So let's modify the content of this tag dynamically, using the router of our application. The goal is to use the "name" value for each route, and put that value in &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; on every page change.&lt;/p&gt;

&lt;p&gt;For this, we use the &lt;a href="https://router.vuejs.org/api/interfaces/Router.html#Methods-beforeEach"&gt;beforeEach&lt;/a&gt; method of the router. As the name suggests, this function fires before each route loads. Once triggered, we can set up a new value for &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; with the &lt;code&gt;name&lt;/code&gt; property of the route that was just loaded.&lt;br&gt;
To do all this, add the code below in &lt;code&gt;main.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;router&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Get the page title from the route's 'name' attribute (if it exists)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;string&lt;/span&gt;&lt;span class="dl"&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
    &lt;span class="c1"&gt;// If the route has a title, set it as the page title of the document/page&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;title&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="nx"&gt;title&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// Continue resolving the route&lt;/span&gt;
  &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aaand voilà! Our page navigation is complete.&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding a Custom Event in the DataLayer
&lt;/h1&gt;

&lt;p&gt;If we add other interactions in the application, we will have to trace them manually.&lt;br&gt;
Let's imagine that our application allows users to register. Once you have registered, you can trigger the &lt;code&gt;login&lt;/code&gt; event, which is one of the &lt;a href="https://support.google.com/analytics/answer/9267735?hl=fr"&gt;recommended events in GA4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For that, nothing could be simpler: let's use &lt;code&gt;useGtm&lt;/code&gt; and its &lt;code&gt;trackEvent&lt;/code&gt; method (similar to &lt;code&gt;trackView&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useGtm&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;@gtm-support/vue-gtm&lt;/span&gt;&lt;span class="dl"&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;gtm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useGtm&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="c1"&gt;//Example of login event trigger...this should be inside a function that runs after the login&lt;/span&gt;
&lt;span class="nx"&gt;gtm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trackEvent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use this trigger on your page views or elsewhere in the app as needed. See my example here: &lt;a href="https://github.com/JeanRemyDuboc/vue-gtm/blob/Part-2/src/views/AboutView.vue"&gt;https://github.com/JeanRemyDuboc/vue-gtm/blob/Part-2/src/views/AboutView.vue&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;And there you go! You can now track all your events with Vue.js and Google Tag Manager. Now, all you have to do is configure Google Analytics in Google Tag Manager, and add a GDPR banner.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Utiliser GTM dans une application à page unique en Vue 3 et TypeScript, Partie 1 - configuration de base</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Thu, 02 Mar 2023 10:44:09 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/utiliser-gtm-dans-une-application-a-page-unique-en-vue-3-et-typescript-partie-1-configuration-de-base-1l61</link>
      <guid>https://dev.to/jeanremyduboc/utiliser-gtm-dans-une-application-a-page-unique-en-vue-3-et-typescript-partie-1-configuration-de-base-1l61</guid>
      <description>&lt;p&gt;Dans cette série, je vais vous montrer comment démarrer rapidement la configuration de analytics avec Google Tag Manager lorsque vous créez une application à page unique (Single Page Application) avec Vue.js. Le but est traquer ce qui se passe dans votre application pour l'améliorer au fil du temps, en utilisant le datalayer et Google Analytics.&lt;/p&gt;

&lt;p&gt;Nous utiliserons TypeScript, mais il devrait être facile d'adapter tout cela en JavaScript.&lt;br&gt;
Quand nous aurons terminé, vous aurez une SPA entièrement intégrée à Google Tag Manager, utilisant le routage pour suivre les "vues de page", une bannière GDPR simple, et des événements personnalisés traqués dans Google Analytics via Google Tag Manager.&lt;br&gt;
Le premier article de la série vous montrera comment créer une application Vue.js simple, puis installer et configurer Google Tag Manager dessus.&lt;/p&gt;
&lt;h1&gt;
  
  
  Créer une application simple avec Vue.js
&lt;/h1&gt;

&lt;p&gt;Pour commencer, vous aurez besoin de votre arsenal JavaScript moderne standard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node&lt;/li&gt;
&lt;li&gt;NPM ou Yarn&lt;/li&gt;
&lt;li&gt;La ligne de commande&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vue dispose d'un excellent utilitaire en ligne de commande que vous pouvez utiliser pour créer rapidement la structure de votre projet. Pour l'installer, commencez par exécuter cette commande:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init vue@latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Cela lancera votre nouvelle application.&lt;/p&gt;

&lt;p&gt;Commencez par saisir le nom de votre projet, puis:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;sélectionnez "yes" pour ajouter TypeScript,&lt;/li&gt;
&lt;li&gt;choisissez si vous voulez le support JSX (pas essentiel pour ce tutoriel, mais vous pourriez en avoir besoin pour votre propre application),&lt;/li&gt;
&lt;li&gt;sélectionnez "yes" pour ajouter Vue Router pour le développement d'applications à page unique (plus d'informations ci-dessous),&lt;/li&gt;
&lt;li&gt;ajoutez Pinia pour la gestion de l'état (facultatif),&lt;/li&gt;
&lt;li&gt;choisissez les autres options comme indiqué ci-dessous:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Project name: … &amp;lt;your-project-name&amp;gt;
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit testing? … No / Yes
✔ Add Cypress for both Unit and End-to-End testing? … No / Yes
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes

Scaffolding project in ./&amp;lt;your-project-name&amp;gt;...
Done.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Si vous voulez créer un autre projet plus tard, exécutez &lt;code&gt;npm create vue@3&lt;/code&gt;, et vous verrez les mêmes options pour votre prochaine application. Pour en savoir plus, consultez &lt;a href="https://vuejs.org/guide/quick-start.html#creating-a-vue-application"&gt;la documentation complète sur le site officiel de Vue&lt;/a&gt;.&lt;br&gt;
Nous sommes maintenant prêts à installer GTM sur notre nouvelle application!&lt;/p&gt;
&lt;h1&gt;
  
  
  Configurer un nouveau conteneur Google Tag Manager
&lt;/h1&gt;

&lt;p&gt;Ensuite, vous aurez besoin d'un conteneur GTM. Suivez les instructions de &lt;a href="https://tagmanager.google.com/"&gt;Google Tag Manager&lt;/a&gt; pour créer un nouveau conteneur, et notez l'ID de votre conteneur pour une utilisation ultérieure. Consultez &lt;a href="https://www.analyticsmania.com/post/google-tag-manager-id/"&gt;cet excellent article de Julius Fedorovicius&lt;/a&gt; pour en savoir plus sur l'ID du conteneur GTM.&lt;/p&gt;
&lt;h1&gt;
  
  
  Installer et configurer Vue GTM
&lt;/h1&gt;

&lt;p&gt;Nous avons maintenant une application SPA très simple. Naviguez avec la ligne de commande dans le dossier racine de votre application, et exécutez &lt;code&gt;npm run dev&lt;/code&gt; pour voir le résultat dans votre navigateur.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kNHuXvn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqcwioxzme8w86fligpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kNHuXvn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqcwioxzme8w86fligpi.png" alt="Image description" width="880" height="484"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;La prochaine étape ? Installer &lt;a href="https://www.npmjs.com/package/@gtm-support/vue-gtm"&gt;Vue Google Tag Manager&lt;/a&gt;: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @gtm-support/vue-gtm&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Ce plugin prend en charge notre configuration GTM, y compris la création d'un datalayer. Il permet également le traquage des vues de pages virtuelles à l'aide du &lt;a href="https://router.vuejs.org"&gt;routeur Vue&lt;/a&gt;. Cela signifie que lorsque les utilisateurs naviguent dans l'application, GTM traite chaque route comme une page distincte et ajoute l'événement approprié au datalayer. Nous pouvons ensuite suivre comment les utilisateurs naviguent entre ces "pages", comme nous le ferions pour suivre des pages web traditionnelles.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;Il faut maintenant configurer notre application pour qu'elle envoie des données vers notre conteneur GTM.&lt;br&gt;
Ouvrez &lt;code&gt;main.ts&lt;/code&gt;, et modifiez le fichier comme ci-dessous:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createGtm } from '@gtm-support/vue-gtm';

import App from './App.vue'
import router from './router'

import './assets/main.css'

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(
  createGtm({
    id: "&amp;lt;Your GTM ID&amp;gt;",
    vueRouter: router
  })
)
app.mount('#app')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Les références à Pinia sont bien sûr facultatives.&lt;/p&gt;

&lt;p&gt;Voici notre configuration la plus basique pour GTM sur une application Vue. Nous connectons notre application à une instance de &lt;code&gt;createGtm&lt;/code&gt; avec deux options simples :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;l'ID de GTM que nous avons mentionné ci-dessus. Cela connecte notre compte GTM à notre application.&lt;/li&gt;
&lt;li&gt;une référence au routeur actuellement utilisé. Cela spécifie que nous utilisons le routeur de notre application pour suivre les vues de pages (&lt;code&gt;vueRoute: router&lt;/code&gt;). Pour voir comment le routeur est configuré, ouvrez &lt;code&gt;router/index.ts&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il existe plusieurs autres options que nous explorerons dans les articles suivants.&lt;/p&gt;

&lt;h1&gt;
  
  
  Déboguer les balises GTM de votre application et le datalayer avec les bons outils
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Confirmer que la balise GTM est installée
&lt;/h2&gt;

&lt;p&gt;Nous devrions maintenant être en mesure de voir tout cela fonctionner sans problème sur votre application en utilisant le navigateur. Rechargez votre application ; si vous avez &lt;a href="https://chrome.google.com/webstore/detail/tag-explorer/obhceflecohdhjjomleeakkogaiclhoo"&gt;Tag Explorer&lt;/a&gt; installé sur Chrome, vous pouvez voir votre balise Google Tag Manager se déclencher sur votre application :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EoJPP5r---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwzvpbotro1rxqy89mic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EoJPP5r---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dwzvpbotro1rxqy89mic.png" alt="Image description" width="605" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Vérifier le datalayer dans console Chrome
&lt;/h2&gt;

&lt;p&gt;Maintenant, ouvrez la console de votre navigateur, tapez &lt;code&gt;datalayer&lt;/code&gt;, et vous verrez que le datalayer est chargé sur votre page :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---KPcEMEQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftpv4i2a7ghm6mfrjzm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---KPcEMEQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ftpv4i2a7ghm6mfrjzm7.png" alt="Image description" width="549" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Vous pouvez voir tous les événements de chargement répertoriés là-bas: le début du processus de suivi de GTM, le chargement du DOM, la première vue de page (sous l'événement &lt;code&gt;content-view&lt;/code&gt;). Si vous accédez à la page &lt;code&gt;/about&lt;/code&gt;, un autre événement &lt;code&gt;content-view&lt;/code&gt; est ajouté au datalayer. Cela nous montre que le router Vue est correctement connecté à notre configuration GTM et envoie des données au datalayer:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hOj_5MBK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zasnrqc7h8w9uqxnxjj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hOj_5MBK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zasnrqc7h8w9uqxnxjj.png" alt="Image description" width="554" height="169"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans le prochain article, nous apprendrons comment tracer d'autres types d'événements sur votre application à page unique (SPA), et comment utiliser GTM pour traquer l'utilisation de votre application dans Google Analytics.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to use GTM in a Vue 3 TypeScript Single Page Application Part 1 - basic configuration</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Thu, 02 Mar 2023 10:41:46 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/how-to-use-gtm-in-a-vue-3-typescript-single-page-application-part-1-basic-configuration-26ne</link>
      <guid>https://dev.to/jeanremyduboc/how-to-use-gtm-in-a-vue-3-typescript-single-page-application-part-1-basic-configuration-26ne</guid>
      <description>&lt;p&gt;In this series I'll show you how to kickstart your analytics configurations with &lt;a href="https://tagmanager.google.com/" rel="noopener noreferrer"&gt;Google Tag Manager&lt;/a&gt; when you create a Single Page Application using &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vue.js&lt;/a&gt;. The goal is to track what's happening in your application to improve it over time, using the datalayer and Google Analytics.&lt;/p&gt;

&lt;p&gt;We'll be using TypeScript, but it should be easy to retrofit most of it to JavaScript.&lt;br&gt;
When we're done, you'll have a SPA fully integrated with Google Tag Manager, using routing to track "page views", a simple GDPR banner, and custom events tracked into Google Analytics via Google Tag Manager.&lt;br&gt;
The first post of the series will show you how to create a simple Vue.js app, then install and configure Google Tag Manager on it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a Vue application
&lt;/h1&gt;

&lt;p&gt;To begin with, you'll need your standard modern JavaScript weaponry:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node&lt;/li&gt;
&lt;li&gt;NPM or Yarn&lt;/li&gt;
&lt;li&gt;The command line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Vue has a great command line utility you can use to scaffold your project with minimal effort. To install this, start by running this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm init vue@latest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It will kick-start your new application. &lt;/p&gt;

&lt;p&gt;Start by entering your project name, then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;select "yes"  to add TypeScript, &lt;/li&gt;
&lt;li&gt;choose if you want JSX support (not essential for this tutorial, but you might want it for your own application), &lt;/li&gt;
&lt;li&gt;select "yes" to add Vue Router for Single Page Application development (more about that below), &lt;/li&gt;
&lt;li&gt;add &lt;a href="https://pinia.vuejs.org/" rel="noopener noreferrer"&gt;Pinia&lt;/a&gt; for state management (optional), &lt;/li&gt;
&lt;li&gt;choose the other options as shown below:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

✔ Project name: … &amp;lt;your-project-name&amp;gt;
✔ Add TypeScript? … No / Yes
✔ Add JSX Support? … No / Yes
✔ Add Vue Router for Single Page Application development? … No / Yes
✔ Add Pinia for state management? … No / Yes
✔ Add Vitest for Unit testing? … No / Yes
✔ Add Cypress for both Unit and End-to-End testing? … No / Yes
✔ Add ESLint for code quality? … No / Yes
✔ Add Prettier for code formatting? … No / Yes

Scaffolding project in ./&amp;lt;your-project-name&amp;gt;...
Done.


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

&lt;/div&gt;

&lt;p&gt;If you want to create another project later, run &lt;code&gt;npm create vue@3&lt;/code&gt;, and you'll see the same options for your next app. &lt;a href="https://vuejs.org/guide/quick-start.html#creating-a-vue-application" rel="noopener noreferrer"&gt;Check the full documentation&lt;/a&gt; on Vue's official site.&lt;br&gt;
We're now ready to set up GTM on our newly created app!&lt;/p&gt;

&lt;h1&gt;
  
  
  Set up a new Google Tag Manager Container
&lt;/h1&gt;

&lt;p&gt;Next, you'll need a GTM container. Follow the instructions in &lt;a href="https://tagmanager.google.com/" rel="noopener noreferrer"&gt;Google Tag Manager&lt;/a&gt; to create a new container, and keep track of your container ID for later use. Check out &lt;a href="https://www.analyticsmania.com/post/google-tag-manager-id/" rel="noopener noreferrer"&gt;this excellent article from Julius Fedorovicius&lt;/a&gt; to learn more about the GTM container ID.&lt;/p&gt;

&lt;h1&gt;
  
  
  Install and configure Vue GTM
&lt;/h1&gt;

&lt;p&gt;We now have a very simple SPA to work with. Navigate into your app's root folder and run &lt;code&gt;npm run dev&lt;/code&gt; to see it in your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6d3lemwhi8w6bzljtctx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6d3lemwhi8w6bzljtctx.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next step is to install &lt;a href="https://www.npmjs.com/package/@gtm-support/vue-gtm" rel="noopener noreferrer"&gt;Vue Google Tag Manager&lt;/a&gt;: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install @gtm-support/vue-gtm&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This plugin takes care of our GTM configuration, including the creation of a datalayer. It also enables the tracking of virtual page views using &lt;a href="https://router.vuejs.org/" rel="noopener noreferrer"&gt;the Vue router&lt;/a&gt;. This means that when users navigate in the application, GTM treats each route as a separate page, and adds the appropriate event to the datalayer. We can then track how users navigate between these routes, just like we would track regular web pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuration
&lt;/h2&gt;

&lt;p&gt;Now we need to configure our application so that it sends data to our GTM container. &lt;br&gt;
Open &lt;code&gt;main.ts&lt;/code&gt;, and edit it to look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createGtm } from '@gtm-support/vue-gtm';

import App from './App.vue'
import router from './router'

import './assets/main.css'

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(
  createGtm({
    id: "&amp;lt;Your GTM ID&amp;gt;",
    vueRouter: router
  })
)
app.mount('#app')


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

&lt;/div&gt;

&lt;p&gt;References to Pinia are, of course, optional.&lt;/p&gt;

&lt;p&gt;This is our most basic configuration for GTM on a Vue application. We hook our app to an instance of &lt;code&gt;createGtm&lt;/code&gt; with two simple options: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the GTM ID we mentioned above. This connects our GTM account to our app.&lt;/li&gt;
&lt;li&gt;a reference to the router currently in use. This specifies that we're using our app's router to track page views (&lt;code&gt;vueRoute: router&lt;/code&gt;). To see how the router is configured, open &lt;code&gt;router/index.ts&lt;/code&gt;. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are several other options; we'll explore them in later posts.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using debugging tools to debug your app's GTM tagging and the datalayer
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Confirm that the GTM tag is installed
&lt;/h2&gt;

&lt;p&gt;We should now be able to see everything come together on your app from your browser. &lt;br&gt;
Reload your application; if you have &lt;a href="https://chrome.google.com/webstore/detail/tag-explorer/obhceflecohdhjjomleeakkogaiclhoo" rel="noopener noreferrer"&gt;Tag Explorer&lt;/a&gt; installed on Chrome, you can see your Google Tag Manager tag firing on your application:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpf1vg6buoo37i2nod6ix.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpf1vg6buoo37i2nod6ix.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Check the data layer in the console
&lt;/h2&gt;

&lt;p&gt;Now open your browser console, type &lt;code&gt;datalayer&lt;/code&gt; , and you'll see that the data layer is loaded on your page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg598dedcd0fsd0qugkjr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg598dedcd0fsd0qugkjr.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see all loading events listed in there: the start of the GTM tracking process, the DOM load, the first page view (under event &lt;code&gt;content-view&lt;/code&gt;). If you navigate to the &lt;code&gt;/about&lt;/code&gt; page, another &lt;code&gt;content-view&lt;/code&gt; event is added to the data layer. This shows us that the Vue router is connected properly with our GTM setup, and is sending data to the data layer:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsayvtzvzw3910i2z5c06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsayvtzvzw3910i2z5c06.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next post, we'll learn how to track other type of events on your Single Page Application, and how to use GTM to track your app's usage in Google Analytics.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>analytics</category>
      <category>vue</category>
    </item>
    <item>
      <title>Comment lire la non-fiction comme un génie 📚️</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Thu, 05 Jan 2023 14:45:34 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/comment-lire-la-non-fiction-comme-un-genie-1l8b</link>
      <guid>https://dev.to/jeanremyduboc/comment-lire-la-non-fiction-comme-un-genie-1l8b</guid>
      <description>&lt;p&gt;Pour devenir polymathe, vous devrez étudier dans plusieurs domaines. En pratique, cela signifie que vous allez lire énormément.&lt;br&gt;
Commençons par les livres; les livres sont une source précieuse de connaissances depuis des siècles, et je ne crois pas que cela va changer de sitôt. La majorté des informations disponibles sont encore publiées dans des livres, et beaucoup d'entre elles ne sont pas encore disponibles en ligne.&lt;br&gt;
Ensuite, il y a les ressources Web : blogs, magazines en ligne, newsletters, tutoriels, etc. Pas de limite quand il s'agit d'apprendre en ligne, mais peu de gens profitent vraiment de cette opportunité.&lt;br&gt;
Voici comment vous pouvez mieux lire et tirer le meilleur parti de votre lecture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F202zmfmncf9bcsnzi9jv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F202zmfmncf9bcsnzi9jv.png" alt="Image description" width="800" height="798"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Faire de la lecture une habitude
&lt;/h2&gt;

&lt;p&gt;Si vous voulez apprendre beaucoup, la lecture ne devrait pas être quelque chose que vous faisiez à l'école. Cela devrait devenir une habitude, une partie intégrante de votre personnalité.&lt;br&gt;
&lt;strong&gt;Oubliez le speed reading. Oubliez les défis de lecture annuels. Vous avez lu un livre chaque semaine l'année dernière? Tout le monde s'en moque. Contentez-vous de lire.&lt;/strong&gt; Apprenez. Aussi souvent que vous le pouvez.&lt;/p&gt;

&lt;p&gt;Voici un système simple qui vous fera lire plus chaque jour :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prenez toujours un livre ou un article partout avec vous : sur votre téléphone ou votre tablette (utilisez l'application Kindle pour les livres et &lt;a href="https://getpocket.com" rel="noopener noreferrer"&gt;Pocket&lt;/a&gt; pour les articles), sous forme papier, etc.&lt;/li&gt;
&lt;li&gt;Lisez dès que vous avez quelques minutes de libre. Notex vos progrès. Vous serez surpris par la quantité d'informations que vous parvenez à absorber au fil du temps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;C'est tout. N'oubliez pas: &lt;a href="https://jamesclear.com/goals-systems" rel="noopener noreferrer"&gt;process over goals wins every time(en)&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Le seul moyen de réellement gagner est de s'améliorer chaque jour. [...] Si vous voulez de meilleurs résultats, oubliez les objectifs. Concentrez-vous plutôt sur votre système.&lt;br&gt;
James Clear.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Comprenez le contexte de ce que vous lisez. Ajustez votre pensée en conséquence.
&lt;/h2&gt;

&lt;p&gt;Ne lisez pas un article scientifique complexe de la même manière que vous parcourez les nouvelles. Cela peut sembler évident, mais cela transformera la façon dont vous lisez tout.&lt;br&gt;
Avant de lire quoi que ce soit, assurez-vous de vérifier quelques éléments clés:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Qui est l'auteur ?
Vous aurez au moins une idée des deux B : Bio et Biais. Qui sont-ils ? Pourquoi écrivent-ils cela et quel est leur parcours ? Comment leur expérience personnelle affecte-t-elle leur écriture ? Comment votre biais personnel envers eux affecte-t-il votre lecture ? Cela semble s'appliquer uniquement aux articles personnels et aux domaines de l'humanité, mais même les sciences "dures" ont leurs biais. Être biaisé, c'est être humain.&lt;/li&gt;
&lt;li&gt;Qui est l'éditeur ?
L'éditeur est le facilitateur de l'auteur, sa plateforme. Ils apportent leurs propres compétences et biais au mélange. Un bon éditeur est crucial pour la qualité et le succès d'un livre. Apprenez à identifier les meilleurs éditeurs et sites web ou newsletters dans les domaines que vous apprenez.
N'importe qui peut publier n'importe quoi en ligne, ce qui signifie que la qualité est très variable. Cela rend les éditeurs en ligne encore plus pertinents. Avant de lire une resource en ligne, posez-vous quelques questions. Votre article est-il publié dans sur un site bien connue, comme un journal établi ou une newsletter de technologie respectée ? Ou est-il simplement publié dans un blog sous le nom de l'auteur ?
Gardez à l'esprit que, si parce qu'un article est publié sur un blog personnel, cela ne le rend pas forcément mauvais (j'espère que cet article en est la preuve). Cela signifie simplement qu'aucun tiers n'a revu l'article avant publication et que les biais de l'auteur ont pu être manqués.&lt;/li&gt;
&lt;li&gt;Quelle est la date de publication ?
Les livres plus anciens sont le produit de leur temps, et il est faut les comprendre dans leur contexte, et non de les juger en fonction des normes actuelles. Vous devez également tenir compte de l'information obsolète et mettre à jour vos connaissances en conséquence.
Les ressources en ligne sont particulièrement sujettes à l'obsolescence, en particulier en ce qui concerne la technologie. Assurez-vous que les tutoriels que vous utilisez fonctionnent avec la dernière version du framework que vous utilisez.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ce processus peut sembler assez fastidieux, mais en pratique, il ne prend que quelques instants et devient plus rapide avec la pratique. Et n'oubliez pas, pas de lecture rapide ici. De plus, les techniques que je décris dans la prochaine section vous montreront comment vous pouvez absorber un texte beaucoup plus rapidement et en profondeur.&lt;/p&gt;

&lt;h2&gt;
  
  
  Utilisez un maximum les table des matières, glossaires et index
&lt;/h2&gt;

&lt;p&gt;Voici &lt;em&gt;la&lt;/em&gt; clé d'une' lecture efficace : devenez un lecteur actif et exigeant, ne vous contentez pas de passivement absorber le texte de la première à la dernière page.&lt;br&gt;
Commencez toujours par la table des matières. Utilisez-la pour comprendre la structure du texte, et choisissez les parties qui vous intéressent le plus. Posez des questions, prenez des notes et vérifiez comment le livre y répond. Avant de lire un article, parcourez-le rapidement, utilisez les titres et les paragraphes pour comprendre sa structure.&lt;br&gt;
Ensuite, examinez l'index pour trouver les mots-clés que vous connaissez déjà ou cherchez des mots que vous n'avez jamais rencontrés, et laissez libre cours à votre curiosité.&lt;br&gt;
Voici une chose que la plupart des gens, étonnamment, n'apprennent jamais à l'école : vous n'avez pas à lire quoi que ce soit dans un ordre spécifique. C'est &lt;strong&gt;votre&lt;/strong&gt; livre, &lt;strong&gt;votre&lt;/strong&gt; article, &lt;strong&gt;vous&lt;/strong&gt; pouvez choisir et sélectionner les passages que vous voulez lire, dans l'ordre que vous voulez. Cela s'appelle la lecture active, une compétence criminellement négligée. Faites-en une habitude et vous aurez un pouvoir surhumain.&lt;br&gt;
Avec le temps, cela vous permettra de parcourir rapidement les livres, en sautant directement aux parties qui sont pertinentes pour votre recherche actuelle et en laissant de côté le reste. Vous apprendrez où trouver l'information dont vous avez besoin plus tard si nécessaire.&lt;/p&gt;

&lt;p&gt;Voici comment "consommer" de l'information. Dans les prochaines sections, nous verrons comment la "digérer", c'est-à-dire la mémoriser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhxvx5kqyxqfdpyve3jm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbhxvx5kqyxqfdpyve3jm.png" alt="Image description" width="800" height="798"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Apprenez les trois secrets pour mémoriser ce que vous lisez.
&lt;/h2&gt;

&lt;p&gt;Beaucoup ont du mal à se souvenir de ce qu'ils lisent, c'est pourquoi ils abandonnent la lecture tout court après l'école. Et qui peut leur en vouloir ? Cela semble être une perte de temps. La bonne nouvelle, c'est que, avec la lecture active, décrite ci-dessus, vous mémorisez déjà beaucoup plus.&lt;/p&gt;

&lt;p&gt;C'est le premier secret pour mémoriser ce que vous lisez : &lt;strong&gt;devenez un lecteur exigeant : continuez à poser des questions pendant que vous lisez et cherchez les réponses&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Le second secret fait également partie du processus de lecture active : &lt;strong&gt;reliez ce que vous lisez à ce que vous savez déjà&lt;/strong&gt;. Le cerveau fonctionne en faisant des liens : c'est pourquoi la mémorisation par cœur ne marche pas bien : s'il n'y a rien à "accrocher" sur une liste ennuyeuse qui n'a aucun contexte pour vous, le cerveau oublie très vite. C'est aussi pourquoi les connaissances se cumulent si bien : si vous connaissez un peu sur plusieurs sujets différents, vous avez plus de liens à établir et vous pouvez "aller en profondeur" sur de nombreux sujets très rapidement. C'est un super-pouvoir de polymathe.&lt;/p&gt;

&lt;p&gt;Le troisième secret est un peu plus technique, mais en vaut largement la peine : &lt;strong&gt;utilisez la répétition espacée pour raviver vos connaissances&lt;/strong&gt;. Je n'expliquerais pas en détail la répétition espacée (c'est hors-sujet pour cet article), mais en un mot, il s'agit d'utiliser quotidiennement des flashcards ou cartes mémoire informatisées. Chaque fiche est révisée à des intervalles de plus en plus longs, grâce à un algorithme spécialisé.&lt;br&gt;
Je vous recommande d'utiliser &lt;a href="https://apps.ankiweb.net/" rel="noopener noreferrer"&gt;Anki&lt;/a&gt; pour commencer : il est gratuit et possède toutes les fonctionnalités dont vous pourriez avoir besoin. Lisez &lt;a href="https://leananki.com/how-to-use-anki-tutorial/" rel="noopener noreferrer"&gt;cet article pour apprendre les bases d'Anki(en)&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  La règle d'or de la lecture et de l'apprentissage
&lt;/h2&gt;

&lt;p&gt;Voici une autre chose que nous n'apprenons jamais à l'école : dans le monde réel, &lt;strong&gt;vous n'êtes pas obligé de continuer à lire quelque chose qui n'a pas de valeur pour vous&lt;/strong&gt;. Vous êtes également autorisé à lire ce que vous voulez. &lt;strong&gt;Il n'y a pas de devoirs ou de "lecture obligatoire" dans la vie, juste le &lt;a href="https://supermemo.guru/wiki/Pleasure_of_learning" rel="noopener noreferrer"&gt;plaisir d'apprendre&lt;/a&gt;.&lt;/strong&gt;&lt;br&gt;
Ne laissez jamais personne vous faire honte pour ce que vous lisez ou ne lisez pas, ou pour la façon dont vous le lisez. Vous êtes libre.&lt;br&gt;
Encore une fois, il suffit de lire et d'apprendre. Aussi vite ou aussi lentement que vous le souhaitez. Et si le livre, l'article de blog ou le magazine ne vous convient pas, remettez-le simplement en rayon. Ce sera peut-être pour plus tard. Peut-être jamais. Vous êtes libre.&lt;/p&gt;

&lt;p&gt;Ce qui compte, toujours, c'est de continuer. N'arrêtez pas d'apprendre, jamais.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Ne laissez pas l'école interférer avec votre éducation.&lt;br&gt;
Mark Twain&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Que lisez-vous en ce moment ? &lt;/p&gt;

&lt;h3&gt;
  
  
  Lectures recommandées (en anglais)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.co.uk/Lifetime-Learners-Guide-Reading-Learning-ebook/dp/B073VBZCS8/" rel="noopener noreferrer"&gt;The Lifetime Learner's Guide to Reading and Learning&lt;/a&gt; par Gary Hoover
Le passionné de livres &lt;a href="https://hooversworld.com/gary-hoover/" rel="noopener noreferrer"&gt;Gary Hoover&lt;/a&gt; vit dans un immeuble de 33 pièces, dont 32 contiennent sa bibliothèque personnelle de 57 000 livres. Peu de gens ont « consommé » ou appris et retenu autant de livres. Dans ce livre, Gary expose sa méthode pour capturer les idées importantes contenues dans les livres en 30 minutes (ou moins) sans lecture rapide.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.co.uk/How-Read-Book-Intelligent-Touchstone-ebook/dp/B004Z0TU0W" rel="noopener noreferrer"&gt;How to Read a Book&lt;/a&gt; par Charles Van Doren et Mortimer Adler
Publié à l'origine en 1940, ce livre est un phénomène rare, un classique toujours actuel, qui présente et explique les différents niveaux de lecture et comment les atteindre - de la lecture élémentaire à la lecture rapide en passant par l'écrémage systématique et la lecture d'inspection. Les lecteurs apprendront quand et comment "juger un livre par sa couverture", et aussi comment le radiographier, lire de manière critique et extraire le message de l'auteur du texte.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>How to read non-fiction like a genius 📚️</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Tue, 03 Jan 2023 12:26:02 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/how-to-read-non-fiction-like-a-genius-39ap</link>
      <guid>https://dev.to/jeanremyduboc/how-to-read-non-fiction-like-a-genius-39ap</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZW2jsJW_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf1uqgbv5p20hldwkz9r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZW2jsJW_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf1uqgbv5p20hldwkz9r.png" alt="Image description" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to become a polymath, you have to study across multiple fields of knowledge. In practice, this means you're going to read a lot. &lt;br&gt;
Start with books; books have been a valuable source of knowledge for centuries, and I don't believe that's going to change anytime soon. Most of the information available is still published in books, and a lot of it isn't available online yet.&lt;br&gt;
Then there's web-based resources: blogs, online magazines, newsletters, tutorials, etc. The sky is the limit when it comes to learning online, but few people truly take advantage of it.&lt;br&gt;
Here's how you can read better, and get the most out of your reading.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make learning and reading a habit
&lt;/h2&gt;

&lt;p&gt;If you want to learn a lot, reading shouldn't be something you used to do in school. It should become a habit, an integral part of your personality.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Forget speed-reading. Forget yearly reading challenges. Nobody cares that you've read a book every week last year. Just read&lt;/strong&gt;. Learn. As often as you can.&lt;br&gt;
Here's a simple system that will get you reading more every day:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a book or an article with you everywhere you go: on your phone or tablet (use the Kindle app for books and &lt;a href="https://getpocket.com"&gt;Pocket&lt;/a&gt; for articles), in paper form, etc.&lt;/li&gt;
&lt;li&gt;Read whenever you have a few spare minutes. Keep track of your progress. You'll be amazed by the amount of information you manage to absorb over time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it. That's all you need. Remember: &lt;a href="https://jamesclear.com/goals-systems"&gt;process over goals wins every time&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The only way to actually win is to get better each day. [...] If you want better results, then forget about setting goals. Focus on your system instead.&lt;br&gt;
James Clear.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Understand the context of what you're reading, adjust accordingly
&lt;/h2&gt;

&lt;p&gt;Don't read a complex scientific paper the same way you browse the news. This seems obvious, but it will transform the way you read anything.&lt;br&gt;
Before you read anything, make sure you check a few things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Who's the writer? 
You'll need to have at least some idea of the &lt;strong&gt;two Bs: Bio and Bias&lt;/strong&gt;. Who are they? Why are they writing this, and what's their background? How does their personal experience affect their writing? How does your personal bias with them affect your reading? It seems like this should only apply to personal articles and the humanities, but even the hard sciences have their bias. To be biased is to be human.&lt;/li&gt;
&lt;li&gt;Who's the publisher? 
The publisher is the author's facilitator, their platform. They bring their own skills and biases to the mix. A good publisher is crucial to the quality and success of a book. Learn to identify the top publishers and websites or newsletters in the fields you're learning about.
Anyone can publish anything online, which means quality varies greatly. This makes online publishers all the more relevant. Before reading an online resource, ask yourself a few questions. Is your article published in a well-known online resource, such as an established newspaper or a respected tech newsletter? Or is it just published in a blog under the writer's own name? 
Keep in mind, just because a post is published on a personal blog doesn't make it bad (I hope this very article demonstrates this). It just means that no third party reviewed the article before publication, and that the author's biases and blind spots may have been missed.&lt;/li&gt;
&lt;li&gt;When was this published?
Older books are a product of their time, and you need to understand them in their proper context, not judge them based on today's standards. You also need to account for out-of-date information, and update your knowledge accordingly.
Online resources are especially prone to obsolescence, especially when it comes to tech. Make sure that the tutorials you use work with the latest version of whatever framework you're using.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This process may seem quite tedious, but in practice it only takes a few moments, and gets faster with practice. And remember, we don't care about speed-reading here. Besides, the techniques I describe in the next section will show you how you can absorb a text much faster, and much deeper.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use and abuse table of contents, glossaries and indexes
&lt;/h2&gt;

&lt;p&gt;This is &lt;em&gt;the&lt;/em&gt; key to effective reading: become an active and demanding reader, don't just passively absorb the text from start to finish.&lt;br&gt;
Start with the table of contents, always. Use it to understand the structure of the book, and pick the parts that interest you most. Ask questions, make a note, and go check how the book answers them. Before you read an article, skim it, use the headlines and paragraphs to understand it's structure.&lt;br&gt;
Then, look at the index to find connections to keywords you already know about, or look for words you never encountered and indulge your curiosity.&lt;br&gt;
Here is something most people, astonishingly,  never learn at school: &lt;strong&gt;you do not have to read anything in a specific order&lt;/strong&gt;. This is &lt;strong&gt;your&lt;/strong&gt; book, &lt;strong&gt;your&lt;/strong&gt; article, &lt;strong&gt;you&lt;/strong&gt; can pick and choose which bits you want to read, in whatever order you want. This is called &lt;strong&gt;active reading&lt;/strong&gt;, a criminally neglected skill. Make that a habit and you got yourself a superpower.&lt;br&gt;
Over time, doing this will enable you to go through books quickly, jumping straight to0 parts that are relevant to your current research, leaving out the rest. Learning were to find the information you need later if needed.&lt;/p&gt;

&lt;p&gt;This is how to "consume" information. In the next sections we'll have a look at how to "digest" it, aka memorisation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn the three secrets to memorising what you read
&lt;/h2&gt;

&lt;p&gt;Most people struggle to remember what they read, which is why they give up on reading altogether after school. And who can blame them? It seems like a waste of time. The good news is, with &lt;strong&gt;active reading&lt;/strong&gt;, described above, you're already memorising a lot more. &lt;/p&gt;

&lt;p&gt;That's the first secret to memorising what you read: &lt;strong&gt;become a demanding reader: keep asking questions as you read, and look for answers&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The second secret is also part of the active reading process: &lt;strong&gt;connect what you read to what you already know&lt;/strong&gt;. The brain works by making connections: that's why rote memorisation doesn't work well: if there's nothing to "peg" onto a bland list that has no context for you, the brain just forgets. That's also why knowledge compounds so well: if you know a little about a lot of different subjects, you have more connections to make and you can "go deep" on many topics very quickly. That's a polymath superpower.&lt;/p&gt;

&lt;p&gt;The third secret is a bit more involved, but worth the effort: &lt;strong&gt;use spaced repetition to keep your knowledge alive&lt;/strong&gt;. Explaining spaced repetition in detail is out of the scope of this post, but in a nutshell it's using computerised flash cards every day. Each card is revised at increasingly long intervals, based on a specialised algorithm. &lt;br&gt;
I recommend using &lt;a href="https://apps.ankiweb.net/"&gt;Anki&lt;/a&gt; to get started: it's free and has all the features you're likely to need. Read &lt;a href="https://leananki.com/how-to-use-anki-tutorial/"&gt;this post to learn the basics of  Anki&lt;/a&gt;.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  The golden rule of reading and learning
&lt;/h2&gt;

&lt;p&gt;Here's something else we never learn about reading in school: in the real world, &lt;strong&gt;you do not have to keep reading anything that's not valuable to you&lt;/strong&gt;. You're also allowed to read whatever the hell you want. &lt;strong&gt;There are no assignments or "required reading" in life, just the &lt;a href="https://supermemo.guru/wiki/Pleasure_of_learning"&gt;pleasure of learning&lt;/a&gt;.&lt;/strong&gt; &lt;br&gt;
Never, ever let anyone shame you for what you're reading or not reading, or how you're reading it. You're free.&lt;br&gt;
Once again, just read and learn. As fast or as slowly as you please. And if the book, the blog post or the magazine isn't for you, just put it back on the shelf. Maybe later. Maybe never. You're free.&lt;/p&gt;

&lt;p&gt;What matters, always, is that you just keep going. Don't stop learning, ever.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don't let schooling interfere with your education.&lt;br&gt;
Mark Twain&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What are you reading at the moment? Let me know !&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommended reading
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.co.uk/Lifetime-Learners-Guide-Reading-Learning-ebook/dp/B073VBZCS8/"&gt;The Lifetime Learner's Guide to Reading and Learning&lt;/a&gt; by Gary Hoover
Book lover &lt;a href="https://hooversworld.com/gary-hoover/"&gt;Gary Hoover&lt;/a&gt; lives in a 33-room building, of which 32 contain his 57,000-book personal library. Few people have “consumed” or learned from and remembered as many books. In The Lifetime Learner’s Guide to Reading and Learning, Gary lays out his method for capturing important ideas contained in books in 30 minutes (or less) without speed-reading. &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.amazon.co.uk/How-Read-Book-Intelligent-Touchstone-ebook/dp/B004Z0TU0W"&gt;How to Read a Book&lt;/a&gt; by Charles Van Doren and Mortimer Adler
Originally published in 1940, this book is a rare phenomenon, a living classic that introduces and elucidates the various levels of reading and how to achieve them—from elementary reading, through systematic skimming and inspectional reading, to speed reading. Readers will learn when and how to “judge a book by its cover,” and also how to X-ray it, read critically, and extract the author’s message from the text.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Analytics Integration with TypeScript, React and Styled Components - Part 1: Setting up the Tools</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Mon, 05 Dec 2022 08:13:41 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/analytics-integration-with-typescript-react-and-styled-components-part-1-setting-up-the-tools-5d84</link>
      <guid>https://dev.to/jeanremyduboc/analytics-integration-with-typescript-react-and-styled-components-part-1-setting-up-the-tools-5d84</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgej9hpsbiplwl9p0g5as.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgej9hpsbiplwl9p0g5as.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this series of tutorials, we are going to create a simple web applications using 3 technologies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; as our language of choice&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; will be our framework to develop our app&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://styled-components.com/" rel="noopener noreferrer"&gt;Styled Components&lt;/a&gt; to manage styling with CSS-in-JS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will learn how to track user actions in the app using Google Analytics 4. We'll also use the &lt;a href="https://github.com/GoogleChrome/web-vitals" rel="noopener noreferrer"&gt;Web Vitals&lt;/a&gt; library to measure and send the app's performance data to GA4.&lt;/p&gt;

&lt;p&gt;The aim is to dive into the basics of modern front-end workflows, and how they integrate with Google Analytics.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;In this first part of the tutorial, we'll learn how to set up the basic tools for this application.&lt;/p&gt;

&lt;p&gt;To do this tutorial you'll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;your command line tool of choice&lt;/li&gt;
&lt;li&gt;node, npm and npx installed on your computer. At the time of writing I'm using node 16.11.0, npx 8.0.0 and nvm 0.39.1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm also using VSCode and the Git bash command line, but you can use whatever command line and code editor you prefer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Creating a new React app with TypeScript
&lt;/h1&gt;

&lt;p&gt;The first step is to use &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;&lt;code&gt;create-react-app&lt;/code&gt;&lt;/a&gt; to generate a simple application as a starting point. &lt;code&gt;create-react-app&lt;/code&gt; spares us the work of configuring several build tools, and makes our life easier. Among many others, it will automatically set up &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt; and &lt;a href="https://babeljs.io/" rel="noopener noreferrer"&gt;Babel&lt;/a&gt;(configured to compile TypeScript), as well as &lt;a href="https://github.com/GoogleChrome/web-vitals" rel="noopener noreferrer"&gt;web-vitals&lt;/a&gt;.&lt;br&gt;
All of this in a single command!&lt;/p&gt;

&lt;p&gt;Go to the folder where you want you application to live, then type the below in your command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="nx"&gt;typescript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it ! Your application now lives in a new folder called &lt;code&gt;/my-react-ts-app&lt;/code&gt;. You'll notice a few configuration files already in place such as &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;tsconfig.json&lt;/code&gt;. You also have the source files for the application itself already in place in the &lt;code&gt;/src&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;Start your application by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Install Styled Components for TypeScript
&lt;/h1&gt;

&lt;p&gt;The next step is to add Styled Components to our apps. Start by installing the styled-components library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we install the styled-components types for TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @types/styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read more about these types at: &lt;a href="https://github.com/DefinitelyTyped/DefinitelyTyped" rel="noopener noreferrer"&gt;https://github.com/DefinitelyTyped/DefinitelyTyped&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;We've just installed the styled-components &lt;a href="https://medium.com/jspoint/typescript-type-declaration-files-4b29077c43" rel="noopener noreferrer"&gt;declaration file&lt;/a&gt;. Ready to go!&lt;/p&gt;

&lt;h1&gt;
  
  
  Add a new styled component
&lt;/h1&gt;

&lt;p&gt;Now we'll create a very basic style component, with conditional styling. Create a new file called &lt;code&gt;Heading.tsx&lt;/code&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&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;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;`
  color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; component class that takes a boolean prop called &lt;code&gt;active&lt;/code&gt;, If &lt;code&gt;active&lt;/code&gt; is set to &lt;code&gt;true&lt;/code&gt;, we set header's color to blue, otherwise we'll paint it red.&lt;/p&gt;

&lt;p&gt;Let's test it: go to App.tsx and copy the below content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;logo&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;./logo.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Heading&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;./Heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&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;header&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-header&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;Heading&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;My&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Heading&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;img&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="nx"&gt;logo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-logo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;logo&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;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Edit&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tsx&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/code&amp;gt; and save to reload&lt;/span&gt;&lt;span class="err"&gt;.
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&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;a&lt;/span&gt;
          &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://reactjs.org&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_blank&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noopener noreferrer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Learn&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&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;/header&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;/div&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've imported the &lt;code&gt;Heading&lt;/code&gt; component class, and inserted a heading with &lt;code&gt;active&lt;/code&gt; set to &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
Here's what the result should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6qwc25xcg5m42qcmw16b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6qwc25xcg5m42qcmw16b.png" alt="Image description" width="611" height="707"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well done! You're ready to build your React application in TypeScript using Styled Components! &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Intégration analytics avec TypeScript, React et les Styled Components - partie 1: l'outillage</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Mon, 05 Dec 2022 08:08:23 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/integration-analytics-avec-typescript-react-et-les-styled-components-10mc</link>
      <guid>https://dev.to/jeanremyduboc/integration-analytics-avec-typescript-react-et-les-styled-components-10mc</guid>
      <description>&lt;p&gt;Dans cette série de tutoriels, nous allons créer une application web toute simple avec trois technologies :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; sera notre language de programmation,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; sera notre framework pour développer notre application,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://styled-components.com/" rel="noopener noreferrer"&gt;Styled Components&lt;/a&gt; pour gérer les styles avec CSS-in-JS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nous allons ensuite traçer les actions utilisateurs dans l'application avec Google Analytics 4. Nous utiliserons aussi la librairie &lt;a href="https://github.com/GoogleChrome/web-vitals" rel="noopener noreferrer"&gt;Web Vitals&lt;/a&gt; pour mesurer les performances de l'application et envoyer les résultats vers GA4.&lt;/p&gt;

&lt;p&gt;L'objectif est de comprendre les workflow front-end modernes, et leurs intégrations avec Google Analytics.&lt;/p&gt;

&lt;h1&gt;
  
  
  Prérequis
&lt;/h1&gt;

&lt;p&gt;Pour faire ce tutoriel, vous aurez besoin de :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;votre application de ligne de commande favorite&lt;/li&gt;
&lt;li&gt;node, npm et npx installés sur votre ordinateur. Au moment d'écrire cet article, j'utilise node 16.11.0, npx 8.0.0 et npm 8.0.0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;J'utilise également VSCode et la ligne de commande Git bash, mais vous pouvez utiliser la ligne de commande et l'éditeur de code que vous préférez.&lt;/p&gt;

&lt;h1&gt;
  
  
  Création d'une nouvelle application React avec TypeScript
&lt;/h1&gt;

&lt;p&gt;La première étape consiste à utiliser &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;&lt;code&gt;create-react-app&lt;/code&gt;&lt;/a&gt; pour générer une application simple comme point de départ. &lt;code&gt;create-react-app&lt;/code&gt; nous facilite la vie en configurant les outils de base automatiquement. Entre autres choses, il configurera automatiquement &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt; et &lt;a href="https://babeljs.io/" rel="noopener noreferrer"&gt;Babel&lt;/a&gt; (configuré pour compiler TypeScript), ainsi que &lt;a href="https://github.com/GoogleChrome/web-vitals#send-the-results-to-google-analytics" rel="noopener noreferrer"&gt;web -vitals&lt;/a&gt;.&lt;br&gt;
Tout ça en une seule commande !&lt;/p&gt;

&lt;p&gt;Naviguez dans le dossier où vous voulez que votre application soit installée, puis tapez la command suivante :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app my-react-ts-app &lt;span class="nt"&gt;--template&lt;/span&gt; typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Et voilà ! Votre application vit maintenant dans un nouveau dossier appelé &lt;code&gt;/my-react-ts-app&lt;/code&gt;. Vous remarquerez quelques fichiers de configuration déjà en place tels que &lt;code&gt;package.json&lt;/code&gt; et &lt;code&gt;tsconfig.json&lt;/code&gt;. Vous avez également les fichiers source de l'application elle-même déjà en place dans le dossier &lt;code&gt;/src&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Démarrez votre application en tapant :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Installer des Styled Components pour TypeScript
&lt;/h1&gt;

&lt;p&gt;L'étape suivante consiste à ajouter des styled components à nos applications. Commencez par installer la bibliothèque styled-components :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensuite, nous installons les types styled-components pour TypeScript :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @types/styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;En savoir plus sur ces types sur : &lt;a href="https://github.com/DefinitelyTyped/DefinitelyTyped" rel="noopener noreferrer"&gt;https://github.com/DefinitelyTyped/DefinitelyTyped&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Nous venons d'installer le &lt;a href="https://medium.com/jspoint/typescript-type-declaration-files-4b29077c43" rel="noopener noreferrer"&gt;fichier de déclaration&lt;/a&gt; qui contient tous les types nécessaires à l'utilisation des styled components en TypeScript. C'est parti !&lt;/p&gt;

&lt;h1&gt;
  
  
  Ajouter un nouveau composant stylé
&lt;/h1&gt;

&lt;p&gt;Nous allons maintenant créer un composant de style très basique, avec un style conditionnel. Créez un nouveau fichier nommé "Heading.tsx" avec le contenu suivant :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&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;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;`
  color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cela créera une nouvelle classe de composant &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; qui prend un &lt;a href="https://fr.reactjs.org/docs/components-and-props.html#gatsby-focus-wrapper" rel="noopener noreferrer"&gt;prop&lt;/a&gt; booléen appelé &lt;code&gt;active&lt;/code&gt;. Si &lt;code&gt;active&lt;/code&gt; est défini sur &lt;code&gt;true&lt;/code&gt;, nous définissons la couleur de notre titre &lt;code&gt;h1&lt;/code&gt; sur bleu, sinon nous le peindrons en rouge.&lt;/p&gt;

&lt;p&gt;Testons-le : ouvrez App.tsx et copiez le contenu ci-dessous :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;logo&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;./logo.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Heading&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;./Heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&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;header&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-header&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;Heading&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;My&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Heading&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;img&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="nx"&gt;logo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-logo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;logo&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;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Edit&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tsx&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/code&amp;gt; and save to reload&lt;/span&gt;&lt;span class="err"&gt;.
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&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;a&lt;/span&gt;
          &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://reactjs.org&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_blank&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noopener noreferrer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Learn&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&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;/header&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;/div&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nous avons importé la classe de composants &lt;code&gt;Heading&lt;/code&gt; et inséré un titre avec &lt;code&gt;active&lt;/code&gt; défini sur &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
Voici à quoi devrait ressembler le résultat :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmr9ojk5y5fhh32bduj2i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmr9ojk5y5fhh32bduj2i.png" alt="Image description" width="611" height="707"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Joli travail! Vous êtes prêt à créer votre application React en TypeScript à l'aide des Styled Components !&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>A Simple App with TypeScript, React and Styled Components - Part 1: setting up the tools</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Tue, 29 Nov 2022 00:00:00 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/a-simple-app-with-typescript-react-and-styled-components-part-1-setting-up-the-tools-5740</link>
      <guid>https://dev.to/jeanremyduboc/a-simple-app-with-typescript-react-and-styled-components-part-1-setting-up-the-tools-5740</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1od3ouj6itmjsbg24c1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy1od3ouj6itmjsbg24c1.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;this series of tutorials, we are going to create a simple web applications using 3 technologies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; as our language of choice&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt; will be our framework to develop our app&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://styled-components.com/" rel="noopener noreferrer"&gt;Styled Components&lt;/a&gt; to manage styling with CSS-in-JS &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The aim is to learn the basics of these tools and have you write your own application in no time.&lt;br&gt;
Let's see what you'll need to get started.&lt;/p&gt;
&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;To do this tutorial you'll need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;your command line tool of choice&lt;/li&gt;
&lt;li&gt;node, npm and npx installed on your computer. At the time of writing I'm using node 16.11.0, npx 8.0.0 and nvm 0.39.1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm also using VSCode and the Git bash command line, but you can use whatever command line and code editor you prefer.&lt;/p&gt;
&lt;h1&gt;
  
  
  Creating a new React app with TypeScript
&lt;/h1&gt;

&lt;p&gt;The first step is to use &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;&lt;code&gt;create-react-app&lt;/code&gt;&lt;/a&gt; to generate a simple application as a starting point. &lt;code&gt;create-react-app&lt;/code&gt; spares us the work of configuring several build tools, and makes our life easier. Among many others, it will automatically set up &lt;a href="https://webpack.js.org/" rel="noopener noreferrer"&gt;Webpack&lt;/a&gt; and &lt;a href="https://babeljs.io/" rel="noopener noreferrer"&gt;Babel&lt;/a&gt;(configured to compile TypeScript), as well as &lt;a href="https://github.com/GoogleChrome/web-vitals#send-the-results-to-google-analytics" rel="noopener noreferrer"&gt;web-vitals&lt;/a&gt;.&lt;br&gt;
All of this in a single command!&lt;/p&gt;

&lt;p&gt;Go to the folder where you'll want you application to live, then type the below in your command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="nx"&gt;typescript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it ! Your application now lives in a new folder called &lt;code&gt;/my-react-ts-app&lt;/code&gt;. You'll notice a few configuration files already in place such as &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;tsconfig.json&lt;/code&gt;. You also have the source files for the application itself already in place in the &lt;code&gt;/src&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;Start your application by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Install Styled Components for TypeScript
&lt;/h1&gt;

&lt;p&gt;The next step is to add Styled Components to our apps. Start by installing the styled-components library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we install the styled-components types for TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @types/styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read more about these types at: &lt;a href="https://github.com/DefinitelyTyped/DefinitelyTyped" rel="noopener noreferrer"&gt;https://github.com/DefinitelyTyped/DefinitelyTyped&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;We've just installed the styled-components &lt;a href="https://medium.com/jspoint/typescript-type-declaration-files-4b29077c43" rel="noopener noreferrer"&gt;declaration file&lt;/a&gt;. Ready to go!&lt;/p&gt;

&lt;h1&gt;
  
  
  Add a new styled component
&lt;/h1&gt;

&lt;p&gt;Now we'll create a very basic style component, with conditional styling. Create a new file called &lt;code&gt;Heading.tsx&lt;/code&gt; with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&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;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;`
  color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a new &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; component class that takes a boolean prop called &lt;code&gt;active&lt;/code&gt;, If &lt;code&gt;active&lt;/code&gt; is set to &lt;code&gt;true&lt;/code&gt;, we set header's color to blue, otherwise we'll paint it red.&lt;/p&gt;

&lt;p&gt;Let's test it: go to App.tsx and copy the below content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;logo&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;./logo.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Heading&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;./Heading&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&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;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&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;header&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-header&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;Heading&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;My&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Heading&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;img&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="nx"&gt;logo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-logo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;logo&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;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Edit&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tsx&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/code&amp;gt; and save to reload&lt;/span&gt;&lt;span class="err"&gt;.
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&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;a&lt;/span&gt;
          &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://reactjs.org&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_blank&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noopener noreferrer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Learn&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&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;/header&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;/div&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've imported the &lt;code&gt;Heading&lt;/code&gt; component class, and inserted a heading with &lt;code&gt;active&lt;/code&gt; set to &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
Here's what the result should look like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2uufim7xtf8z6aksme7u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2uufim7xtf8z6aksme7u.png" alt="Image description" width="611" height="707"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well done! You're ready to build your React application in TypeScript using Styled Components! &lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Une application simple avec TypeScript, React et les Styled Components</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Fri, 25 Nov 2022 07:53:55 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/une-application-simple-avec-typescript-react-et-les-styled-components-254</link>
      <guid>https://dev.to/jeanremyduboc/une-application-simple-avec-typescript-react-et-les-styled-components-254</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h3Yi7vJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wzkzlf7w483a6eh4o68.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h3Yi7vJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wzkzlf7w483a6eh4o68.png" alt="Image description" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dans cette série de tutoriels, nous allons créer une application web simple avec trois technologies :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt; sera notre language de programmation,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; sera notre framework pour développer notre application,&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://styled-components.com/"&gt;Styled Components&lt;/a&gt; pour gérer les styles avec CSS-in-JS.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;L'objectif est d'apprendre les bases de ces outils pour vous permettre d'écrire votre propre application en un rien de temps.&lt;br&gt;
Voyons ce dont vous aurez besoin pour commencer.&lt;/p&gt;
&lt;h1&gt;
  
  
  Prérequis
&lt;/h1&gt;

&lt;p&gt;Pour faire ce tutoriel, vous aurez besoin de :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;votre application de ligne de commande favorite&lt;/li&gt;
&lt;li&gt;node, npm et npx installés sur votre ordinateur. Au moment d'écrire cet article, j'utilise node 16.11.0, npx 8.0.0 et npm 8.0.0.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;J'utilise également VSCode et la ligne de commande Git bash, mais vous pouvez utiliser la ligne de commande et l'éditeur de code que vous préférez.&lt;/p&gt;
&lt;h1&gt;
  
  
  Création d'une nouvelle application React avec TypeScript
&lt;/h1&gt;

&lt;p&gt;La première étape consiste à utiliser &lt;a href="https://create-react-app.dev/"&gt;&lt;code&gt;create-react-app&lt;/code&gt;&lt;/a&gt; pour générer une application simple comme point de départ. &lt;code&gt;create-react-app&lt;/code&gt; nous facilite la vie en configurant les outils de base automatiquement. Entre autres choses, il configurera automatiquement &lt;a href="https://webpack.js.org/"&gt;Webpack&lt;/a&gt; et &lt;a href="https://babeljs.io/"&gt;Babel&lt;/a&gt; (configuré pour compiler TypeScript), ainsi que &lt;a href="https://github.com/GoogleChrome/web-vitals#send-the-results-to-google-analytics"&gt;web -vitals&lt;/a&gt;.&lt;br&gt;
Tout ça en une seule commande !&lt;/p&gt;

&lt;p&gt;Naviguez dans le dossier où vous voulez que votre application soit installée, puis tapez la command suivante :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npx&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;my&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;react&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="nx"&gt;typescript&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Et voilà ! Votre application vit maintenant dans un nouveau dossier appelé &lt;code&gt;/my-react-ts-app&lt;/code&gt;. Vous remarquerez quelques fichiers de configuration déjà en place tels que &lt;code&gt;package.json&lt;/code&gt; et &lt;code&gt;tsconfig.json&lt;/code&gt;. Vous avez également les fichiers source de l'application elle-même déjà en place dans le dossier &lt;code&gt;/src&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Démarrez votre application en tapant :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Installer des Styled Components pour TypeScript
&lt;/h1&gt;

&lt;p&gt;L'étape suivante consiste à ajouter des styled components à nos applications. Commencez par installer la bibliothèque styled-components :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensuite, nous installons les types styled-components pour TypeScript :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;--save-dev&lt;/span&gt; @types/styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;En savoir plus sur ces types sur : &lt;a href="https://github.com/DefinitelyTyped/DefinitelyTyped"&gt;https://github.com/DefinitelyTyped/DefinitelyTyped&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Nous venons d'installer le &lt;a href="https://medium.com/jspoint/typescript-type-declaration-files-4b29077c43"&gt;fichier de déclaration&lt;/a&gt; qui contient tous les types nécessaires à l'utilisation des styled components en TypeScript. C'est parti !&lt;/p&gt;

&lt;h1&gt;
  
  
  Ajouter un nouveau composant stylé
&lt;/h1&gt;

&lt;p&gt;Nous allons maintenant créer un composant de style très basique, avec un style conditionnel. Créez un nouveau fichier nommé "Heading.tsx" avec le contenu suivant :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styled&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;styled-components&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styled&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;`
  color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;red&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;blue&lt;/span&gt;&lt;span class="dl"&gt;'&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cela créera une nouvelle classe de composant &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; qui prend un &lt;a href="https://fr.reactjs.org/docs/components-and-props.html#gatsby-focus-wrapper"&gt;prop&lt;/a&gt; booléen appelé &lt;code&gt;active&lt;/code&gt;. Si &lt;code&gt;active&lt;/code&gt; est défini sur &lt;code&gt;true&lt;/code&gt;, nous définissons la couleur de notre titre &lt;code&gt;h1&lt;/code&gt; sur bleu, sinon nous le peindrons en rouge.&lt;/p&gt;

&lt;p&gt;Testons-le : ouvrez App.tsx et copiez le contenu ci-dessous :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;logo&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;./logo.svg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Heading&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;./Heading&lt;/span&gt;&lt;span class="dl"&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;App&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;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&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;header&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-header&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;Heading&lt;/span&gt; &lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;My&lt;/span&gt; &lt;span class="nx"&gt;Heading&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Heading&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;img&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="nx"&gt;logo&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-logo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;alt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;logo&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;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Edit&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tsx&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/code&amp;gt; and save to reload&lt;/span&gt;&lt;span class="err"&gt;.
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&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;a&lt;/span&gt;
          &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App-link&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://reactjs.org&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_blank&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
          &lt;span class="nx"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;noopener noreferrer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;Learn&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&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;/header&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;/div&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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nous avons importé la classe de composants &lt;code&gt;Heading&lt;/code&gt; et inséré un titre avec &lt;code&gt;active&lt;/code&gt; défini sur &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
Voici à quoi devrait ressembler le résultat :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mN9din9J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wewx8ade5ei3nm8ixwbk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mN9din9J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wewx8ade5ei3nm8ixwbk.png" alt="Image description" width="611" height="707"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Joli travail! Vous êtes prêt à créer votre application React en TypeScript à l'aide des Styled Components !&lt;/p&gt;

</description>
      <category>react</category>
      <category>styledcomponents</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Les développeurs doivent être paresseux: voilà pourquoi</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Fri, 25 Nov 2022 07:25:49 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/les-developpeurs-doivent-etre-paresseux-voila-pourquoi-36jb</link>
      <guid>https://dev.to/jeanremyduboc/les-developpeurs-doivent-etre-paresseux-voila-pourquoi-36jb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Je pense que c'est une bonne chose pour les programmeurs (ou, en réalité, n'importe quel travailleur) d'être paresseux.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Je pense vraiment que les recruteurs devraient rechercher le développeur le plus paresseux qu'ils puissent trouver.&lt;br&gt;
OK, OK, tout le monde, posez vos fourches et vos torches, et laissez-moi vous expliquer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Deux types de paresse
&lt;/h1&gt;

&lt;p&gt;L'autre jour, sur Twitter, quelqu'un a demandé s'il fallait utiliser des points-virgules en JS. Mon avis ? Je ne m'embête pas avec ça. Pour moi, c'est du gaspillage de frappe, un effort inutile. Cela ne rend pas le code meilleur ou plus facile à lire, et si ça peut faire gagner quelques millisecondes ici et là, je suis à 100% pour. J'essaie toujours de trouver la voie de la moindre résistance, ce que j'ai appelé "&lt;strong&gt;l'option du plus faible effort&lt;/strong&gt;" dans mon tweet.&lt;br&gt;
Cela a provoqué une tempête dans un vers d'eau, et certains ce sont vexé:&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;Ew. Lowest effort option? That ethos couldn’t lead to great software…&lt;br&gt;&lt;br&gt;That being said, when I’m speed coding on &lt;a href="https://twitter.com/LeetCode?ref_src=twsrc%5Etfw"&gt;@LeetCode&lt;/a&gt; I’ve begun dropping the semicolons. I’m so ashamed of myself. 🤦‍♂️😜&lt;/p&gt;— Zakery Kates (@zakkates) &lt;a href="https://twitter.com/zakkates/status/1591210130150150144?ref_src=twsrc%5Etfw"&gt;November 11, 2022&lt;/a&gt;
&lt;/blockquote&gt; 


&lt;blockquote&gt;
&lt;p&gt;I disagree. Semi-colons are there to separate the end of each line and therefore serve a purpose to both compiler and programmer. There's no way low effort is always the best policy - it just leads to lazy programming.&lt;/p&gt;— Daniel Hartgrove (@danhartgrovexyz) &lt;a href="https://twitter.com/danhartgrovexyz/status/1591423705821089794?ref_src=twsrc%5Etfw"&gt;November 12, 2022&lt;/a&gt;
&lt;/blockquote&gt; 

&lt;p&gt;Il y a quelques points techniques valables ici, mais la réponse qui m'a le plus dérangé a été le "ewww, peu d'effort ? Mais c'est pour les perdants !" viscérale. Cela me dérange parce qu'ils ont mal compris ce que je voulais dire. Je ne parlais en aucun cas de tout lâcher, de ne pas faire son travail sérieusement.&lt;/p&gt;

&lt;p&gt;Je crois que ces commentateurs ont lu "l'option du plus faible effort" et ont compris "un faible effort tout le temps". Ce n'est absolument pas ce que je veux dire. Je parlais de la vraie paresse, comme Larry Wall le décrit dans &lt;a href="https://www.amazon.co.uk/Programming-Perl-Unmatched-processing-scripting"&gt;le livre Perl&lt;/a&gt; :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don’t have to answer so many questions about it. Hence, the first great virtue of a programmer. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  La vraie « paresse » = optimisation
&lt;/h1&gt;

&lt;p&gt;Voyez-vous, cher lecteur, nous ne parlons pas de relâchement ici. Il ne s'agit pas de copier et coller du code manuellement jusqu'à ce qu'il soit temps de rentrer à la maison, parce qu'on a la flemme d'écrire un script avec une ou deux regexps qui feront le travail en quelques secondes. L'écriture du script demande certe plus d'efforts au départ, mais vous fera économiser des heures de travail fastidieux sur le long terme. Et peut-être aider vos collègues. Et vous donner plus de temps libre pour travailler sur quelque chose de plus intéressant, ou simplement pour vous détendre un peu si vous en avez envie.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6LsMNom6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/911cryhhm8fgl7pmsyen.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6LsMNom6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/911cryhhm8fgl7pmsyen.png" alt="Image description" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Je veux prendre le chemin de la moindre résistance, oui, mais c'est seulement pour obtenir plus de qualité, pour avancer, pour accélérer les choses, et, au final, pour éviter de perdre un temps précieux sur du baratin inutile.&lt;/p&gt;

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

&lt;p&gt;En outre, &lt;a href="https://www.amazon.co.uk/Laziness-Does-Exist-Devon-Price-ebook/dp/B08C1G3J1T/ref=tmm_kin_swatch_0?_encoding=UTF8&amp;amp;qid=&amp;amp;sr="&gt;je ne crois plus à la paresse de toute façon&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Je suis tombé sur un autre exemple l'autre jour. Un collègue implémentait une nouvelle fonctionnalité de paiement (temporaire) sur l'un de nos sites. Nous voulions savoir quand les utilisateurs ont finalisé un achat sur le site, à la fois dans Universal Analytics et dans GA4. Étant donné qu'il y avait quelques paramètres inhabituels dans le traçage de cette fonctionnalité, il avait initiallement envisagé de déclencher les événements directement dans son code, à l'aide du &lt;a href="https://support.google.com/analytics/answer/9900444?hl=en"&gt;protocole de mesure d'Universal Analytics&lt;/a&gt; et du &lt;a href="https://developers.google.com/analytics/devguides/collection/protocol/ga4"&gt;protocole de mesure de GA4&lt;/a&gt; pour suivre tout ça. Gardez à l'esprit que nous avions déjà une configuration complète de Google Tag Manager, avec UA et GA4 déjà en place.&lt;br&gt;&lt;br&gt;
Mon cerveau paresseux s'est simplement demandé "a-t-on vraiment besoin de faire tout ce boulot pour une fonctionnalité &lt;em&gt;temporaire&lt;/em&gt; ?". Il s'avère qu'il existait une solution simple avec très peu de code : il suffit de pousser les données concernant l'achat dans le datalayer, et d'ajuster GTM pour déclencher correctement les événements. Boom. Tout ça été bouclé en quelques heures.&lt;/p&gt;

&lt;p&gt;Du coup j'ai passé le reste de la journée à regarder la télé. Je plaisante.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Developers should be lazy; here's why</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Fri, 25 Nov 2022 07:13:50 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/developers-should-be-lazy-heres-why-3j0</link>
      <guid>https://dev.to/jeanremyduboc/developers-should-be-lazy-heres-why-3j0</guid>
      <description>&lt;p&gt;I believe it's a good thing for programmers (or any worker, really) to be lazy. I truly think hiring managers should seek the laziest developer they can find. &lt;br&gt;
All right, people, put your pitchforks down and let me explain. &lt;/p&gt;

&lt;h1&gt;
  
  
  Two kinds of laziness
&lt;/h1&gt;

&lt;p&gt;On Twitter the other day, someone asked if one should use semicolons in JS. My take? I don't bother. To me, it's wasted typing, wasted effort for no benefit. It doesn't make the code any better or easier to read, and it might save a few milliseconds here and there. I'm all about that. I'm all about choosing the path of least resistance, what I called "&lt;strong&gt;the lowest effort option&lt;/strong&gt;" in my tweet.&lt;br&gt;
This caused a bit of a storm in a teacup, and triggered a few folks:&lt;/p&gt;


&lt;blockquote&gt;
&lt;p&gt;Ew. Lowest effort option? That ethos couldn’t lead to great software…&lt;br&gt;&lt;br&gt;That being said, when I’m speed coding on &lt;a href="https://twitter.com/LeetCode?ref_src=twsrc%5Etfw"&gt;@LeetCode&lt;/a&gt; I’ve begun dropping the semicolons. I’m so ashamed of myself. 🤦‍♂️😜&lt;/p&gt;— Zakery Kates (@zakkates) &lt;a href="https://twitter.com/zakkates/status/1591210130150150144?ref_src=twsrc%5Etfw"&gt;November 11, 2022&lt;/a&gt;
&lt;/blockquote&gt; 


&lt;blockquote&gt;
&lt;p&gt;I disagree. Semi-colons are there to separate the end of each line and therefore serve a purpose to both compiler and programmer. There's no way low effort is always the best policy - it just leads to lazy programming.&lt;/p&gt;— Daniel Hartgrove (@danhartgrovexyz) &lt;a href="https://twitter.com/danhartgrovexyz/status/1591423705821089794?ref_src=twsrc%5Etfw"&gt;November 12, 2022&lt;/a&gt;
&lt;/blockquote&gt; 

&lt;p&gt;There's a few valid technical points there, but the response that bothered me most was the immediate "ewww, low effort? That's for losers." gut reaction. It bothers me because they misinterpreted what I meant. I wasn't talking about slacking off and not doing a good job. &lt;/p&gt;

&lt;p&gt;I believe these responder read "the lowest effort option", and understood "low effort all the time". That is not what I mean. I was talking about true laziness, the way Larry Wall describes it in &lt;a href="https://www.amazon.co.uk/Programming-Perl-Unmatched-processing-scripting"&gt;the Perl book&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don’t have to answer so many questions about it. Hence, the first great virtue of a programmer. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  True laziness = optimisation
&lt;/h1&gt;

&lt;p&gt;You see, dear reader, we're not talking about slacking off here. It's not about copying and pasting code manually until it's time to go clock out and go home, because you can't be bothered to write a script with regexp or two that will do the job for you in seconds. Writing the script takes more effort initially, but will save hours of tedious labor down the line. And maybe help your colleagues. And give you more free time to work on something more interesting, or just to relax for a bit if you feel like it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vjjseh6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9a7arvcxf5n618p2h26u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vjjseh6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9a7arvcxf5n618p2h26u.png" alt="Image description" width="880" height="880"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want to take the path of least resistance, yes, but it's only to get more quality, to scale, to speed things up, and ultimately, to avoid spending precious company time on useless BS.&lt;/p&gt;

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

&lt;p&gt;Besides, &lt;a href="https://www.amazon.co.uk/Laziness-Does-Exist-Devon-Price-ebook/dp/B08C1G3J1T/ref=tmm_kin_swatch_0?_encoding=UTF8&amp;amp;qid=&amp;amp;sr="&gt;I no longer believe laziness is real anyway&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I came across another example just the other day. A collegue was implementing a new (temporary) payment feature on one of our sites. We needed to track when users finalised a purchase on the site in both Universal Analytics and GA4. Because there were a few odd parameters in the tracking, he was planning on triggering the events in his code, using &lt;a href="https://support.google.com/analytics/answer/9900444?hl=en"&gt;Universal Analytics's measurement protocol&lt;/a&gt; and &lt;a href="https://developers.google.com/analytics/devguides/collection/protocol/ga4"&gt;GA4's measurement protocol&lt;/a&gt; directly to track all this. Keep in mind we already had a fully fledge Google Tag Manager setup, with both UA and GA4 configured.&lt;br&gt;
My Lazy brain just went "do we really need to do all that work for a &lt;em&gt;temporary&lt;/em&gt; feature?". Turns out there was a simple, low-code solution: just push data about the purchase in the datalayer, and tweak GTM to trigger the events correctly. Boom. All done in a few hours.&lt;/p&gt;

&lt;p&gt;I spent the rest of the day watching TV. Just kidding.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understanding Default Dimensions in Google Analytics 4</title>
      <dc:creator>Jean-Rémy Duboc</dc:creator>
      <pubDate>Wed, 09 Nov 2022 08:17:50 +0000</pubDate>
      <link>https://dev.to/jeanremyduboc/understanding-default-dimensions-in-google-analytics-4-982</link>
      <guid>https://dev.to/jeanremyduboc/understanding-default-dimensions-in-google-analytics-4-982</guid>
      <description>&lt;h1&gt;
  
  
  What is a dimension in GA4? A Few Examples
&lt;/h1&gt;

&lt;p&gt;Google Analytics is a tool designed to collect data. To know what the data represents, we use dimensions.&lt;br&gt;
For example, when a user browses a web page, Google Analytics measures the following dimensions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The URL of the page&lt;/li&gt;
&lt;li&gt;Day and time&lt;/li&gt;
&lt;li&gt;The the user's location, distributed over several dimensions: continent, country, city, etc.&lt;/li&gt;
&lt;li&gt;Possibly dimensions describing the original source of the user (campaign, medium, )&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Quick reminder: in GA4, unlike Universal Analytics, a page visit is represented by an event.&lt;/p&gt;

&lt;p&gt;Now let's see how we can visualise these dimensions in our reports on GA4.&lt;/p&gt;

&lt;h1&gt;
  
  
  Use dimensions in reports on GA4
&lt;/h1&gt;

&lt;p&gt;The reports available by default in GA4 are simply used to view the dimensions present by default, grouped by category. Let's see, for example, the "User Acquisition" report:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HqvO-79k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4twm4k1thhxckxxbfcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HqvO-79k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n4twm4k1thhxckxxbfcg.png" alt="Image description" width="880" height="363"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this report we can see, arranged in a line, the values defined for an acquisition dimension, the &lt;em&gt;First user default channel grouping&lt;/em&gt;. This dimension represents the group of origin of the first interaction with a user: organic search (Organic Search), sponsored search (Paid Search), direct traffic, etc.&lt;br&gt;
The columns show us the different &lt;em&gt;metrics&lt;/em&gt; related to this dimension: number of new users, sessions with engagement, conversions, etc.&lt;br&gt;
The acquisition report allows you to see these same metrics linked with other dimensions: source of the first interaction, first ad group of the user, etc.&lt;br&gt;
This report therefore allows you to see the acquisition and promotion techniques that work best. We can answer questions such as: what is my most effective promotional campaign? Does organic traffic generate more conversion than traffic from promotional campaigns, etc. ?&lt;/p&gt;

&lt;h2&gt;
  
  
  Secondary Dimensions
&lt;/h2&gt;

&lt;p&gt;You can also add secondary dimensions to group the dimensions into subcategories:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4XZWMKyX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6x41dhc1ie4js6d38lvv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4XZWMKyX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6x41dhc1ie4js6d38lvv.png" alt="Image description" width="358" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the example below we have aggregated users by first grouping by default, and by country (the country is the secondary dimension):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KWJoD8Lz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwtpz6nnpc1r5mufl1v1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KWJoD8Lz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwtpz6nnpc1r5mufl1v1.png" alt="Image description" width="880" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't hesitate to explore the other reports to observe the multiple dimensions at your disposal.&lt;/p&gt;

&lt;h1&gt;
  
  
  Some default dimensions to know on GA4
&lt;/h1&gt;

&lt;p&gt;By default, Google Analytics 4 provides us with a wide range of dimensions. You can see a complete list in the &lt;a href="https://support.google.com/analytics/answer/9143382"&gt;official Google documentation&lt;/a&gt;.&lt;br&gt;
Let us see some of these dimensions in details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where do your users come from? Attribution dimensions and traffic sources
&lt;/h2&gt;

&lt;p&gt;Attribution and traffic source dimensions help identify users and sessions based on criteria such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Marketing campaigns used for acquisition&lt;/li&gt;
&lt;li&gt;acquisition support (email, CPC, etc.)&lt;/li&gt;
&lt;li&gt;source (the publisher or the source of inventory having generated traffic)&lt;/li&gt;
&lt;li&gt;data relating to Google Ads or Search Ads 360:&lt;/li&gt;
&lt;li&gt;account name&lt;/li&gt;
&lt;li&gt;ad group&lt;/li&gt;
&lt;li&gt;keyword&lt;/li&gt;
&lt;li&gt;query&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;li&gt;data relating to creatives on &lt;a href="https://support.google.com/displayvideo#topic=9059505"&gt;Google Display &amp;amp; Video 360&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Attribution dimensions are user-driven, while Traffic Source dimensions are user-driven and session-driven.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding your Visitors - Demographics, Geographies and Device
&lt;/h2&gt;

&lt;p&gt;In order to best serve our customers, we need to know who they are. Identifying customers by certain criteria can help us know if our app is serving the right people, understand how people from different backgrounds use our app, compare different populations, and more.&lt;/p&gt;

&lt;p&gt;For example, you can use the dimensions of demographic data automatically deduced by Google, after having &lt;a href="https://support.google.com/analytics/answer/7532985"&gt;activated Google signals&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Age&lt;/li&gt;
&lt;li&gt;Gender&lt;/li&gt;
&lt;li&gt;Hobbies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The geographical origin of visitors is measured with the following default dimensions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;City/City ID&lt;/li&gt;
&lt;li&gt;Continent and subcontinent/ID &lt;a href="https://en.wikipedia.org/wiki/UN_M49"&gt;UN M29&lt;/a&gt; of subcontinent&lt;/li&gt;
&lt;li&gt;Country/ID &lt;a href="https://en.wikipedia.org/wiki/ISO_3166"&gt;ISO 3166&lt;/a&gt; of country&lt;/li&gt;
&lt;li&gt;Region/Region ID&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can also know what type of platforms are used to navigate our application. It's very useful to provide the best user experience. For example, if we know that 90% of our visitors are on a tablet device with a relatively low screen resolution, we will favor optimization for this configuration (or try to understand why users prefer this option, which may reveal a problem on other platforms).&lt;br&gt;
The Platform/Device dimensions to consider are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser&lt;/li&gt;
&lt;li&gt;Device&lt;/li&gt;
&lt;li&gt;Device category (mobile, tablet or computer)&lt;/li&gt;
&lt;li&gt;Operating system&lt;/li&gt;
&lt;li&gt;Platform ("Android", "iOS" and "Web")&lt;/li&gt;
&lt;li&gt;Screen resolution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Important note&lt;/strong&gt;: make sure you have users' consent in advance (using the appropriate GDPR tools) before recording this type of personal data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Know what your users are doing - events, page/screen, and user lifetime
&lt;/h2&gt;

&lt;p&gt;Now let's move on to the details of user actions on our application.&lt;br&gt;
For events, we have two key dimensions at our disposal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Event name&lt;/li&gt;
&lt;li&gt;Is it a conversion event ("true" if the event is a &lt;a href="https://support.google.com/analytics/answer/9267568"&gt;conversion&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To know what type of page or screen our users are on, we have, among others, the following dimensions at our disposal:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Page location (page URL or screen)&lt;/li&gt;
&lt;li&gt;Page referrer (the previous page in the user's journey, which can be on your site or another site)&lt;/li&gt;
&lt;li&gt;Page title&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Engagement metrics&lt;/strong&gt; will be used to measure data such as time spent on page.&lt;/p&gt;

&lt;p&gt;Finally, to find out if visitors are loyal and often return to the application, we can use "User lifetime" type dimensions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Date of the first session&lt;/li&gt;
&lt;li&gt;Date of first visit&lt;/li&gt;
&lt;li&gt;Date of last activity&lt;/li&gt;
&lt;li&gt;Date of first purchase&lt;/li&gt;
&lt;li&gt;Date of last purchase&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Measure the commercial performance of your application - E-commerce dimensions
&lt;/h2&gt;

&lt;p&gt;Finally, if you have an e-commerce site, Google Analytics provides you with a large number of dimensions to describe the products you sell, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Currency&lt;/li&gt;
&lt;li&gt;Item brand&lt;/li&gt;
&lt;li&gt;Item category (with 5 levels of hierarchy for your subcategories)&lt;/li&gt;
&lt;li&gt;Discount voucher for the item&lt;/li&gt;
&lt;li&gt;Item ID&lt;/li&gt;
&lt;li&gt;Item name&lt;/li&gt;
&lt;li&gt;Local price of the item&lt;/li&gt;
&lt;li&gt;Shipping tier (by road transport, by air, next day, etc.)&lt;/li&gt;
&lt;li&gt;Tax amount&lt;/li&gt;
&lt;li&gt;Transaction ID&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Dimension activation and monitoring
&lt;/h1&gt;

&lt;p&gt;To create reports that suit your needs, you will need to enable and test the necessary dimensions. Some dimensions are activated and populated by default, but others, depending on the data collected, must be activated in a specific way.&lt;br&gt;
Refer to the &lt;a href="https://support.google.com/analytics/answer/9143382?hl=fr"&gt;Google documentation&lt;/a&gt; to find out how to activate each dimension.&lt;/p&gt;

&lt;p&gt;To see at a glance which dimensions are available on your property, use the &lt;a href="https://ga-dev-tools.web.app/ga4/dimensions-metrics-explorer/"&gt;dimensions and metrics explorer provided by Google&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;What dimensions do you use for your Google Analytics reports and why? Feel free to share your experiences!&lt;/p&gt;

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