[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Google Analytics in WordPress

Posted on 2014-07-11
10
Medium Priority
?
194 Views
Last Modified: 2016-02-24
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>
0
Comment
Question by:Richard Korts
  • 4
  • 4
  • 2
10 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40190961
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
 
LVL 12

Expert Comment

by:Nathan Riley
ID: 40191223
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
 

Author Comment

by:Richard Korts
ID: 40191365
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40191369
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
 

Author Comment

by:Richard Korts
ID: 40191384
"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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40191426
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
 

Author Comment

by:Richard Korts
ID: 40191486
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40191538
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
 

Author Comment

by:Richard Korts
ID: 40191565
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
 
LVL 12

Accepted Solution

by:
Nathan Riley earned 2000 total points
ID: 40191585
You won't see the stats from today until tomorrow.
0

Featured Post

Get Certified for a Job in Cybersecurity

Want an exciting career in an emerging field? Earn your MS in Cybersecurity and get certified in ethical hacking or computer forensic investigation. WGU’s MSCSIA degree program was designed to meet the most recent U.S. Department of Homeland Security (DHS) and NSA guidelines.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read about the 3 stages of the buyer's journey: awareness, consideration, and decision.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question