×
  • Themes
  • Support
  • Blog
  • Log In
  • Sign Up

NiceThemesNiceThemes

  • Support
  • Themes
  • Log In
  • Sign Up
Menu

Support Articles

Articles and Documentation for your NiceThemes products.

Knowledge Base / Theme Configuration / How to Add Google Analytics Tracking Code

How to Add Google Analytics Tracking Code

Google Analytics is a very popular statistics service. In order to get your traffic information, it provides you with a tracking code, which needs to be added to all the pages of your site.

How to add the tracking code

  1. Log into your Google Analytics account, and copy your tracking code.
  2. In your WordPress Dashboard, go to NiceThemes → Theme Options.
  3. In the theme options panel, go to General Settings.
  4. Paste your tracking code into the Tracking Code option.
  5. Click the Save Changes button at the top.

How to conditionally print the tracking code

There is a chance that you may not always want to track all the activity of your site. In example, let’s say you only give user accounts to editors or administrators. In that case, you should only track the activity of unlogged, because doing otherwise may alter your statistics and lead to inaccurate information. All that such a requirement would take is a little bit of code in your functions.php file:

if ( ! function_exists( 'conditionally_do_tracking_code' ) ) :
/**
 * Don't show tracking code for logged in users.
 *
 * @return bool
 */
function conditionally_do_tracking_code() {
   if ( is_user_logged_in() ) {
      return false;
   }

   return true;
}
endif;

The function must return a boolean value, which should be true for every case in which you want to show the tracking code, and false for every case in which you want to hide it. In the example, we use the WordPress function is_user_logged_in(), which returns true if a user is currently logged in, and false if not.

As you can see, it’s very easy to customize this function to suit other needs. The only thing you need to remember is to always return a boolean value.

Theme Configuration

Related Articles

  • Importing demo content
  • Changing the logo of your Theme
  • Using the Gallery template
  • Turning Off WordPress Comments
  • Ordering categories
XML Demo Content
If you're looking for the XML demo contents, you can get them here

Categories

  • Installation & Updates
  • Theme Basics
  • Theme Configuration
  • Theme Customization
  • Support
  • FAQs

Documentation

In the documentation you'll find all you need to get started. Select the product from the list to see the documentation.

NiceThemes

  • About
  • Blog
  • Contact

Support

  • Support Center
  • Knowledge Base
  • Support Forums

Products

  • Themes

Join Us On

Curated with lots of    by your friends at NiceThemes™

Login to your Account

Welcome back! Please log in to your account by filling the fields below:

Forgot?

Not a member? Create a free account.

Create a Free Account

You're 27 seconds away from some awesome WordPress free stuff, benefits and more. Create a free account and have access to our free products, benefits and more!

Already have an account? Log in
Secure Server