← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/async-ga into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/async-ga into lp:launchpad.

Commit message:
Load Google Analytics asynchronously.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #997600 in Launchpad itself: "make google analytics served via async"
  https://bugs.launchpad.net/launchpad/+bug/997600

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/async-ga/+merge/261131

Load Google Analytics asynchronously.  This matches Google's current recommendations: https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/async-ga into lp:launchpad.
=== modified file 'configs/development/launchpad-lazr.conf'
--- configs/development/launchpad-lazr.conf	2015-02-19 17:33:35 +0000
+++ configs/development/launchpad-lazr.conf	2015-06-04 19:01:23 +0000
@@ -108,6 +108,7 @@
 geoip_database: /usr/share/GeoIP/GeoLiteCity.dat
 geonames_identity: lpdev
 feature_flags_endpoint: http://xmlrpc-private.launchpad.dev:8087/featureflags/
+is_lpnet: True
 
 [launchpad_session]
 cookie: launchpad_dev

=== modified file 'lib/lp/app/templates/base-layout.pt'
--- lib/lp/app/templates/base-layout.pt	2014-11-28 05:40:54 +0000
+++ lib/lp/app/templates/base-layout.pt	2015-06-04 19:01:23 +0000
@@ -55,6 +55,26 @@
     <tal:view condition="not: view/macro:is-page-contentless">
       <metal:block define-slot="head_epilogue"></metal:block>
     </tal:view>
+
+    <tal:ga condition="python: is_lpnet">
+      <tal:script
+          replace="structure string:&lt;script type='text/javascript'&gt;" />
+        var _gaq = _gaq || [];
+        _gaq.push(['_setAccount', 'UA-12833497-1']);
+        _gaq.push(['_setDomainName', '.launchpad.net']);
+        _gaq.push(['_setAllowHash', false]);
+        _gaq.push(['_trackPageview']);
+
+        (function() {
+          var ga = document.createElement('script');
+          ga.type = 'text/javascript';
+          ga.async = true;
+          ga.src = '<tal:ga-js replace="string:${icingroot}/google-analytics/ga.js" />';
+          var s = document.getElementsByTagName('script')[0];
+          s.parentNode.insertBefore(ga, s);
+        })();
+      <tal:script replace="structure string:&lt;/script&gt;" />
+    </tal:ga>
   </head>
 
   <body id="document"
@@ -74,17 +94,6 @@
                 <noscript><strong>The information on this page is private.</strong></noscript>
             </div>
           </tal:private-banner>
-        <script type="text/javascript"
-          tal:condition="python: is_lpnet">
-          var _gaq = _gaq || [];
-          _gaq.push(['_setAccount', 'UA-12833497-1']);
-          _gaq.push(['_setDomainName', '.launchpad.net']);
-          _gaq.push(['_setAllowHash', false]);
-          _gaq.push(['_trackPageview']);
-        </script>
-        <script type="text/javascript"
-            tal:condition="python: is_lpnet"
-            tal:attributes="src string:${icingroot}/google-analytics/ga.js"></script>
     <div class="yui-d0">
       <div id="locationbar" class="login-logout">
         <tal:login replace="structure context/@@login_status" />


Follow ups