Google Analytics in WordPress

How do I insert Google Analytics code into a WordPress site?

E.g.,

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxx-1', 'auto');
  ga('send', 'pageview');

</script>
Richard KortsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jason C. LevineNo oneCommented:
Several ways:

Easiest is to use the Google Analytics plugin from Yoast and then just feed it the UA-XXXXX code and the plugin does the work from there.  It's very lightweight and works with your caching solution so it's not a drag on the site.  Adding things via a plugin means you don't have to worry when switching themes.

Other solutions would include checking your theme options (if it has them) to see if they provide an "add a script" section that outputs CSS or JS on every page.  If not, you can always open the theme's header.php file and add the script there.
0
Nathan RileyFounderCommented:
If you don't want to use a plugin you could always login to the domain.com/wp-admin and follow these steps.

1. Click Appearance on the left sidebar
2. Click Editor
3. Select the Footer.php file on the right
4. Drop in your code before the </body> tag and save
Untitled-1.png
0
Richard KortsAuthor Commented:
To Jason C. Levine,

Yes, a plugin would be easy, but I got that one & it didn't ask for the UA code so I can't see how it could work so I deactivated it.

Word Press is Soooooooooooooooooo odd.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Jason C. LevineNo oneCommented:
When you install the Yoast plugin it will actually try to access your Google account via browser cookie.  At the top of the settings screen (under the initial text and button to auto-validate) is a link that says "Manually Add UA Code"  Find it and use it.

Word Press is Soooooooooooooooooo odd.

Nope.  You're just giving up too quickly.
0
Richard KortsAuthor Commented:
"At the top of the settings screen (under the initial text and button to auto-validate) is a link that says "Manually Add UA Code"  Find it and use it."

I have NO clue where to find this. It is not on the plugins page. I go to edit plugin, can't see it there.

I go to settings (overall), not there.

As I said, Wordpress is so Odd.
0
Jason C. LevineNo oneCommented:
With the plugin active:

1) Go to Settings | Google Analytics
2) Refer to screenshot:

Location of manual entry code.
Alternate #2 = You can also click the big blue button and attempt the auto validation.
0
Richard KortsAuthor Commented:
To Jason C. Levine

There is no "Google Analytics" under Settings. See attached.

And the plugin IS Active.

I already put in the code the other responder suggested; maybe that's mixing it up?
settings.jpg
0
Jason C. LevineNo oneCommented:
There is no "Google Analytics" under Settings. See attached. And the plugin IS Active.

Then I have no idea what is wrong with your site.

I already put in the code the other responder suggested; maybe that's mixing it up?

Shouldn't matter
0
Richard KortsAuthor Commented:
To Nathan Riley

I put the code in as you suggested. I have visited my site several times SINCE then.

Google Analytics shows nobody visited my site, ever.

I guess it's a different question, but how do you look at the results? I searched "How to look at Google Analytics...", showed me how, nothing.

Obviously I'm doing something wrong.

If you go to my Wordpress site, view source, you see the Google Analytics code near the bottom. But it does nothing. www.rkassociates.com
0
Nathan RileyFounderCommented:
You won't see the stats from today until tomorrow.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.