<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pier-Yves C Valade on Medium]]></title>
        <description><![CDATA[Stories by Pier-Yves C Valade on Medium]]></description>
        <link>https://medium.com/@pycvalade?source=rss-a90715a517df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xqwOBX3PXnupkM8j5drN5Q.jpeg</url>
            <title>Stories by Pier-Yves C Valade on Medium</title>
            <link>https://medium.com/@pycvalade?source=rss-a90715a517df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 03:44:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pycvalade/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AWS Magic: Adding Free Let’s Encrypt SSL Certificate to Amazon Linux]]></title>
            <link>https://medium.com/@pycvalade/aws-magic-adding-free-lets-encrypt-ssl-certificate-to-amazon-linux-1d53701dafde?source=rss-a90715a517df------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d53701dafde</guid>
            <category><![CDATA[https]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Pier-Yves C Valade]]></dc:creator>
            <pubDate>Thu, 01 Mar 2018 22:37:41 GMT</pubDate>
            <atom:updated>2018-11-28T01:01:01.720Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*e4sd_8bAgg7GAYPyM1w8KA.jpeg" /></figure><p>With today’s web, having an SSL certificate on your website that shows a <strong>green HTTPS icon</strong> in your visitor’s browser is a must. Not only does it drastically help with SEO, it also ensures transactions between your website and your visitor are encrypted and hacker proof-ish to a certain extent. Read on to get all the info on how to setup <strong>Amazon Linux SSL using Let’s Encrypt</strong>!</p><h3>How does Let’s Encrypt SSL and Certbot work?</h3><p>In the past, setting up an <strong>HTTPS website with an SSL certificate</strong> required recurring yearly fees from a certificate authority like <a href="https://www.comodo.com/">Comodo SSL Certificates</a> otherwise you would trigger the big red “danger danger site” warning on most browsers and <strong>scare your visitors</strong> to safety.</p><p>With the dream of an <strong>HTTPS-only web</strong> put forward by <a href="https://searchengineland.com/google-starts-giving-ranking-boost-secure-httpsssl-sites-199446">Google</a></p><p><a href="https://searchengineland.com/google-starts-giving-ranking-boost-secure-httpsssl-sites-199446">and other major tech companies, </a><a href="https://letsencrypt.org/">Let’s Encrypt Free Certificate Authority</a> with the help of <a href="https://certbot.eff.org/">Certbot automations</a> created the perfect setup to promote a secure browsing experience to web users at a cost every site owner can afford: <em>free</em>.</p><p>Simply put, <strong>Let’s Encrypt is the Certificate Authority</strong> providing the trust certificate and <strong>Certbot</strong> is the program you will use to install and keep up to date the certificate on your server.</p><h3>Setting up your Amazon Linux for SSL</h3><p>Looks easy enough, here’s how to setup your HTTPS Let’s Encrypt certificate on your single website <strong>AWS EC2 Amazon Linux AMI</strong> instance of predilection. Take note that the process should be very similar for any linux based LAMP server setup.</p><h3>Installing the mod_ssl module for Apache</h3><p>First, let’s make sure Apache is running:</p><pre>[ec2-user ~]$ sudo service httpd status</pre><p>If not, start it to make sure everything is fine:</p><pre>[ec2-user ~]$ sudo service httpd start</pre><p>Now that we know Apache is good to go, we’ll need <strong>the mod_ssl module installed and our server up-to-date</strong>.</p><pre>[ec2-user ~]$ sudo yum update -y <br>[ec2-user ~]$ sudo yum install -y mod24_ssl</pre><h3>Downloading Certbot’s tool</h3><p>First thing you will want to do is download <strong>Cerbot’s tool</strong> to setup everything. At time of writing those lines, the URL was <a href="https://dl.eff.org/certbot-auto">https://dl.eff.org/certbot-auto</a>.</p><p>Simply login via SSH to your <strong>AWS EC2 instance</strong> and type this in to download the software:</p><pre>[ec2-user ~]$ wget <a href="https://dl.eff.org/certbot-auto">https://dl.eff.org/certbot-auto</a></pre><p>Then, we will need to make the software executable, changing the rights on the file like so:</p><pre>[ec2-user ~]$ chmod a+x ./certbot-auto</pre><h3>Generating your Let’s Encrypt Free SSL Certificate</h3><p>Since, at the time of writing, <strong>Amazon Linux wasn’t officially supported</strong>, we will need to run Cerbot’s tool in <strong>standalone mode with the debug flag on</strong> and update the Apache config ourselves.</p><p>Make sure that your DNS records are set properly for those domains before continuing!</p><p>First, let’s turn off Apache so that <a href="https://letsencrypt.org/how-it-works/">Certbot can do it’s thing</a>:</p><pre>[ec2-user ~]$ sudo service httpd stop</pre><p>Here’s how to do it for the domain “example.com”:</p><pre>[ec2-user ~]$ ./certbot-auto certonly --standalone --debug -d example.com -d <a href="http://www.example.com/">www.example.com</a></pre><p>Notice the “www.example.com” option added there. <strong>You can add as many subdomains as you want using the -d flag.</strong> The WWW subdomain is usually needed by most applications, hence why I added it in the example.</p><p>The <strong>Certbot</strong> will once again do its robot thing and after asking you a few questions hopefully come back to you with <strong>paths to your certificate and private key files</strong> (as shown in the previous screenshot) for you to add to Apache’s config.</p><h3>Configuring Apache with your Let’s Encrypt certificate</h3><p>Now that <strong>Certbot</strong> has created the required files for you, all you need to do is configure Apache for SSL and where to locate the required files.</p><p>While this may vary, Certbot will usually put your certs in the following paths for you:</p><pre>Certificate: /etc/letsencrypt/live/example.com/cert.pem <br>Full Chain: /etc/letsencrypt/live/example.com/fullchain.pem <br>Private Key: /etc/letsencrypt/live/example.com/privkey.pem</pre><p>Simply edit your <strong>Apache SSL config</strong> using your favorite text editor, mine being vim.</p><pre>[ec2-user ~]$ sudo vim /etc/httpd/conf.d/ssl.conf</pre><p>Now, go find and edit those 3 lines using the provided paths above:</p><ul><li>Set SSLCertificateFile to your Certificate path.</li><li>Set SSLCertificateKeyFile to your Private Key path.</li><li>Set SSLCertificateChainFile to your Full Chain path.</li></ul><p>Save and close the file. Now all you need to do is restart Apache and voilà!</p><pre>[ec2-user ~]$ sudo service httpd restart</pre><h3>Setting up Certbot’s auto-renew job</h3><p><strong>Let’s Encrypt certificates</strong> are valid for 90 days from the time of generation. In order to keep them free-forever, you will need to renew them using <strong>Certbot’s auto-renew feature</strong>. Just to make sure it’s always valid, I like to run it twice a day, every day with a cron job. If it’s not due for renewal, Certbot will automagically skip the update!</p><p>Here’s how to edit your crontab:</p><pre>[ec2-user ~]$ crontab -e</pre><p>Here’s what to add at the end of the crontab file:</p><pre>0 1,13 * * * /home/ec2-user/certbot-auto renew</pre><p>Simply copy-paste what’s above and then save/exit the text editor!</p><p>If everything went according to plan, you should be enjoying a fully functional HTTPS website using a <strong>free SSL certificate provided by Let’s Encrypt on your AWS EC2 Amazon Linux instance</strong>! Congrats 🙂</p><p>If it’s not working out as it should, comment below so that I can try to help!</p><p><em>Originally published at </em><a href="https://pycvala.de/blog/aws/aws-magic-adding-lets-encrypt-ssl-to-amazon-linux/"><em>pycvala.de</em></a><em> on March 1, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d53701dafde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PowerShell: Adding Office 365 Group Members to an Exchange Shared Mailbox]]></title>
            <link>https://medium.com/@pycvalade/powershell-adding-office-365-group-members-to-an-exchange-shared-mailbox-271bb7d36d76?source=rss-a90715a517df------2</link>
            <guid isPermaLink="false">https://medium.com/p/271bb7d36d76</guid>
            <category><![CDATA[sysadmin]]></category>
            <category><![CDATA[exchange]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[office-365]]></category>
            <category><![CDATA[powershell]]></category>
            <dc:creator><![CDATA[Pier-Yves C Valade]]></dc:creator>
            <pubDate>Thu, 18 Jan 2018 22:55:24 GMT</pubDate>
            <atom:updated>2018-11-28T01:04:33.675Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*DjokjGvJGrzGF7AkEsYp2Q.jpeg" /></figure><p>For one of my clients, we had to migrate a Microsoft Exchange 2010 server to <strong>Microsoft Exchange 365</strong> in one night. Lots of shared mailboxes had to be migrated by hand and it’s authorized users required to be added one by one through the interface as there was no feature provided by Microsoft to just add all members of a group. We were in need of a <strong>PowerShell script</strong>!</p><p>Having only one night to make it work and nothing to be found on the web to help, I managed to babble this little <a href="https://fr.wikipedia.org/wiki/Windows_PowerShell">Power Shell</a> script that logs into the <strong>Online Exchange Power Shell console</strong> and adds all users of Office 365 groups as full access users on a defined shared mailbox or any mailbox.</p><h3>Connecting to Microsoft Exchange Online PowerShell</h3><p>First thing to do is to connect to your <strong>Online Exchange PowerShell</strong>. Here’s how to proceed. You can read on my simpler version or go through the full Microsoft documentation on <a href="https://technet.microsoft.com/en-us/library/jj984289(v=exchg.160).aspx">how to connect</a> to the Online Microsoft Exchange PowerShell.</p><h3>Run PowerShell as Administrator</h3><p>With everything Microsoft, the easiest way of getting something working the first time is to run the program or commands as an Administrator to avoid lacking of sufficient permissions.</p><p>To run Power Shell as administrator in Windows 10, simply search for “Power Shell” in the search bar located down left beside the Windows menu icon. Then, right click on the <strong>Power Shell program</strong> that pops up, or the <a href="https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ise/introducing-the-windows-powershell-ise?view=powershell-5.1">Power Shell ISE</a> one which I prefer, and select Run as Administrator in the resulting dropdown.</p><p>Voilà, you are now running every commands or script as admin in this instance of Power Shell!</p><h3>Enable Remote Certificate support</h3><p>In order for our <strong>PowerShell environment</strong> to accept the remote certificate of our online Microsoft Exchange server, we need to configure our environment to do so. This is a one time thing, and is only needed to be activated once per computer.</p><p>Simply type on the PowerShell command line:</p><pre>Set-ExecutionPolicy RemoteSigned</pre><h3>Supply Your Credentials</h3><p>Next up, we need to tell our Power Shell environment which <strong>credentials</strong> to use to connect to our remote server.</p><p>There’s many ways of doing so but the simplest is to type-in this:</p><pre>$UserCredential = Get-Credential</pre><p>A windows dialog will popup asking you for your credentials, which are the same as the ones you use to login into your <strong>Office 365 console</strong> online. Put in your username and password and submit them. They are now stored into the $UserCredential variable we will use next.</p><h3>Open a New Session on Your Online Exchange Server</h3><p>Now, we have everything to open a new session to our Online Microsoft Exchange 365 Console. We’ll store it into a $Session variable so that we can work with it afterwards.</p><p>Simply copy-paste this into the prompt and hit Enter:</p><pre>$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection</pre><p>Now, our session is stored into this new variable!</p><h3>Import the Remote Session</h3><p>Now to make everything work locally, we need to import the session to our <strong>PowerShell environment</strong>.</p><pre>Import-PSSession $Session</pre><p>This might take a few seconds to download and work its magic. Once done, congrats you’re connected to your remote Exchange 365 console!</p><h3>Testing Your Online Microsoft Exchange PowerShell Connection</h3><p>Now I know, it seems you’re not online like an SSH connection would tell you by changing the prompt and all. The way to test it’s actually working is to call any cmdlet into the prompt to test it out.</p><p>Here’s a simple cmdlet that will list all mailboxes configured in your Microsoft Exchange 365 Server:</p><pre>Get-Mailbox</pre><h3>The PowerShell Script</h3><p>Once we’re connected to our remote server, the basic idea is to list every member for a given Unified 365 Group, loop through them and give them FullAccess access rights to the chosen mailbox in the process.</p><p>Start by creating a new PS1 file in your prefered text editor (I use Notepad++) and name the file something that speaks to you like addgrouptomailbox.ps1 and read on.</p><h3>Asking for parameters</h3><pre>$groupname = Read-Host -Prompt &#39;Group to add?&#39; $mailboxname = Read-Host -Prompt &#39;Mailbox to target?&#39;</pre><h3>Retreiving the Unified Group members</h3><pre>$members = Get-UnifiedGroupLinks -Identity $groupname -LinkType Members</pre><h3>Adding Mailbox Permissions</h3><pre>foreach ($member in $members){ Add-MailboxPermission -Identity $mailboxname -User $member.Name - AccessRights FullAccess -InheritanceType All }</pre><h3>Getting it all together</h3><p>That’s it! Now just to make your life simpler by giving to you to copy paste all at once, here it is:</p><pre>$groupname = Read-Host -Prompt &#39;Group to add?&#39; $mailboxname = Read-Host -Prompt &#39;Mailbox to target?&#39; $members = Get-UnifiedGroupLinks -Identity $groupname -LinkType Members foreach ($member in $members){ Add-MailboxPermission -Identity $mailboxname -User $member.Name - AccessRights FullAccess -InheritanceType All }</pre><p>To run it, simply move to the destination folder you saved the file and run it as many times as needed!</p><p>Once done, you will want to log out to make sure you don’t use up all allowed sessions and lock yourself out!</p><pre>Remove-PSSession $Session</pre><h3>Final Toughts</h3><p>Simple things are often the best ones. This script might not be perfect but might save you some time like it did for me! Feel free to upgrade it to whatever your needs are as every applications are different.</p><p>All in all, the old adage that says that a Microsoft Exchange server without the use of <strong>PowerShell</strong> is useless still applies even now with the newer Exchange 365 service provided by the Microsoft Office 365 Suite.</p><p><em>Originally published at </em><a href="https://pycvala.de/blog/code/power-shell-adding-office-365-group-members-to-an-exchange-shared-mailbox/"><em>pycvala.de</em></a><em> on January 18, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=271bb7d36d76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google Analytics: From analytics.js to gtag.js]]></title>
            <link>https://medium.com/@pycvalade/google-analytics-from-analytics-js-to-gtag-js-899f37d9a955?source=rss-a90715a517df------2</link>
            <guid isPermaLink="false">https://medium.com/p/899f37d9a955</guid>
            <category><![CDATA[google-analytics]]></category>
            <category><![CDATA[google-tag-manager]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[tracking]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Pier-Yves C Valade]]></dc:creator>
            <pubDate>Sat, 30 Dec 2017 20:21:43 GMT</pubDate>
            <atom:updated>2018-11-28T01:07:40.094Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*4pcbcm6kHm11CynhjOpeDQ.jpeg" /></figure><p>A few months ago, Google released a new Javascript library, named gtag.js to replace it’s already 7 years old analytics.js. It claims to bring in simpler deployment for website owners and better Google Products integration (such as Google Adwords Tracking). Let’s have a look into the key differences and what are your options regarding migration.</p><p><strong>TL;DR</strong><br> Great new library, awesome new features. But, honestly, why not just switch to Google Tag Manager already?</p><h3>analytics.js VS gtag.js</h3><p>Let’s say you implemented the default <strong>Google Analytics code snippet</strong> on your website a while ago. It should look something like this somewhere at the top of any webpage on your website:</p><pre>&lt;!-- Google Analytics --&gt; &lt;script&gt; (function(i,s,o,g,r,a,m){i[&#39;GoogleAnalyticsObject&#39;]=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,&#39;script&#39;,&#39;https://www.google-analytics.com/analytics.js&#39;,&#39;ga&#39;); ga(&#39;create&#39;, &#39;UA-12345678-1&#39;, &#39;auto&#39;); ga(&#39;send&#39;, &#39;pageview&#39;); &lt;/script&gt; &lt;!-- End Google Analytics --&gt;</pre><p>Now, if we look at <strong>the new gtag.js code snippet</strong> we’ve just been introduced, it looks more like this:</p><pre>&lt;!-- Global Site Tag (gtag.js) - Google Analytics --&gt; &lt;script async src=&quot;https://www.googletagmanager.com/gtag/js?id=UA-12345678-1&quot;&gt;&lt;/script&gt; &lt;script&gt; window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag(&#39;js&#39;, new Date()); gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;); &lt;/script&gt;</pre><p>What kind of black magic is this? Looks like someone’s been cleaning up their code!</p><h3>An In-depth Look At The gtag.js Snippet</h3><p>Now that we have a new tag to replace our old, dusty Google Analytics snippet, let’s talk about their key differences.</p><h3>The gtag.js’ Source Script</h3><p>Looking carefully at <strong>the new Google Analytics code snippet</strong>, you’ll find out the first thing that changes is the domain from which the initial Javascript file is imported. It comes from <a href="https://www.googletagmanager.com/">googletagmanager.com</a> instead of <a href="https://www.google-analytics.com/">google-analytics.com</a>.</p><pre>&lt;script async src=&quot;https://www.googletagmanager.com/gtag/js?id=UA-12345678-1&quot;&gt;&lt;/script&gt;</pre><p>As some of you may know, the Google Tag Manager (GTM) is an easy to use yet extremely powerful tag management system provided by Google. Even though the tool was and still is a major breakthrough in Website Tracking Management, Google’s launch of the product was a quiet one so to speak.</p><h3>The dataLayer Variable</h3><p>For those of you familiar with the Google Tag Manager, the dataLayer variable might sound like good news. That’s mainly because that javascript object is what probably makes the Google Tag Manager such a powerful tool.</p><pre>window.dataLayer = window.dataLayer || [];</pre><p>Using that dataLayer object one can actually transmit data from the website directly to the Google Tag Manager and perform numerous tasks within the GTM itself such as triggering custom events, pushing custom data to third party software and so much more.</p><p>It seems like the new Google Analytics library just uses the same, which seems a bit risky if you have an hybrid setup already using the GTM’s default object.</p><h3>Sending a PageView to Google Analytics</h3><p>Previously, one would’ve needed 2 actions: defining the domain and Google Analytics Property ID, then sending the pageview event per se.</p><pre>ga(&#39;create&#39;, &#39;UA-12345678-1&#39;, &#39;auto&#39;); ga(&#39;send&#39;, &#39;pageview&#39;);</pre><p>Now, all gtag.js requires is to add the GA Property ID as a config statement and the pageview gets sent by default.</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;);</pre><p>And… that’s it!</p><h3>Custom Pageview Attributes</h3><p>A great feature of the gtag.js library is the support for <a href="https://developers.google.com/analytics/devguides/collection/gtagjs/pages">custom pageview attributes</a>. These enable a more advanced and/or cleaner tracking setup where the default settings aren’t enough.</p><p>Here are the 3 settings that could be set when calling the “config” event:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;, { &#39;page_title&#39;: &#39;some custom page title&#39;, &#39;page_location&#39;: &#39;http://foo.com/your-custom/location&#39;, &#39;page_path&#39;: &#39;/your-custom/location&#39; });</pre><p>One typical usage example of this would be to merge all pageviews for a specific content into one single permalink for that particular page, <strong>helping with duplicate content and cleaner reports</strong>.</p><p>2 URLs for this same content:</p><ul><li><a href="https://pycvala.de/?p=30">https://pycvala.de/?p=30</a></li><li><a href="https://pycvala.de/blog/analytics/google-analytics-from-analytics-js-to-gtag-js">https://pycvala.de/blog/analytics/google-analytics-from-analytics-js-to-gtag-js</a></li></ul><p>1 clean pageview in Google Analytics:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;, { &#39;page_title&#39;: &#39;Google Analytics: From analytics.js to gtag.js&#39;, &#39;page_location&#39;: &#39;https://pycvala.de/blog/analytics/google-analytics-from-analytics-js-to-gtag-js&#39;, &#39;page_path&#39;: &#39;/blog/analytics/google-analytics-from-analytics-js-to-gtag-js&#39; });</pre><h3>Multi-Property gtag.js Support</h3><p>One of the big features of <strong>the new Google Analytics library</strong> is the multiple Google Analytics property support. That enables you to push events to simultaneous GA properties at onces, without having to duplicate tags and lose hair doing so. Let’s see how it works.</p><p>Previously, we pushed a config parameter with our property UA ID as parameter. Let’s add another one, this time without sending a pageview event to prevent data corruption.</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;); gtag(&#39;config&#39;, &#39;UA-98765432-1&#39;, {&#39;send_page_view&#39;: false});</pre><p>Now any data or event that will be sent to our first property will be sent to the second one. Good thing is you can add as many as you’d like!</p><h3>Google Analytics Property Grouping</h3><p>One of the new key features added to the gtag.js library is Google Analytics Property Grouping through parameters. By default, all properties are added to the default group named “default”.</p><p>Hence, doing this:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;);</pre><p>Is basically the same as doing this:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;, {&#39;groups&#39;: &#39;default&#39;});</pre><p>Let’s say you have 3 properties, one being the main one and 2 others being other websites related to affiliates to which you would like to send specific data all at once. You could define a second “affiliate” group and put them all in like so:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;, {&#39;groups&#39;: &#39;default&#39;}); gtag(&#39;config&#39;, &#39;UA-12332112-1&#39;, {&#39;send_page_view&#39;: false, &#39;groups&#39;: &#39;affiliate&#39;}); gtag(&#39;config&#39;, &#39;UA-98798778-1&#39;, {&#39;send_page_view&#39;: false, &#39;groups&#39;: &#39;affiliate&#39;});</pre><h3>Sending Google Analytics Events With gtag.js</h3><p>Every event sent to Google Analytics has been accepting 4 parameters for almost a decade:</p><ul><li>An Event Category, here “Button”</li><li>An Event Action, here “Click”</li><li>An Event Label, here “Homepage Slider Button”</li><li>An Event Value, here the number 5</li></ul><p>With analytics.js, we were used to the ga() method:</p><pre>ga(&#39;send&#39;, &#39;event&#39;, &#39;Button&#39;, &#39;Click&#39;, &#39;Homepage Slider Button&#39;, 5);</pre><p>The new gtag.js library actually gets <strong>improved and simpler event sending capabilities</strong>, thanks to its new dataLayer-like support. You can now send custom events just like in Google Tag Manager with it’s simplest usage:</p><pre>gtag(&#39;event&#39;, &#39;event_name&#39;);</pre><p>Like the pageview, the gtag event supports custom, non mandatory parameters. Here’s the same event as the previous example to show all main properties applied to the new library.</p><pre>gtag(<br>&#39;event&#39;, &#39;Click&#39;, <br>{ <br>&#39;event_category&#39;: &#39;Button&#39;, // good ol&#39; event category <br>&#39;event_action&#39;: &#39;Click&#39; //defaults to the &quot;event_name&quot; (here &quot;Click&quot;) if not set <br>&#39;event_label&#39;: &#39;Homepage Slider Button&#39;, &#39;value&#39;: 5 <br>}<br>);</pre><p>The extensive list of suggested and other embedded event names one could use and much more can be found in the <a href="https://developers.google.com/analytics/devguides/collection/gtagjs/events">Event tracking with gtag.js</a> section of Google’s documentation.</p><h3>Persistent Parameter Value Support</h3><p>The new gtag.js library has persistent parameter value support. Yes, you read that right: e-Commerce tracking setup just got way easier.</p><p>Let’s say you have your usual Google Analytics pixel on your e-commerce. What if you had multiple currency support and multiple country support on your website? Until now, you would’ve set the currency in your Google Analytics property, created many views and called it quits. You would’ve been stuck with whatever those settings where. But now you don’t!</p><p>Your user lands on your main US based, USD e-commerce:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;, {&#39;currency&#39;: &#39;USD&#39;, &#39;country&#39;: &#39;US&#39;});</pre><p>But he switches to the Canadian, CAD store to have prices in his preffered currency and shipping calculated right. On page load, all you have to do, without changing all your event scripts or creating a new view in Google Analytics:</p><pre>gtag(&#39;config&#39;, &#39;UA-12345678-1&#39;, {&#39;currency&#39;: &#39;CAD&#39;, &#39;country&#39;: &#39;CA&#39;});</pre><p>Now all your event values are now seen as CAD and from Canada.</p><p>If you did setup many properties on page load and have some javascript switcher, you can use the “set” method to change all values at once to CAD/CA or any other parameter:</p><pre>gtag(&#39;set&#39;, {&#39;country&#39;: &#39;CA&#39;, &#39;currency&#39;: &#39;CAD&#39;});</pre><h3>Sending events to specific properties</h3><p>Earlier, we’ve been setting groups for our affiliates, remember? Now it’s time to put it to the test by sending them both an event I used earlier, using the “send_to” parameter using either a group name, a property ID or both in an array.</p><p>Using a group name:</p><pre>gtag(&#39;event&#39;, &#39;Click&#39;, { &#39;send_to&#39;: &#39;affiliates&#39;, &#39;event_category&#39;: &#39;CTA&#39;, &#39;event_action&#39;: &#39;Click&#39;, &#39;event_label&#39;: &#39;Homepage Slider Button&#39;, &#39;value&#39;: 5 });</pre><p>Using a property ID:</p><pre>gtag(&#39;event&#39;, &#39;Click&#39;, { &#39;send_to&#39;: &#39;UA-12332112-1&#39;, &#39;event_category&#39;: &#39;CTA&#39;, &#39;event_action&#39;: &#39;Click&#39;, &#39;event_label&#39;: &#39;Homepage Slider Button&#39;, &#39;value&#39;: 5 });</pre><p>Using both:</p><pre>gtag(&#39;event&#39;, &#39;Click&#39;, { &#39;send_to&#39;: [&#39;UA-12345678-1&#39;, &#39;affiliates&#39;], &#39;event_category&#39;: &#39;CTA&#39;, &#39;event_action&#39;: &#39;Click&#39;, &#39;event_label&#39;: &#39;Homepage Slider Button&#39;, &#39;value&#39;: 5 });</pre><p>Take note you can put as many property IDs or group names in that array, mixed or not.</p><h3>Pushing It Further</h3><p>The <strong>new gtag.js library for Google Analytics</strong> is good. It bridges a gap between the Google Tag Manager that I love with the simpler, more classic tracking setups. It just gets more done, faster.</p><p><strong>But, honestly, why not just switch to Google Tag Manager already?</strong></p><p>If you would like to know more in-depth or advanced settings and implementations of the gtag.js library, feel free to suggest it in the comments or have a look at the full and extensive <a href="https://developers.google.com/analytics/devguides/collection/gtagjs/">gtag.js documentation</a> by Google.</p><p><em>Originally published at </em><a href="https://pycvala.de/blog/analytics/google-analytics-from-analytics-js-to-gtag-js/"><em>pycvala.de</em></a><em> on December 30, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=899f37d9a955" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>