How to add Google Analytics code in WordPress website

By gnanaguru, 22 December, 2022

Google Analytics is a web analytics service offered by Google that tracks and reports website traffic.

There are numeros plugins available to insert Google Analytics code in the WordPress website. Here we are going to see that how Google Analytics script can be added via WordPress hooks.

WordPress hooks allow developers to change or extend WordPress' functionality without needing to edit the WordPress core code itself.

wp_head hook is fired in the head action.  Google Analytics scripts should be placed in the head of HTML in all the pages. So it will track all the activities/captures the actions.

Image removed.

Above code snippet will insert the Google Analytics code in head of the WordPress pages

Image removed.

Henceforth your website activities are tracked by Google

 

 

 

 

Tags

Comments

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.