Loading Now
×

How to add google analytics in wordpress

How to add google analytics in wordpress

Method 1: (Best for Users Who Are Comfortable with Code)

1. Gather Your Google Analytics Tracking Code:1. Gather Your Google Analytics Tracking Code:

Switch to your Google account with Analytics and go to the property you need (Admin – Data Streams).
Take selection of your website’s data stream and scroll down to “Global site tag (gtag.js)”.
Paste the whole code snippet provided in the section “Global site tag (gtag.js)” below.


2. Choose Your Insertion Point:2. Choose Your Insertion Point:

Although plugins provide a lightweight mechanism to integrate Google Analytics with WordPress, manual methods do exist for whom code is not a problem. This guide details two methods to add Google Analytics to your WordPress site without plugins:This guide details two methods to add Google Analytics to your WordPress site without plugins:

Theme Header:

This method adds the code to all pages so the tracking covers the whole website completely. But make theme file editor, there is a possibility to achieve some issues with WordPress installation, if the task is performed incorrectly.
Functions.php: This helps to provide more flexible results since you can use conditional statements to track precise pages and sections using them. Yet, it is skill intensive.

3. Edit Your Theme Files:3. Edit Your Theme Files:

Theme Header:
Move to the WordPress dashboard of your website and click on “Appearance” > “Editor”.
Select “Theme Header (header.php)” from “Right hand side menu”
Important: Look for the nearest </head> tag. Put you Google Analytics tracking code directly above </body> tag.
Click “Update File” to save the file.
Functions.php:
Access the “functions.php” state through an FTP client or a file manager plugin.
Add the following code snippet, replacing YOUR_TRACKING_ID with your actual code:Add the following code snippet, replacing YOUR_TRACKING_ID with your actual code:

<head>
    <!-- Other header content -->
    <!-- Paste your Google Analytics tracking code below this line -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=YOUR_ANALYTICS_ID"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'YOUR_ANALYTICS_ID');
    </script>
    <!-- End of Google Analytics tracking code -->
</head>


Use code with caution.
- Put the updated "function.php" file back to your web server.


4. Verify and Test:

You must wait 24-48 hours to allow your Google Analytics report to update.
Make sure Google Analytics is working by using the Real-Time feature of Google Analytics to check if the tracking works shortly after the changes are made.


Method 2: Applying a Child Theme for Tuning the Code Safely (for Advanced Users Only)

1. Create a Child theme

With this option you can keep up to date with the latest theme updates so they do not affect your code changes. Attend to each instruction to your theme for the child theme.


2. Edit the Child Theme’s Header.php:2. Edit the Child Theme’s Header.php:

Look at the “Theme Header” section in Method 1 and paste your code between <head> and </head>

Here instructions are being given for you through photos which will be very easy for you to understanding. You can connect Google Analytics in WordPress by following them one after the other. There are other methods to connect Google Analytics in WordPress :

Go to google analytics website : https://analytics.google.com/analytics

i hope this content healpfull for you , thank you for reading my content any qurey and question to ask me in comment section in below thank you viewers.

Post Comment