Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 - Adding in Google Analytics script into Twig

I've been trying to setup Google Analytics and according their website you're supposed to just insert their script into your html page.

I've added this into my base.html.twig file right after the opening tag. This is then extended by the layout.html.twig file which is extended by all other pages.

This isn't showing up as installed from the Google Analytics page. The tag shows in the page source and is being blocked by Ghostery yet it still shows up as Status: Tracking Not Installed.

What am I doing wrong and how do I insert this properly?

According to their instructions - Paste immediately before the </head> tag:

<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', 'XX-XXXXXXXX-X', 'example.com');
ga('send', 'pageview');
</script>

base.html.twig

<head>
<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', 'XX-XXXXXXXX-X', 'example.com');
    ga('send', 'pageview');

</script>

<meta charset="UTF-8"/>
<title>{% block title %}{% endblock %}</title>
{% block stylesheets %}
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}"/>
</head>

layout.html.twig

{% extends '::base.html.twig'%}
like image 560
esteemed.squire Avatar asked Jun 17 '14 06:06

esteemed.squire


1 Answers

It takes up to 72 hours to detect a newly added tracker. The standard reports can take 24 - 48 hours after that to start registering data. The Real-time reports should show data earlier.

The tracking code you posted looks good, you just need to wait a little until Google picks it up.

like image 117
DaImTo Avatar answered Nov 07 '22 07:11

DaImTo