<?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: Hannu Hartikainen</title>
    <description>The latest articles on DEV Community by Hannu Hartikainen (@dancek).</description>
    <link>https://dev.to/dancek</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%2F374255%2Fe1e3f472-6aea-4849-b4e6-43a4392cd068.jpeg</url>
      <title>DEV Community: Hannu Hartikainen</title>
      <link>https://dev.to/dancek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dancek"/>
    <language>en</language>
    <item>
      <title>opt-in-script: letting visitors choose</title>
      <dc:creator>Hannu Hartikainen</dc:creator>
      <pubDate>Tue, 19 May 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/dancek/opt-in-script-letting-visitors-choose-1d3l</link>
      <guid>https://dev.to/dancek/opt-in-script-letting-visitors-choose-1d3l</guid>
      <description>&lt;p&gt;I used to have &lt;a href="https://utteranc.es"&gt;utteranc.es&lt;/a&gt; for comments in my blog. I think it's a nice, lightweight, usable system (it's basically Github issues).&lt;/p&gt;

&lt;p&gt;But it's a third party script. I may have read the source and I may trust the maintainers, but some of my visitors might not. So forcing it on everyone feels a bit immoral. And after switching my blog to &lt;a href="https://getzola.org"&gt;Zola&lt;/a&gt; I didn't add &lt;em&gt;any&lt;/em&gt; JS on my blog -- until now.&lt;/p&gt;

&lt;p&gt;I've thought about &lt;em&gt;opt-in analytics&lt;/em&gt; before: I'd like to have analytics on my site, but I don't want to track my visitors without consent or give their data to third parties&lt;sup id="fnref1"&gt;1&lt;/sup&gt;. The solution might be a &lt;em&gt;please track my visit&lt;/em&gt; button. Perhaps not that many people would click, but maybe I'll try it someday.&lt;/p&gt;

&lt;p&gt;The general idea seems more suited for comments, though: maybe you want to read comments or write one, and one click isn't a big annoyance. Meanwhile the visitors that don't care about comments (ie. most, I guess) avoid some unnecessary traffic and content.&lt;/p&gt;

&lt;p&gt;So I wrote &lt;a href="https://github.com/dancek/opt-in-script"&gt;opt-in-script&lt;/a&gt; which takes something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;opt-in-script&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"analytics.js"&lt;/span&gt;
               &lt;span class="na"&gt;some-attr=&lt;/span&gt;&lt;span class="s"&gt;"123-456-7"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&amp;gt;&lt;/span&gt;Enable analytics!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  Note: this will log foo, bar and baz to my server.
&lt;span class="nt"&gt;&amp;lt;/opt-in-script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and only after the button is clicked, turns it into a real &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag that the browser will load and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"analytics.js"&lt;/span&gt; &lt;span class="na"&gt;some-attr=&lt;/span&gt;&lt;span class="s"&gt;"123-456-7"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You may see it in action in &lt;a href="https://hannuhartikainen.fi/blog/opt-in-script/#footer"&gt;my blog post footers&lt;/a&gt;, wrapping the comments section. Check what happens in the browser devtools network tab when you click!&lt;/p&gt;

&lt;p&gt;I'm hoping to see more websites that respect their visitors. Maybe you could consider something similar on your site?&lt;/p&gt;




&lt;ol&gt;

&lt;li id="fn1"&gt;
&lt;p&gt;Note that you should not trust me. I probably will start tracking visitors if I ever see a significant benefit in doing so. Such is human nature. ↩&lt;/p&gt;
&lt;/li&gt;

&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>privacy</category>
    </item>
  </channel>
</rss>
