{"id":10288599,"date":"2018-05-16T23:15:43","date_gmt":"2018-05-16T23:15:43","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/script-blocking-explained\/"},"modified":"2018-05-17T02:45:45","modified_gmt":"2018-05-17T02:45:45","slug":"script-blocking-explained","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/script-blocking-explained\/","title":{"rendered":"Script Blocking &#8211; Explained"},"content":{"rendered":"<p>First of all, let me say I am in no way affiliated with this plugin other than that I&#8217;m using it and the below might not be accurate in every scenario. It&#8217;s simply a report of what seems to be the case from what I can ascertain in my particular setup.<\/p>\n<p>I did however try to make sense of the description under the script blocking section and searched high and low regarding how to &#8211; in my case &#8211; deal with a google analytics implementation.<br \/>\nSo the below only refers to that , but I would assume it&#8217;s applicable to all sorts of things.<\/p>\n<p>In short: the description (as it stands in the current version of the plugin anyway) says: &#8220;Enter non functional cookies Javascript code here&#8230;etc&#8221;<\/p>\n<p>That&#8217;s somewhat misleading from what I can make out and to me seems to be something that&#8217;s got &#8220;lost in translation&#8221; so to speak (why would I possibly want to put non functional code anywhere ?!)<\/p>\n<p>I think a better description would be (something like):<br \/>\n&#8220;Put your javascript code here you want to be executed when &#8216;third party non functional cookies&#8217; have been accepted&#8221;<\/p>\n<p>Because what seems to happen is the code you can put in that textarea will only get added to the\/a page if  a user accepted those 3rd party cookies (Note: I have not tested what happens when using caching plugins as that might well throw some &#8220;spanners in the works&#8221; so to speak)<\/p>\n<p>as a real world example (works for me anyway &#8211; mileage might vary)<\/p>\n<p>I had a google analytics plugin installed on my site which generated more or less the following code on each page (sensitive data removed):<\/p>\n<pre><code>\n&lt;script type=&quot;text\/javascript&quot;&gt;\n\tvar _gaq=_gaq||[];\n_gaq.push([&quot;_setAccount&quot;,&quot;xxxxx&quot;]),_gaq.push([&quot;_setDomainName&quot;,&quot;.xxxxx.com&quot;]),_gaq.push([&quot;_trackPageview&quot;]),function(){var t=document.createElement(&quot;script&quot;);\n\t\t.....some more code ........\n\t\ta.parentNode.insertBefore(t,a)}();\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>what needed to be done was to add that whole code (including  <code>&lt;script .... &lt;\/script&gt;<\/code> ) into the &#8220;Script blocking&#8221; textbox of this cookie plugin and subsequently de-activate the google analytics plugin that i used (as it knows nothing about that cookie consent plugin) so only the code added to that &#8220;Script blocking&#8221; box was being executed and only if consent was given<\/p>\n<p>That&#8217;s all from me on that subject.<br \/>\nmaybe it helps someone as I have come across many (unanswered) questions to that effect when searching for a solution myself&#8230;&#8230;<\/p>\n","protected":false},"template":"","class_list":["post-10288599","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10288599","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10288599\/revisions"}],"predecessor-version":[{"id":10288636,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10288599\/revisions\/10288636"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10288599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}