How to place Google Analytics script in head instead of body in nopCommerce

Many search engine optimization (SEO) experts have different opinions about where to place Google Analytics script. Whether it should be in <head> or </body> section? If you search online, you will find several different opinions from different SEO experts / developers.

In nopCommerce (out of the box), the Google Analytics script (if enabled) is designed to be placed right before your </body> tag. But, there are some users / developers who prefer to place the Google Analytics script in the <head> section.

So what is the best location for your GA script? Well, practically the Google Analytics code will work regardless of where you put it on the page.

This is how GA script location looks like by default in nopCommerce:

So, let us go over the process if you wish to change the placement of your Google Analytics script from </body> to <head>.

Step 1: First, make sure you are using the source code version of nopCommerce (For more info, see web vs source code)

Step 4: As, you can see in the default code, the widget zone that is defined for this plugin is “body_end_html_tag_before”. Let’s change the widget zone to “head_html_tag”. Your updated code should look like this:

Author Spotlight

Lavish Kumar

Founder, developer and owner of StrivingProgrammers.com - By profession, he is a software programmer / web developer, web designer & DBA. He is passionate about technology and electronic gadgets. He enjoys writing tech articles and developing web applications. He is a nopCommerce MVP and author of official nopCommerce Designer's Guide.