Google Analytics - move the tag inside the head?

4 years ago
Hi maybe you know why i see this information? I add GA code in nop-widget.
"Move the tag inside the head.
We have detected that the Google Analytics tracking code is outside of the
section on this page. This decreases the likelihood that the tracking beacon will be sent before the user leaves the page.
One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. We've determined that on most pages, the optimal location for the asynchronous snippet is at the bottom of the
section, just before the closing tag.
Solution: Ensure that you add the Google Analytics tracking code onto this page before the closing tag."

Any idea?

Maybe you change this plugin in NOP3.6?
4 years ago
Currently Google Analytics code is present before closing of body tag. Do you want to add in Head tag ?
4 years ago
Hmm... this is Google Sugestion :)
4 years ago
Hi,

find GoogleAnalyticPlugin.cs and change:


"body_end_html_tag_before"

in

"head_html_tag"

so, you have to compile Nop.Plugin.Widgets.GoogleAnalytics
4 years ago
Hello and thx !
Can you explain to me why the NOP is used at the end of the <body> tag ? no in the <HOME > like Google suggests?
is any reason?
4 years ago
I don't know
I had to make the same code change.

However in the next release tag is inside the head.
4 years ago
Zyje_sobie wrote:
Hi maybe you know why i see this information? I add GA code in nop-widget.
"Move the tag inside the head.
We have detected that the Google Analytics tracking code is outside of the
section on this page. This decreases the likelihood that the tracking beacon will be sent before the user leaves the page.
One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. We've determined that on most pages, the optimal location for the asynchronous snippet is at the bottom of the
section, just before the closing tag.
Solution: Ensure that you add the Google Analytics tracking code onto this page before the closing tag."

Any idea?

Maybe you change this plugin in NOP3.6?


While GA is probably fine in the head tag, particularly if they are recommending it, I have had experiences with trackers that claim to be asynchronous but block the page for up to 500ms to pull a script.  In cases like those, I would definitely opt to put those scripts as far down in the page as possible.
I guess what I am trying to say is proceed with caution if you use other trackers and use Chrome dev tools or something similar to see when your document is truly finished loading.