Add code Analytics in Wordpress blog

Asked

Viewed 179 times

0

I’m trying to change the code Analytics of a Wordpress blog. However, I don’t have much knowledge and I’m having trouble figuring out how the code was added.

From what I research, I managed to figure out 3 ways to add the code Analytics in wordpress. However, none of these forms have been used and yet it has an Analytics code already added.

The shapes I found are:

  • Using a plugin (I looked at the plugins and did not find the Google Analytics or any other plugin with the word "Analytics").
  • Inserting the code into header.php theme (The theme does not have the script for the Analytcs tag. But it does have a PHP function that might add something: <?php wp_head(); ?> However, I’m not sure if the code is inserted by this function).
  • Creating a new function in the file functions.php (I searched this file and it also has no script for Analytics)

These were the only ways I found to add Analytics code in Wordpress. But from the looks of it, the code was added otherwise.

There are other ways to add Analytics code in Wordpress?

  • Your theme has some plugin that is called Yoast ?

  • Yes @hugocsl. It has the plugin "Yoast SEO Premium".

  • Is there a link to this site? The Google script you are looking for is at the top or at the bottom of the page ?

  • Yes. It’s posted! the code appears at the head of the pages. It seems to be added by the "wp_head()" function of the header.php file.

  • Guy goes in theme, in Appearance > Edit > Find header.php must be inside it

  • It’s not. Like I said upstairs. In the header.php of the theme, I only have the wp_head() function. I even added the new code of la Analytics and mine appears just below the old on the page. Leaving it with two codes of Analytics. Above the script tag I added there is no script tag. everything is added running. That’s why I think it’s this "wp_head()".

  • can be YOAST, disable it and see if Analytics remains: Yoast Plugin > Features > Disabled and save changes

  • I don’t have much knowledge in wordpress. So I don’t feel safe in disabling this plugin. Because it might be making other settings. I will search and study a little more about it before. To not affect the functioning of the blog.

  • Try the brute force: download all the files in a folder and search for Windows by searching for the term "Analytics" inside the files.

  • @The funny thing is, I did this, and as amazing as it sounds, it’s not in the files. The old Analytics code only appears on the HTML cache pages of the blog. What makes me strongly believe that this setting comes from some plugin!

  • If there were go disabling each plugin at once and checking.

  • @dvd I intend to do this, but calmly. As I do not have much knowledge in Wordpress, I intend to study a little about each plugin before disabling. To know the effect of this on the blog. I’ve already added the new code, so it’s at least already being tracked. My problem now is that it has two Analytics codes. The old and the new, so I need to remove the old and leave only the new.

  • I understood, but what I meant was you disable (even if it affects the blog) a plugin, give refresh on the blog and see if the old Analytics is gone; if not, enable the plugin again and part to other doing the same thing.

  • @Alan If you use a linux server, go to the root of your project and run the following command: grep -irwn "analytic*" --include "*.php". So it will list all the files that contain that word. Another alternative is to search the Analytics code in the database, so you can delete it; If it still does not solve, it is probably encrypted and you will need to check plugin by plugin.

  • @Thanks Valdeirpsr. But I did the verification process (search) on all the blog files in sublime text. So I strongly believe that this setting is coming from some plugin. I will test every one of them calmly and when I find I will post here what was!

  • I did a lot of research regarding your problem, and almost everywhere the tip is the same: disable the plugins and go enabling one by one (giving refresh before the blog) to see if appears the old Analytics. By enabling a plugin again and appearing the Analytics, you will know that it is it that is generating. But this has to be a quick process, even if the Blog if Sconfigure for a few moments, I think it’s not a big problem for you to find where this comes from.

  • @dvd thanks for the effort in trying to help me. But to my surprise the setting was within the configuration screen of the theme itself! :)

Show 12 more comments

2 answers

0


Finally I found it. Thanks to your help. Thanks to everyone who tried to help with tips in the comments :D

Before I was always accessing Appearance -> Editor, selecting the current theme and looking for the code in the files header.php, functions.php and in others.

But this time I went on Aparência -> Temas. All themes were listed. I clicked on Customize theme I’m using. A new editing screen loaded with a side menu. I clicked on the option Theme Panel menu. After that, another configuration page was opened "Newspaper - Theme panel" displaying the menu panel of the wordpress itself and another menu of the theme on the side. Then clicked on the menu ANALYTICS theme. And a box with the code Analytics has been opened! :)

Full path: Appearance -> Themes -> Customize -> Panel Theme -> ANALYTICS

-3

Get in the header.php or in the footer.php of your THEME and add the code Provided by Google.

Example of a Google code:

<!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-114669691-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'UA-ID-1');
    </script>

No header.php coloque antes de </head>
No footer.php coloque antes do </body>

Example:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Exemplo</title>

    <!-- Faça dessa forma se for usar no header.php -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-114669691-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'UA-ID-1');
    </script> <!-- Faça dessa forma se for usar no header.php -->
  </head>
  <body>

    <h1>Olá Mundo!</h1>

    <!-- Faça dessa forma se for usar no footer.php -->
    
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-114669691-1"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'UA-ID-1');
    </script> <!-- Faça dessa forma se for usar no footer.php -->
  </body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.