<?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: Adrian Kirsten</title>
    <description>The latest articles on DEV Community by Adrian Kirsten (@traaidmark).</description>
    <link>https://dev.to/traaidmark</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%2F2379%2F1195935.jpeg</url>
      <title>DEV Community: Adrian Kirsten</title>
      <link>https://dev.to/traaidmark</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/traaidmark"/>
    <language>en</language>
    <item>
      <title>What is your most versatile do-anything bit of code?</title>
      <dc:creator>Adrian Kirsten</dc:creator>
      <pubDate>Mon, 19 Jun 2017 12:47:55 +0000</pubDate>
      <link>https://dev.to/traaidmark/what-is-your-most-versatile-do-anything-bit-of-code</link>
      <guid>https://dev.to/traaidmark/what-is-your-most-versatile-do-anything-bit-of-code</guid>
      <description>&lt;p&gt;That bit of code that you almost depend upon to save your ass in just about any situation, and carry with you in your developer's toolbox. &lt;/p&gt;




&lt;h3&gt;
  
  
  Let me begin
&lt;/h3&gt;

&lt;p&gt;This piece of code has travelled with me for at least the last 4 years. It's changed a bit here and there, but the overall structure &amp;amp; purpose has remained the same throughout.&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;jQuery&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;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.c-reveal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;click&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;target&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&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;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;href&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&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;c-toggle&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c-inactive&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;hasClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c-inactive&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;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c-inactive&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;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;removeClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;c-inactive&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;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most simple use case for demonstration would be to simply show and hide a div. Let's look at the HTML below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#my-div-name"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"c-reveal"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Show / hide this div&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my-div-name"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"c-inactive"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    This is mind-blowing div contents
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In css I have several helper classes, one of which is &lt;code&gt;.c-inactive {}&lt;/code&gt; which basically removes the attached element off screen. Add to this some transitions and you have a pretty robust thing.&lt;/p&gt;

&lt;p&gt;That simple bit of Jquery can power pretty much anything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Show / hide divs&lt;/li&gt;
&lt;li&gt;Modal windows&lt;/li&gt;
&lt;li&gt;Accordion types&lt;/li&gt;
&lt;li&gt;Etc&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Tracking Events with Google Analytics</title>
      <dc:creator>Adrian Kirsten</dc:creator>
      <pubDate>Tue, 13 Jun 2017 11:50:08 +0000</pubDate>
      <link>https://dev.to/traaidmark/tracking-events-with-google-analytics</link>
      <guid>https://dev.to/traaidmark/tracking-events-with-google-analytics</guid>
      <description>

&lt;p&gt;&lt;em&gt;Please note: This article was written way back in 2015-07-14 on my own blog. I am moving relevant (interesting) articles over here. I made a few edits now.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Google Analytics can do some pretty awesome stuff, it's a near standard addition to any site. We use it to see how many (or little) people visit our site, from where they come and to where they go. Today's little experiment is all about tracking specific links within a website in a friendly and front-end happy way. &lt;/p&gt;

&lt;p&gt;Turns out the Google Analytics API is quite powerful, and you can do a lot with it. When I designed this website I added a whole bunch of Call to Action type of links, and I figured it would be great to see just how valuable they would be to my end strategy. The simplest way for me to do that would be to treat the links as goals, and to track them specifically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's build a reusable event tracker!
&lt;/h2&gt;

&lt;p&gt;The plan is to create the google event tracker in such a way that it's easy to implement within your site, and can be reused as often as we need it to.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Function
&lt;/h3&gt;

&lt;p&gt;The tracker itself is by no means bulky code, but it's a hassle to rewrite everytime, especially if we can whittle it down to a single line call.&lt;/p&gt;

