Opening a new issue per this comment...

Using Domain Access and Google Analytics. In order to maintain separate Google Analytics accounts on subdomains I followed this advice and placed the following code into a domain_conf.inc file:

/**
* Implements hook_domainconf() to add the google analytics account number per domain.
*/

function googleanalytics_domainconf() {
  $form['googleanalytics'] = array(
    '#type' => 'fieldset',
    '#title' => t('Google Analytics settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );

  $form['googleanalytics']['googleanalytics_account'] = array(
    '#type' => 'textfield',
    '#title' => t('Google Analytics account number'),
    '#default_value' => variable_get('google_analytics', 'UA-'),
    '#size' => 15,
    '#maxlength' => 20,
    '#required' => TRUE,
    '#description' => t('The account number is unique to the websites domain. Click the <strong>Edit</strong> link in your Google Analytics account next to the appropriate profile on the <strong>Analytics Settings</strong> page, then select <strong>Check Status</strong> at the top-right of the table to find the account number (UA-xxxx-x) of your site. You can obtain a user account from the <a href="@url">Google Analytics</a> website.', array('@url' => 'http://www.google.com/analytics/')),
  );
  return $form;
}

The end result is the separation is working as expected within the Google accounts using individual UA-#'s for each the primary domain and subdomains. There is however a problem within the Drupal site itself:

At admin => build => domain => conf => "domain #", the Google Analytics account number field does allow input of the UA-# and it is recorded in the db and Google is receiving data to that specific account; however, the text field itself does not remain populated with the previously entered value upon revisiting or refreshing the conf page again. This creates a bit of a problem when the user attempts to update information in other fields on the domain conf page, as the user will also be required to re-enter the correct UA-# value again, or else the value will be unset.

What is very interesting, is at admin => settings => googleanalytics. If the individual UA-# values have been entered and saved from the domain conf page (above), the correct values are then pre-populated, as they should be, in the Google Analytics account number field in the respective domain's Google Analytics module configuration pages... e.g. example.com/admin/settings/googleanalytics, domain1.example.com/admin/settings/googleanalytics, domain2.example.com/admin/settings/googleanalytics, etc.

Is there a solution to getting the previously entered UA-#'s to also pre-populate the Google Analytics account number field on the domain conf pages as well?

Comments

agentrickard’s picture

It is possible that the switch to using DomainBatch to define these elements affected the form handling.

See #545946: Domain Mollom for another way to expose your data to Domain Conf.

If this is the case, we have to update the documentation.

agentrickard’s picture

Category: support » bug
Status: Active » Needs review
StatusFileSize
new2.05 KB

Nope, this is a bug in domain conf. This patch should fix it. Apply from the root domain directory.

yt2s’s picture

Worked like a champ! Thank you very much!

Side Note:   This patch applied to domain_conf.module (28 Jun 2009 V 1.49) starting on line 457.   I applied the patch manually instead to 6.x-2.0-rc8 domain_conf.module (14 Jun 2009 V 1.46) beginning on line 448.

agentrickard’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new1.82 KB

Yes, the patch is against HEAD, so this is fine.

Committed to HEAD. D5 version attached and needs a test.

matteoraggi’s picture

It will be on 6.x-2.0-RC10 ?

agentrickard’s picture

It is already in rc9. There will be no rc10, just a 6.x.2.0 final.

matteoraggi’s picture

Nice to read it, so to add multiple google analytics codes, I?ll need to follow these up instructions, because I don't find into user interface the possibility to do it, for example there:
admin/build/domain/batch
admin/settings/googleanalytics
There will be always need to modify domain_conf.inc or in future we'll be free to use UI.?

croryx’s picture

It is available in the UI (at least using the patch on rc8) at:
/admin/build/domain/conf/THEDOMAINID

or just go to Administer>Site building>Domains and click on the 'settings' link for the domain you want to edit. There should be a Google Analytics settings box at the bottom for you to enter your UA account number.

matteoraggi’s picture

StatusFileSize
new10.08 KB

I'm using rc9 without patch and I can't find it in UI, I have attached what I see on this page.

croryx’s picture

I may have misread your original comment, sorry. You do need the domain_conf.inc file above for this to work.

agentrickard’s picture

You have to implement the hook yourself, or convince the Google Analytics maintainer to put it in the module.

matteoraggi’s picture

I have done it now, with my bad english:
http://drupal.org/node/574930

agentrickard’s picture

Status: Patch (to be ported) » Fixed

D5 does not pass in the null option, so this is done.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

matteoraggi’s picture

I skipped problem using woopra code i's more simple just beause it code is always th same, so easily I can put it into theme or with woopra module and then track with one same code for al site different stats for many sites: http://drupal.org/node/624114#comment-2388318 .

agentrickard’s picture

For reference, in DA 6.x.2, here's how to add Google Analytics properly:

/**
 * Implement hook_domainbatch().
 *
 * Add Google Analytics settings to Domain Conf.
 */
function custom_domainbatch() {
  if (!module_exists('googleanalytics')) {
    return;
  }
  $batch = array();
  $batch['googleanalytics_account'] = array(
    '#form' => array(
      '#title' => t('Google Analytics'),
      '#type' => 'textfield',
      '#size' => 40,
      '#maxlength' => 80,
      '#description' => t('Google Analytics account key, in the format UA-XXXXXX'),
      '#required' => TRUE,
    ),
    '#domain_action' => 'domain_conf',
    '#meta_description' => t('Set Google Analytics keys for each domain.'),
    '#variable' => 'googleanalytics_account',
    '#data_type' => 'string',
    '#weight' => 0,
    '#group' => t('Google analytics'),
    '#update_all' => TRUE,
    '#module' => t('Custom'),
  );
  return $batch;
}

/**
 * Implement hook_domainwarnings().
 *
 * Warn users about the Google Analytics form.
 */
function custom_domainwarnings() {
  return array('googleanalytics_admin_settings_form');
}

This only allows you to change the key per domain. You could add additional settings as well.

davidwhthomas’s picture

Thanks, this D6 approach works perfectly.

seanb’s picture

Perfect! thnx..

davidwhthomas’s picture

StatusFileSize
new735 bytes

Following on from agentrickard's great example, here's a small module "Domain Analytics" to provide per-domain Google Analytics settings with Domain Access.

Using it myself and working perfectly.

Note: rename from domain_analytics.tar_.gz to domain_analytics.tar.gz to extract.

DT

P.S Thanks again for the awesome Domain Access module suite, great stuff.

tevans’s picture

Confirmed. Just installed and working as expected. Thanks!

hawkdrupal’s picture

One apparent shortcoming, either in DA or Domain Analytics:

The domain-specific list is radio buttons, not check boxes. And/or, the option to use the current domain is not in the list. So there must be a setup of this for each and every domain managed by Domain Access.

Yet in some cases (such as mine) there is a mix of subdomains that all get tracked together, and separate domains that need separate tracking. Lacking the ability to select multiple subdomains (or use DA's simpler "Use current domain"), I must set up Domain Analytics individually for DOZENS of subdomains that all track together. So each time I'm just duplicating the entire record then selecting a different subdomain.

DA handles this elsewhere by providing "Use current domain", so I just have to set up the three main domains I use and let the subdomains be handled transparently.

My solution is to stick with my prior method: For each domain I need to track (3 in my case) I have a block with the Javascript Google provides. I use DA's block control module to specify in which domains these blocks appear. This module provides check boxes, so I can put assign one tracking code block to the many subdomains it applies to. (However, this module doesn't provide "Use current domain"; wish it did.) This approach is very simple and presumably efficient. So I'm not clear on what the Google Analytics module would add to the mix.

Also, (minor), in this module, once an item in the list User Segmentation is selected -- inadvertently -- there's no "" or equivalent to unselect. The solution is to select the item while pressing Ctrl, which seems to unselect it. But this isn't obvious and not how most lists work in my experience.

jamesHF’s picture

hawkdrupal, reading your post, it seems that you have Domain Settings module enabled, which is not related to Domain Analytics.

It's not mentioned, but Domain Analytics requires Domain Content module to be enabled. Also, the Domain Analytics page is found on the Batch Updating tab of Domain settings, (the url is admin/build/domain/batch/googleanalytics_account)

(kudos to davidwhthomas for creating the Domain Analytics module)

davidwhthomas’s picture

@hawkdrupal Yes, that is a domain access issue, not domain analytics.

Newer versions of domain access support an 'all domains' radio button when updating settings forms.

In any case, the easiest place to update, as mentioned by jamesHF is min/build/domain/batch/googleanalytics_account

cheers,

David

chirale’s picture

Tested #19, it works fine, thanks davidwhthomas!

Note: please add "domain_conf" to dependencies on the .info. It cannot works without it! ;-)

agentrickard’s picture

Category: bug » feature
StatusFileSize
new2.35 KB

Here's a D7 version, which works almost without modification.

barber75’s picture

Hey,

Gonna check out Domain Analytics, sounds good! Thanks for the hard work...

cheers
Craig

jillpadams’s picture

Version: 6.x-2.0-rc8 » 6.x-2.8

Has anyone here found a successful way to move the Analytics code from the foot to the head, so Analytics will play nicely with Web Master Tools? We are running GA 6.x-3.2, with Domain 6.x-2.8. Have used the code above to set UA codes for each domain.

The new Analytics asynchronous code should appear between the head tags, but haven't seen a convenient way to get it there yet, without adding to the page.tpl (which is bollocks for multiple domains). Any code snippets to offer?

petednz’s picture

Not seeing any comments about this - so just before I throw it in, can you clarify 'almost' in the statement "works almost without modification'

iaminawe’s picture

@Agentrickard I would also like some clarification as to how this works please and what modifications are required to make it work.

I have installed it and would like to check if I should still be tracking a single domain in the settings but then saving the tracking number for each domain by choosing the relevant domains from the "Domain Specific settings form"

I have done it this way and as yet the primary domain is picked up by GA but not the other 2 I am trying to track. It could just be a matter of time before they show up but thought I should check.

bcobin’s picture

Version: 6.x-2.8 » 7.x-3.4
Component: - Domain Conf » - Domain Settings
Status: Closed (fixed) » Active

+1 here for #28 and #29.

I came across the following post for Drupal 6, which describes what perhaps is supposed to be intended behavior, but it isn't clear.

http://amariotti.com/blog/multiple-google-analytics-accounts-domain-acce...

@agentrickard - reopening and changing to 7.x-3.4 insofar as this seems to be the only thread that addresses the issue in D7 and that you have posted a module in #25, even though that was almost two years ago. "Works almost without modification" is also confusing, for obvious reasons.

Please forgive and re-close if I've done the wrong thing by reopening the issue - launching sites now (DA is amazing) and I didn't expect to run into this. Would appreciate any guidance here... thanks!

bcobin’s picture

Status: Active » Reviewed & tested by the community

Changing this to "reviewed and tested by the community" insofar as with #25 installed, settings are independent per domain and I see the appropriate Google tracking code on the different sites - and in head, no less.

The existence of the module should be better documented, but hey - I'll take it!

agentrickard’s picture

Not really RTBC. I have no intention of maintaining this code. Someone else needs to start a project for it.

agentrickard’s picture

Status: Reviewed & tested by the community » Closed (works as designed)
pedrosp’s picture

Another way to go:
Domain + Variable + Domain Variable + Google Analytics
(+ little modif. hopefully soon commited) http://drupal.org/node/1702522#comment-6746318

jsi’s picture

Priority: Normal » Major

I am not able to get analytics to work on my 7.x-3.8 install.

Anyone have a step by step tutorial on how to apply this module and make it work?
I see the analytics forms in admin/config/system/variable/realm/global
but nowhere for me to edit per domain.

If i go to admin/config/system/googleanalytics
underneath there is an option to save for all or select per domain. However, it does not seem to save it cause i cannot see tracking code on front end even after clearing cache.

Also, there is no way for me to know which domains need the analytics code.

Im sure many have installed analytics on your site and made it work. Anyone have a quick tutorial or directions on how to do this?

Thanx.

pedrosp’s picture

Have a look at http://drupal.org/node/1843960
Domain access + domain variable + google analytics
you should click the web property id on /admin/config/system/variable/realm/domain/configure
and it will show up in your specific domain settings /admin/structure/domain/view/xx/variables

jsi’s picture

Thanx for the reply.

I went to that location and there is not a web property id setting.

I have all Domain access + domain variable + google analytics enabled and the web property id does not show here.

Instead it shows here: admin/config/system/variable/realm/language/configure
and here: admin/config/regional/i18n/variable

However, if i enable it in any of these two, it does not show on the domain editing settings.
Seems like i18n is incompatible with google analytics?

Since I cannot figure this out and get it done via CMS, I simply provided the analytics code per domain like specified here:
http://drupal.org/node/595520

In my case, i do not use subdomains. I have over 50 affiliate domains, each of which requires a different analytics code. So i just edited settings.php file directly.

Thanx for that link where it explains how to do that. Although the fact that i was not able to get it to work via domain access module, it leaves me with the question if there is something wrong with my installation since that section is missing or what. hehe

jawi’s picture

Same issue here. Thanks for the url. http://drupal.org/node/595520
Very usefull!!

pedrosp’s picture

I am using last standards versions of DA 3.8 and Domain Variable 1.0,
BUT I forgot to tell that you should use the last Dev version of Google Analytics to see the integration... ;)

shaysmith’s picture

To configure the Web Property ID's for each domain, you will go to the following page:
/admin/config/system/googleanalytics

Make sure you have "One domain with multiple subdomains" selected in the "What are you tracking" section. Enter the id for one of your domains, then select that domain in the "Domain Specific Settings" section at the bottom of the page.

Click "Save configuration" and your ID will be saved and attributed to the correct domain.

Shay Smith.

Drupa1ish’s picture

In order #25 to work with DA 7.x-3.x , modify inside domain_analytics_d7.zip function domain_analytics_domain_batch() , implementing the new hook_domain_batch()

epophoto’s picture

Issue summary: View changes
StatusFileSize
new1.16 KB

Attaching a new version of the D7 version created in #25 that has been updated to reflect the api updates in #41.

I would be willing to create a project for this, @Agentrickard suggests he/she has no interest in doing so above...

I emailed him/her to make sure they have no problem with it then I will make a project.

epophoto’s picture

Now available as a sandbox project here: https://drupal.org/sandbox/epo/2202473

knalstaaf’s picture