Skip to content

Instantly share code, notes, and snippets.

@nateberkopec
Forked from tomfuertes/0.result.md
Last active January 18, 2024 11:20
Show Gist options
  • Select an option

  • Save nateberkopec/a43f3e29d9583df33406 to your computer and use it in GitHub Desktop.

Select an option

Save nateberkopec/a43f3e29d9583df33406 to your computer and use it in GitHub Desktop.

Revisions

  1. nateberkopec revised this gist Nov 5, 2015. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions 0.result.md
    Original file line number Diff line number Diff line change
    @@ -5,9 +5,8 @@ This gist applies the theory from Ilya Grigorik's [Script-injected "async script
    ```html
    <!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
    <script>
    (function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga");
    ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    !function(n,t){n.GoogleAnalyticsObject=t,n[t]=n[t]||function(){(n[t].q=n[t].q||[]).push(arguments)},n[t].l=1*new Date}(window,"ga");
    ga('create', 'UA-XXXX-Y', 'auto'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    ga('send', 'pageview');
    </script>
    <!-- End Google Analytics Part 2 -->
  2. @tomfuertes tomfuertes revised this gist Jun 8, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 0.result.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # De-'Async Inject' Universal Analytics

    This gist applies the theory from Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) on the default Universal Analytics snippet. TLDR place this above the CSS in the `&lt;head&gt;` of your document
    This gist applies the theory from Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) on the default Universal Analytics snippet. TLDR place this above the CSS in the `<head>` of your document

    ```html
    <!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
    @@ -13,7 +13,7 @@ This gist applies the theory from Ilya Grigorik's [Script-injected "async script
    <!-- End Google Analytics Part 2 -->
    ```

    And then place this below your CSS in the `&lt;head&gt;`:
    And then place this below your CSS in the `<head>`:

    ```html
    <!-- Google Analytics Part 2: load analytics.js-->
  3. @tomfuertes tomfuertes revised this gist Jun 8, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 0.result.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # De-'Async Inject' Universal Analytics

    This gist applies the theory from Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) on the default Universal Analytics snippet. TLDR place this above the CSS in the <head> of your document
    This gist applies the theory from Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) on the default Universal Analytics snippet. TLDR place this above the CSS in the `&lt;head&gt;` of your document

    ```html
    <!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
    @@ -13,7 +13,7 @@ This gist applies the theory from Ilya Grigorik's [Script-injected "async script
    <!-- End Google Analytics Part 2 -->
    ```

    And then place this below your CSS in the <head>:
    And then place this below your CSS in the `&lt;head&gt;`:

    ```html
    <!-- Google Analytics Part 2: load analytics.js-->
  4. @tomfuertes tomfuertes revised this gist Jun 8, 2014. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions 0.result.md
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,24 @@
    # De-'Async Inject' Universal Analytics

    By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/). This post walks through a synthesis of that information on the default Universal Analytics snippet:
    This gist applies the theory from Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) on the default Universal Analytics snippet. TLDR place this above the CSS in the <head> of your document

    ```html
    <!-- Google Analytics -->
    <!-- Google Analytics Part 1: Creates window.ga, sets account, and queues pageview-->
    <script>
    (function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga");
    ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    ga('send', 'pageview');
    </script>
    <!-- End Google Analytics Part 2 -->
    ```

    And then place this below your CSS in the <head>:

    ```html
    <!-- Google Analytics Part 2: load analytics.js-->
    <script async src='//www.google-analytics.com/analytics.js'></script>
    <!-- End Google Analytics -->
    <!-- End Google Analytics Part 2 -->
    ```

    * [1.default.html](#file-1-default-html) - Pulled from [Introduction to Analytics.js / Tracking Code Quick Start](https://developers.google.com/analytics/devguides/collection/analyticsjs/)
  5. @tomfuertes tomfuertes revised this gist Jun 8, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 0.result.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injecte
    <!-- Google Analytics -->
    <script>
    (function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga")
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga");
    ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    ga('send', 'pageview');
    </script>
  6. @tomfuertes tomfuertes revised this gist Jun 8, 2014. 2 changed files with 6 additions and 16 deletions.
    9 changes: 0 additions & 9 deletions 0.result.html
    Original file line number Diff line number Diff line change
    @@ -1,9 +0,0 @@
    <!-- Google Analytics -->
    <script>
    (function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga")
    ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    ga('send', 'pageview');
    </script>
    <script async src='//www.google-analytics.com/analytics.js'></script>
    <!-- End Google Analytics -->
    13 changes: 6 additions & 7 deletions 0.result.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,6 @@
    # De-'Async Inject' Universal Analytics

    By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/). This post walks through a synthesis of that information on the default Universal Analytics snippet.

    * [0.result.html](#file-0-result-html) - End Result
    * [1.default.html](#file-1-default-html) - Pulled from [Introduction to Analytics.js / Tracking Code Quick Start](https://developers.google.com/analytics/devguides/collection/analyticsjs/)
    * [2.jsniced.html](#file-2-jsniced-html) - Pulled from [Optimizing the Google Analytics Snippet](http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics)
    * [3.refactored.html](#file-3-refactored-html) - Removes async injected parts + dead variables.
    By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/). This post walks through a synthesis of that information on the default Universal Analytics snippet:

    ```html
    <!-- Google Analytics -->
    @@ -17,4 +12,8 @@ By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injecte
    </script>
    <script async src='//www.google-analytics.com/analytics.js'></script>
    <!-- End Google Analytics -->
    ```
    ```

    * [1.default.html](#file-1-default-html) - Pulled from [Introduction to Analytics.js / Tracking Code Quick Start](https://developers.google.com/analytics/devguides/collection/analyticsjs/)
    * [2.jsniced.html](#file-2-jsniced-html) - Pulled from [Optimizing the Google Analytics Snippet](http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics)
    * [3.refactored.html](#file-3-refactored-html) - Removes async injected parts + dead variables.
  7. @tomfuertes tomfuertes renamed this gist Jun 8, 2014. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion 00.README.md → 0.result.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,16 @@ By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injecte
    * [0.result.html](#file-0-result-html) - End Result
    * [1.default.html](#file-1-default-html) - Pulled from [Introduction to Analytics.js / Tracking Code Quick Start](https://developers.google.com/analytics/devguides/collection/analyticsjs/)
    * [2.jsniced.html](#file-2-jsniced-html) - Pulled from [Optimizing the Google Analytics Snippet](http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics)
    * [3.refactored.html](#file-3-refactored-html) - Removes async injected parts + dead variables.
    * [3.refactored.html](#file-3-refactored-html) - Removes async injected parts + dead variables.

    ```html
    <!-- Google Analytics -->
    <script>
    (function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga")
    ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    ga('send', 'pageview');
    </script>
    <script async src='//www.google-analytics.com/analytics.js'></script>
    <!-- End Google Analytics -->
    ```
  8. @tomfuertes tomfuertes revised this gist Jun 8, 2014. 2 changed files with 12 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions 0.result.html
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,8 @@
    <!-- Google Analytics -->
    <script>(function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga")
    ga('create', 'UA-XXXX-Y');
    <script>
    (function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga")
    ga('create', 'UA-XXXX-Y'); // REPLACE UA-XXXX-Y w/ YOUR ACCOUNT
    ga('send', 'pageview');
    </script>
    <script async src='//www.google-analytics.com/analytics.js'></script>
    8 changes: 8 additions & 0 deletions 00.README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    # De-'Async Inject' Universal Analytics

    By now I'm sure we've all read and thought about Ilya Grigorik's [Script-injected "async scripts" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/). This post walks through a synthesis of that information on the default Universal Analytics snippet.

    * [0.result.html](#file-0-result-html) - End Result
    * [1.default.html](#file-1-default-html) - Pulled from [Introduction to Analytics.js / Tracking Code Quick Start](https://developers.google.com/analytics/devguides/collection/analyticsjs/)
    * [2.jsniced.html](#file-2-jsniced-html) - Pulled from [Optimizing the Google Analytics Snippet](http://mathiasbynens.be/notes/async-analytics-snippet#universal-analytics)
    * [3.refactored.html](#file-3-refactored-html) - Removes async injected parts + dead variables.
  9. @tomfuertes tomfuertes renamed this gist Jun 8, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. @tomfuertes tomfuertes created this gist Jun 8, 2014.
    8 changes: 8 additions & 0 deletions 0.result.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <!-- Google Analytics -->
    <script>(function(e,t){e.GoogleAnalyticsObject=t;e[t]=e[t]||function(){
    (e[t].q=e[t].q||[]).push(arguments)};e[t].l=1*new Date})(t,"ga")
    ga('create', 'UA-XXXX-Y');
    ga('send', 'pageview');
    </script>
    <script async src='//www.google-analytics.com/analytics.js'></script>
    <!-- End Google Analytics -->
    11 changes: 11 additions & 0 deletions 1.default.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    <!-- Google Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=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,'script','//www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-XXXX-Y', 'auto');
    ga('send', 'pageview');
    </script>
    <!-- End Google Analytics -->
    19 changes: 19 additions & 0 deletions 2.jsniced.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <!-- Google Analytics -->
    <script>
    (function(window, document, strScript, url, variableName, scriptElement, firstScript) {
    window['GoogleAnalyticsObject'] = variableName;
    window[variableName] = window[variableName] || function() {
    (window[variableName].q = window[variableName].q || []).push(arguments);
    };
    window[variableName].l = 1 * new Date();
    scriptElement = document.createElement(strScript),
    firstScript = document.getElementsByTagName(strScript)[0];
    scriptElement.async = 1;
    scriptElement.src = url;
    firstScript.parentNode.insertBefore(scriptElement, firstScript)
    })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

    ga('create', 'UA-XXXX-Y');
    ga('send', 'pageview');
    </script>
    <!-- End Google Analytics -->
    15 changes: 15 additions & 0 deletions 3.refractored.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <!-- Google Analytics -->
    <script>
    (function(window, variableName) {
    window.GoogleAnalyticsObject = variableName;
    window[variableName] = window[variableName] || function() {
    (window[variableName].q = window[variableName].q || []).push(arguments);
    };
    window[variableName].l = 1 * new Date();
    })(window, 'ga');

    ga('create', 'UA-XXXX-Y');
    ga('send', 'pageview');
    </script>
    <script async src='//www.google-analytics.com/analytics.js'></script>
    <!-- End Google Analytics -->