Teadmistebaas

How do I add Google Analytics to WordPress

To add Google Analytics to your WordPress website, you can follow these steps:

Method 1: Using a Google Analytics Plugin (Recommended)

  1. Log in to Your Google Analytics Account:

  2. Create a Property for Your Website:

    • After logging in, click on "Admin" in the lower-left corner.
    • In the "Property" column, click the "+ Create Property" button.
    • Follow the prompts to set up a new property for your website.
  3. Get Your Google Analytics Tracking Code (UA Code):

    • Once your property is set up, Google Analytics will provide you with a tracking code (UA code). It looks like "UA-XXXXXXXXX."
    • Copy this UA code.
  4. Install and Configure a Google Analytics Plugin:

    • In your WordPress dashboard, go to "Plugins" > "Add New."
    • Search for a Google Analytics plugin (e.g., "MonsterInsights," "GA Google Analytics") and install it.
    • Activate the plugin.
  5. Connect the Plugin to Your Google Analytics Account:

    • In your WordPress dashboard, go to "Insights" (or the name of the plugin you installed).
    • Follow the setup wizard or instructions to connect the plugin to your Google Analytics account.
    • You'll need to paste the UA code you copied earlier.
  6. Complete Setup:

    • Configure any additional settings provided by the plugin.
    • Save your changes.
  7. Verify Tracking:

    • To verify that Google Analytics is tracking your website, visit your website, and then check your Google Analytics account for real-time data.

Method 2: Manually Adding Google Analytics Code

If you prefer not to use a plugin, you can manually add the Google Analytics tracking code to your WordPress site. Here's how:

  1. Log in to Your Google Analytics Account and obtain your UA code as explained in steps 1-3 above.

  2. Copy the Tracking Code (the script) provided by Google Analytics.

  3. Add the Tracking Code to Your WordPress Site:

    • In your WordPress dashboard, go to "Appearance" > "Theme Editor."
    • Look for the "header.php" file in the right-hand column (usually under "Templates").
    • Click on "header.php" to open it for editing.
  4. Paste the Tracking Code: Locate the closing </head> tag in the "header.php" file, and just before it, paste the Google Analytics tracking code.

    It should look something like this:

    <!-- Google Analytics Tracking Code --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXXXXX'); </script> <!-- End Google Analytics Tracking Code --> </head>

    Replace "UA-XXXXXXXXX" with your actual UA code.

  5. Save Changes: After pasting the code, click the "Update File" button to save the changes.

  6. Verify Tracking: To verify that Google Analytics is tracking your website, visit your website, and then check your Google Analytics account for real-time data.

Using a plugin is generally more user-friendly and may offer additional features and insights. However, manually adding the tracking code gives you more control over where and how the code is implemented on your site. Choose the method that best suits your needs and comfort level with WordPress customization.

  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?