Google Analytics Tracking Options: Doman vs. Subdomain

I am using Donncha's domain mapping plugin for my WP multisite. Because I could not get the Google Analytics for WordPress Multisite plugin to work for me, I've decided to use the tracking code that GA provides by itself along with filters.

The first question is since my subdomains are mapped to look like top level domains, should I use the multiple top-level domains code:

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

or do I use still use the one domain with multiple subdomains code:

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', '.hbcufannation.com']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

Secondly, based on the code that I use, what is the proper filter method to use to track the performance of each individual site without having to create a separate profile. I want to have a report that includes ALL sites in one report and then have reports for each individual blog within on profile. I have tried to find the answer on the GA site, but it is pretty confusing for me. Nobody seems to have one specific solutions.

Any suggestions?

  • Philip John
    • DEV MAN’s Apprentice

    should I use the multiple top-level domains code

    I believe so, yes. Although you are effectively working off sub-domains, Google doesn't actually see that so you don't need to tell it you're working off sub-domains.

    what is the proper filter method to use to track the performance of each individual site without having to create a separate profile

    I'm not sure on the code you used, though obviously the Google Analytics for WordPress Multsite plugin enables sitewide analytics so you could look at the code for that.

    Alternatively, I'd be happy to help you get that plugin working if you can tell me why it wouldn't work for you?

    Cheers,
    Phil

  • rillc
    • Site Builder, Child of Zeus

    Phill, I had problems with the plugin because it at the end of the day my reports would have all "0" as if there were no visitors. But since there is a new version released I will give it another try.

    Question: With the Google Analytics for WordPress Multsite plugin do I have to set filters if I want reports on each of my subsites? If so, how do I need to setup the filters? For some reason I could never get an answer on this.

    The instructions mention something about adding an additional line of code in order to tracksubdomains, but the link provided to the Google site is not very clear to understand. What exactly is the extra line of code that needs to be added if I want to track other sub-domains that are being mapped as top level domains.

    Unfortunately, you are going to have to "dumb" this down for me :slight_smile: .

    Thanks

  • rillc
    • Site Builder, Child of Zeus

    Phil,

    I read the instructions as you've posted and it states the following;

    To track all your subdomains separately you'll need to configure analytics and add in an extra line of code to the tracking code as described here (very easy to do): http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55524

    Are you telling me the above is not necessary if I want to track my sites separately? Are you saying no profiles are needed?

    Do I still need to enable the "Subdomain tracking" option now I am using the domain mapping plugin?

  • neomale
    • New Recruit

    Hi, just install your plugin. I have a multisite with Wordpress 3.1.1 using subdomain. (ex. ourdomain.com, blog.ourdomain.com, blog2.ourdomain.com, etc...)

    I wish to be able to track our main domain and our subdomain each separately.

    To track all your subdomains separately you'll need to configure analytics and add in an extra line of code to the tracking code as described here (very easy to do): http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&answer=55524

    But when i go on this link first thing it tell me is

    Note: This article is for the traditional (ga.js) version of the tracking code. We recommend you update your tracking code to use the latest (asynchronous) version. For instructions on using the latest version

    So do i have to care about this note?

    Thanks

  • alberti
    • Site Builder, Child of Zeus

    Guys, I'm having the same problem. I had a professional Wordpress guy install the extra code. But I don't see the subdomains anywhere and don't even understand the promise here. If it all works as claimed, am I supposed to see, in Google analytics, or my dashboard widget, a running list of each subdomain, with stats? Can you provide screen shots of the analytics dashboard of a successful install with multi-site / subdomains? Thanks.

  • eqhes
    • Flash Drive

    Hi,

    I've patched the Multisite Analytics plugin -Version 2.0.3- to make it track domains (I'm also using Donncha's domain mapping plugin -Version 0.5.4.2-).

    Here's how I got it working:

    1.- Setup your Google Analytics profile for the main site.

    2.- Add a new filter on that profile. These are my settings:
    Filter Name: Multisite all domains stats
    Filter Type: Custom filter
    [selected] Advanced
    Field A -> Extract A, Hostaname, (.*)
    Field B -> Extract B, Request URI, (.*)
    Output To -> Constructor, Request URI, /$A1$B1
    Field A Required: Yes
    Field B Required: No
    Override Output Field: Yes
    Case-sensitive: No

    3.- Edit the Multisite Analytics plugin. You can just upload the two files I'm attaching to this post replacing the original ones on the plugin's folder or follow the next coding replacements on your own (disclaimer: use at your own risk).
    3.1- On page-settings.php right after this code:

    <tr valign="top">
                                            <th scope="row"><?php _e( 'Subdomain tracking', $this->text_domain ); ?></th>
                                            <td>
                                                <input type="radio" name="track_subdomains" value="1" <?php if ( !empty( $site_settings['track_settings']['track_subdomains'] ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Enable', $this->text_domain ) ?>
                                                <br />
                                                <input type="radio" name="track_subdomains" value="0" <?php if ( empty( $site_settings['track_settings']['track_subdomains'] ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Disable', $this->text_domain ) ?>
                                                <br />
                                            </td>
                                        </tr>

    Add this other:

    <tr valign="top">
                                            <th scope="row"><?php _e( 'Domain tracking', $this->text_domain ); ?></th>
                                            <td>
                                                <input type="radio" name="track_domains" value="1" <?php if ( !empty( $site_settings['track_settings']['track_domains'] ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Enable', $this->text_domain ) ?>
                                                <br />
                                                <input type="radio" name="track_domains" value="0" <?php if ( empty( $site_settings['track_settings']['track_domains'] ) ) echo 'checked="checked"'; ?> /> <?php _e( 'Disable', $this->text_domain ) ?>
                                                <br />
                                            </td>
                                        </tr>

    3.2- On google-analytics-async.php right after this code:

    <?php if ( !empty( $network_settings['track_subdomains'] ) && is_multisite() ): ?>
    						_gaq.push(['_setDomainName', '.<?php echo $this->domain; ?>']);
    						_gaq.push(['_setAllowHash', false]);
    					<?php endif; ?>

    Add this other:

    <?php if ( !empty( $network_settings['track_domains'] ) && is_multisite() ): ?>
    						_gaq.push(['_setDomainName', '<?php echo str_replace( array( "http://", "www." ), "", site_url( "", "http" ) ); ?>']);
    						_gaq.push(['_setAllowLinker', true]);
    					<?php endif; ?>

    4.- Go to the Google Analytics Tracking Settings network page ("Tracking Network Settings"), enable "Domain tracking" and disable "Subdomain tracking".

    5.- Enjoy! :slight_smile:

  • eqhes
    • Flash Drive

    Hi @Designophobia,

    I've not tested it tracking both domains and subdomains, but it should work for both at the same time.

    Multisite Analytics 2.0.4 doesn't include my changes, so you will need to apply them again after updating the plugin to the latest version.

    Regards.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.