No Google thing when no Analytics ID present.

This commit is contained in:
James Cole
2015-08-13 17:35:41 +02:00
parent 90cb3279df
commit 4f59b1d32f
3 changed files with 82 additions and 64 deletions

View File

@@ -187,28 +187,34 @@
<script type="text/javascript" src="js/help.js"></script> <script type="text/javascript" src="js/help.js"></script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
{% if env('ANALYTICS_ID','') != '' %}
<script> <script>
(function (i, s, o, g, r, a, m) { // send pageview
i['GoogleAnalyticsObject'] = r; (function (i, s, o, g, r, a, m) {
i[r] = i[r] || function () { i['GoogleAnalyticsObject'] = r;
(i[r].q = i[r].q || []).push(arguments) i[r] = i[r] || function () {
}, i[r].l = 1 * new Date(); (i[r].q = i[r].q || []).push(arguments)
a = s.createElement(o), }, i[r].l = 1 * new Date();
m = s.getElementsByTagName(o)[0]; a = s.createElement(o),
a.async = 1; m = s.getElementsByTagName(o)[0];
a.src = g; a.async = 1;
m.parentNode.insertBefore(a, m) a.src = g;
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); m.parentNode.insertBefore(a, m)
ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100}); })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('send', 'pageview'); ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100});
// send an event if relevant: ga('send', 'pageview');
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and not Session.has('gaEventLabel') %}
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}'); // send an event if relevant:
{% endif %} {% if Session.has('gaEventCategory') and Session.has('gaEventAction') and not Session.has('gaEventLabel') %}
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and Session.has('gaEventLabel') %} ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}');
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}', '{{ Session.get('gaEventLabel') }}'); {% endif %}
{% endif %}
// send event if relevant:
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and Session.has('gaEventLabel') %}
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}', '{{ Session.get('gaEventLabel') }}');
{% endif %}
</script> </script>
{% endif %}
</body> </body>
</html> </html>

View File

@@ -47,27 +47,33 @@
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script> <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script> {% if env('ANALYTICS_ID','') != '' %}
(function (i, s, o, g, r, a, m) { <script>
i['GoogleAnalyticsObject'] = r; // send pageview
i[r] = i[r] || function () { (function (i, s, o, g, r, a, m) {
(i[r].q = i[r].q || []).push(arguments) i['GoogleAnalyticsObject'] = r;
}, i[r].l = 1 * new Date(); i[r] = i[r] || function () {
a = s.createElement(o), (i[r].q = i[r].q || []).push(arguments)
m = s.getElementsByTagName(o)[0]; }, i[r].l = 1 * new Date();
a.async = 1; a = s.createElement(o),
a.src = g; m = s.getElementsByTagName(o)[0];
m.parentNode.insertBefore(a, m) a.async = 1;
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); a.src = g;
ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100}); m.parentNode.insertBefore(a, m)
ga('send', 'pageview'); })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
// send an event if relevant: ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100});
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and not Session.has('gaEventLabel') %} ga('send', 'pageview');
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}');
{% endif %} // send an event if relevant:
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and Session.has('gaEventLabel') %} {% if Session.has('gaEventCategory') and Session.has('gaEventAction') and not Session.has('gaEventLabel') %}
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}', '{{ Session.get('gaEventLabel') }}'); ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}');
{% endif %} {% endif %}
</script>
// send event if relevant:
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and Session.has('gaEventLabel') %}
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}', '{{ Session.get('gaEventLabel') }}');
{% endif %}
</script>
{% endif %}
</body> </body>
</html> </html>

View File

@@ -48,27 +48,33 @@
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script> <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script> <script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script> {% if env('ANALYTICS_ID','') != '' %}
(function (i, s, o, g, r, a, m) { <script>
i['GoogleAnalyticsObject'] = r; // send pageview
i[r] = i[r] || function () { (function (i, s, o, g, r, a, m) {
(i[r].q = i[r].q || []).push(arguments) i['GoogleAnalyticsObject'] = r;
}, i[r].l = 1 * new Date(); i[r] = i[r] || function () {
a = s.createElement(o), (i[r].q = i[r].q || []).push(arguments)
m = s.getElementsByTagName(o)[0]; }, i[r].l = 1 * new Date();
a.async = 1; a = s.createElement(o),
a.src = g; m = s.getElementsByTagName(o)[0];
m.parentNode.insertBefore(a, m) a.async = 1;
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga'); a.src = g;
ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100}); m.parentNode.insertBefore(a, m)
ga('send', 'pageview'); })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
// send an event if relevant: ga('create', '{{ env('ANALYTICS_ID', 'XXX-XX-X') }}', {'siteSpeedSampleRate': 100});
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and not Session.has('gaEventLabel') %} ga('send', 'pageview');
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}');
{% endif %} // send an event if relevant:
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and Session.has('gaEventLabel') %} {% if Session.has('gaEventCategory') and Session.has('gaEventAction') and not Session.has('gaEventLabel') %}
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}', '{{ Session.get('gaEventLabel') }}'); ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}');
{% endif %} {% endif %}
</script>
// send event if relevant:
{% if Session.has('gaEventCategory') and Session.has('gaEventAction') and Session.has('gaEventLabel') %}
ga('send', 'event', '{{Session.get('gaEventCategory')}}', '{{Session.get('gaEventAction')}}', '{{ Session.get('gaEventLabel') }}');
{% endif %}
</script>
{% endif %}
</body> </body>
</html> </html>