Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8371631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:12:36+00:00 2026-06-09T14:12:36+00:00

I am looking to use different Google Analytics codes based on the domain the

  • 0

I am looking to use different Google Analytics codes based on the domain the site is being viewed on.

I read that the following code will work well for my scenario (in a Drupal environement):

<?php
// Override Google Analytics Web Property ID per hostname. 
// Hostnames need to be lower-case!
switch ($_SERVER['HTTP_HOST']) {
  case 'www.example.com':
  case 'www.example.net':
  case 'forum.example.net':
    $conf['googleanalytics_account'] = 'UA-123456-2';
    break;

  case 'www.example.org':
    $conf['googleanalytics_account'] = 'UA-123456-3';
    break;

  default:
    $conf['googleanalytics_account'] = 'UA-123456-1';
}
?>

I am using WordPress. Will this code work for me? If so, I do not exactly understand it…Is this saying that all sites that ARE NOT listed, will use teh default GA code (bottom one), an the http://www.example.org will use the middle GA code, and all of the others will use the top GA code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:12:38+00:00Added an answer on June 9, 2026 at 2:12 pm

    You shouldn’t be setting filtering at the website level. In a nutshell you should use your GA code to declare ALL the subdomains and domains you want to bring into your GA account. Then, in your GA account, you can set up multiple profiles with filtering options.

    http://services.google.com/analytics/breeze/en/v5/domains_subdomainsv22_ad1/
    (Jump right to slide 12 if you want a simple graphic overview)

    Do this:
    1.) Set up your site GA code to encompass all the domains you want to track.
    2.) Choose the account in GA > Admin Menu > Create New Profile
    3.) Click the Filters tab > Choose Predefined Filter > Include only > traffic from the domains > (a subdomain/domain)
    4.) Save

    Now do that for every subdomain/domain you want to add. This is generally the best practice for this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My understanding is that Google Analytics (the tool I'd normally use for website analytics)
I am looking for a most efficient way to re-use widgets with different selectors...
I am looking to use jquery to search for a certain string that gets
I'm looking to use some framework to help generate java client bindings based on
I fairly new to Google Analytics. I'm looking for a way to add GA
I enjoy working with Google Analytics and the ways that I am able to
I have been looking through Google and SO for something that could help me
I am looking to create a client/server application that I can use to slit
I have recently started looking into Google Charts API for possible use within the
I'm looking at the following code I found in libgksu and I'm wondering what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.