&lt;p&gt;It really is as basic an example as it get's, but it's very useful and can provide a lot of value to your site.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.ga-tracker'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'click'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

  &lt;span class="c1"&gt;// I want to know on what page the event fired, as my links are on many pages.&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;LOCATION&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;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;href&lt;/span&gt;

  &lt;span class="c1"&gt;// The category of the event. On my site I have two - general tracker and social trackers.&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;CATEGORY&lt;/span&gt; &lt;span class="o"&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;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'category'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// The action that takes place. Example: On my social tracker I made it 'share'.&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ACTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Click'&lt;/span&gt;

  &lt;span class="c1"&gt;// The label. I add the label we pass in track(); function and add the location.&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;LABEL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;LOCATION&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;' &amp;gt; '&lt;/span&gt; &lt;span class="o"&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;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'label'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Send data to Google Analytics&lt;/span&gt;
  &lt;span class="nx"&gt;ga&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'send'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'event'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CATEGORY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ACTION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;LABEL&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;h3&gt;
  
  
  Implementing this into your HTML
&lt;/h3&gt;

&lt;p&gt;The event tracker above is a very basic one, and simply tracks specific links. Therefore our implementation is equally simple. We simply attach the class we named in the tracker we made in section 'B' of the above gist to the link we want to track:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"ga-tracker"&lt;/span&gt; &lt;span class="na"&gt;data-category=&lt;/span&gt;&lt;span class="s"&gt;"General"&lt;/span&gt; &lt;span class="na"&gt;data-label=&lt;/span&gt;&lt;span class="s"&gt;"Link #1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is my tracked link&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That really is it. If you click the link a few times you will see the results in Google Analytics under:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reporting&lt;/strong&gt; &amp;gt; Behaviour &amp;gt; Events&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where to go from here
&lt;/h2&gt;

&lt;p&gt;This is a tiny little function that does a tiny bit work. It's basic. So what can we do with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The actual data&lt;/li&gt;
&lt;li&gt;Get more useful data&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Working with the data
&lt;/h3&gt;

&lt;p&gt;The first thing I noticed was that the event data is cool, but not very friendly and quite hidden. I created a custom dashboard, and that was cool, but not really all that exciting to me. It didn't tell me all that much.&lt;/p&gt;

&lt;p&gt;So I set up Goals, which basically turns those events into conversions, which is really what you want to do. Now you can look at the events being fired as people doing what you want them to do. If that number is high, then good stuff! If it's low against your page views and unique visits, then you have a great opportunity to go figure out what you are doing wrong!&lt;/p&gt;

&lt;p&gt;That is SO beyond the scope of this article though, so let's get back to code speak.&lt;/p&gt;

&lt;h3&gt;
  
  
  Get more useful data
&lt;/h3&gt;

&lt;p&gt;My example tracks links. Simple as that. But there are so many other things people do on websites that we can track. Imagine the possibilities of knowing when people scroll?&lt;/p&gt;

&lt;p&gt;In terms of UX Design we can track how valuable that fancy carousel feature really is.&lt;/p&gt;

&lt;p&gt;There is so much we can do, so I guess a little bit of experimentation is called for. Stay tuned!&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing
&lt;/h2&gt;

&lt;p&gt;Since Google Analytics are generally delayed a bit with their reporting, testing can be a bit of a pain in the ass. There is a &lt;a href="https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna"&gt;Chrome Extention&lt;/a&gt; that you can use to check (if you don't mind sifting through console messages). If you do use it you can look for something like this:&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;Running &lt;span class="nb"&gt;command&lt;/span&gt;: ga&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"send"&lt;/span&gt;, &lt;span class="s2"&gt;"event"&lt;/span&gt;, &lt;span class="s2"&gt;"Social"&lt;/span&gt;, &lt;span class="s2"&gt;"Share"&lt;/span&gt;, &lt;span class="s2"&gt;"Facebook : http://localhost:4000/blog/code/track-events-with-google-analytics/"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The simplest way to test is to simply use Google Analytics live view. It's somewhat dodgey, but does work fairly well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/events"&gt;Event Tracking - Web Tracking (analytics.js)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


</description>
      <category>jquery</category>
      <category>googleanalytics</category>
    </item>
  </channel>
</rss>
