JavaScript tracker code should be added immediately before the closing </head> section · Issue #9341 · matomo-org/matomo · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript tracker code should be added immediately before the closing </head> section #9341

Closed
3 tasks done
mattab opened this issue Dec 6, 2015 · 6 comments
Closed
3 tasks done
Labels
c: Website matomo.org For issues related to our matomo.org website. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Dec 6, 2015

This issue is about improving our documentation: sometimes we recommend to add the tracking code before </body> and sometimes after <body>.

Actually it is recommended to include the tracking code in the <head> section or after the opening <body> tag.

Guides to fix:

@mattab mattab added the c: Website matomo.org For issues related to our matomo.org website. label Dec 6, 2015
@mattab mattab added this to the 2.15.1 milestone Dec 6, 2015
mattab added a commit that referenced this issue Dec 6, 2015
@gaumondp
Copy link

gaumondp commented Dec 7, 2015

The logic for suggesting to add code after the </body> was that incomplete transmitted pages wouldn't be in the stats. What changed since the original recommendation ?

@hpvd
Copy link

hpvd commented Dec 7, 2015

I think this topic is really important!
From setting up several websites using piwik, we learned the lessons to load piwik as late as possible.
The reason is, when people uses browsers, browser plugins or browser settings which blocks tracking tools, there is a good chance that not only the tracker script is blocked but also everything after the blocked content (piwik) gets damaged too.
This leads to a complete broken website.
This is the worst experience on can give a visitor.

If piwik is loaded late -after most of the visible content-and it is blocked in a bad way, the website still looks mostly fine.

@mattab mattab changed the title JavaScript tracker code should be added in the <head> section or after <body> tag JavaScript tracker code should be added immediately before the closing </head> section Dec 21, 2015
@mattab mattab added the Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. label Jan 30, 2016
@hpvd
Copy link

hpvd commented Feb 3, 2016

just a feedback:
As mentioned putting piwik as late as possible was the lessons learned from having problems with some tracking blockers...
For us this does not mean at end of head but at end of body.

This is how to looks:

    <!-- START PIWIK TRACKING CODE -->
        <script type="text/javascript">
            //<![CDATA[
            ...
        <!-- END PIWIK TRACKING CODE -->

        </div>
</div>
</body>
</html>

@novahyth
Copy link

novahyth commented Feb 5, 2016

@op: This suggestion leads to having the fallback code (<noscript><p><img>...</p></noscript>) inside the <head>. It should mention that the fallback code is to be placed inside the <body>.

@tsteur
Copy link
Member

tsteur commented Feb 13, 2016

@novahyth good point, I just realized this as well while having a look at #9770 . It's not valid HTML otherwise and might not even be executed. I'll create a new issue for this.

@MattiSG
Copy link

MattiSG commented Nov 28, 2016

So, why was this done? I thought that webperf dictated to include all scripts as late as possible in the page, and especially the non-critical ones. Analytics is clearly the least to me. Why should I block rendering by adding Piwik in <head> rather than before the closing </body>?

MattiSG added a commit to betagouv/aides-jeunes that referenced this issue Nov 28, 2016
Include analytics at end of page
Remove tooling-dependent inclusion system
This goes against Piwik recommendation. See discussion at matomo-org/matomo#9341.
MattiSG added a commit to betagouv/aides-jeunes that referenced this issue Nov 29, 2016
Include analytics at end of page
Remove tooling-dependent inclusion system
This goes against Piwik recommendation. See discussion at matomo-org/matomo#9341.
MattiSG added a commit to betagouv/aides-jeunes that referenced this issue Dec 1, 2016
Include analytics at end of page
Remove tooling-dependent inclusion system
This goes against Piwik recommendation. See discussion at matomo-org/matomo#9341.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: Website matomo.org For issues related to our matomo.org website. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Projects
None yet
Development

No branches or pull requests

6 participants