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?
Comment | File | Size | Author |
---|---|---|---|
#42 | domain_analytics-7.x-1.1.zip | 1.16 KB | epophoto |
#25 | domain_analytics_d7.zip | 2.35 KB | agentrickard |
#19 | domain_analytics.tar_.gz | 735 bytes | davidwhthomas |
#9 | ui.jpg | 10.08 KB | matteoraggi |
#4 | 547390-domain-conf-d5.patch | 1.82 KB | agentrickard |
Comments
Comment #1
agentrickardIt 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.
Comment #2
agentrickardNope, this is a bug in domain conf. This patch should fix it. Apply from the root domain directory.
Comment #3
yt2s CreditAttribution: yt2s commentedWorked 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.
Comment #4
agentrickardYes, the patch is against HEAD, so this is fine.
Committed to HEAD. D5 version attached and needs a test.
Comment #5
matteoraggi CreditAttribution: matteoraggi commentedIt will be on 6.x-2.0-RC10 ?
Comment #6
agentrickardIt is already in rc9. There will be no rc10, just a 6.x.2.0 final.
Comment #7
matteoraggi CreditAttribution: matteoraggi commentedNice 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.?
Comment #8
croryx CreditAttribution: croryx commentedIt 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.
Comment #9
matteoraggi CreditAttribution: matteoraggi commentedI'm using rc9 without patch and I can't find it in UI, I have attached what I see on this page.
Comment #10
croryx CreditAttribution: croryx commentedI may have misread your original comment, sorry. You do need the domain_conf.inc file above for this to work.
Comment #11
agentrickardYou have to implement the hook yourself, or convince the Google Analytics maintainer to put it in the module.
Comment #12
matteoraggi CreditAttribution: matteoraggi commentedI have done it now, with my bad english:
http://drupal.org/node/574930
Comment #13
agentrickardD5 does not pass in the null option, so this is done.
Comment #15
matteoraggi CreditAttribution: matteoraggi commentedI 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 .
Comment #16
agentrickardFor reference, in DA 6.x.2, here's how to add Google Analytics properly:
This only allows you to change the key per domain. You could add additional settings as well.
Comment #17
davidwhthomas CreditAttribution: davidwhthomas commentedThanks, this D6 approach works perfectly.
Comment #18
seanBPerfect! thnx..
Comment #19
davidwhthomas CreditAttribution: davidwhthomas commentedFollowing 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.
Comment #20
tevans CreditAttribution: tevans commentedConfirmed. Just installed and working as expected. Thanks!
Comment #21
hawkdrupal CreditAttribution: hawkdrupal commentedOne 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.
Comment #22
jamesHF CreditAttribution: jamesHF commentedhawkdrupal, 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)
Comment #23
davidwhthomas CreditAttribution: davidwhthomas commented@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
Comment #24
chirale CreditAttribution: chirale commentedTested #19, it works fine, thanks davidwhthomas!
Note: please add "domain_conf" to dependencies on the .info. It cannot works without it! ;-)
Comment #25
agentrickardHere's a D7 version, which works almost without modification.
Comment #26
barber75 CreditAttribution: barber75 commentedHey,
Gonna check out Domain Analytics, sounds good! Thanks for the hard work...
cheers
Craig
Comment #27
jillpadams CreditAttribution: jillpadams commentedHas 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?
Comment #28
petednz CreditAttribution: petednz commentedNot seeing any comments about this - so just before I throw it in, can you clarify 'almost' in the statement "works almost without modification'
Comment #29
iaminawe CreditAttribution: iaminawe commented@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.
Comment #30
bcobin CreditAttribution: bcobin commented+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!
Comment #31
bcobin CreditAttribution: bcobin commentedChanging 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!
Comment #32
agentrickardNot really RTBC. I have no intention of maintaining this code. Someone else needs to start a project for it.
Comment #33
agentrickardComment #34
pedrospAnother way to go:
Domain + Variable + Domain Variable + Google Analytics
(+ little modif. hopefully soon commited) http://drupal.org/node/1702522#comment-6746318
Comment #35
jsi CreditAttribution: jsi commentedI 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.
Comment #36
pedrospHave 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
Comment #37
jsi CreditAttribution: jsi commentedThanx 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
Comment #38
Jawi CreditAttribution: Jawi commentedSame issue here. Thanks for the url. http://drupal.org/node/595520
Very usefull!!
Comment #39
pedrospI 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... ;)
Comment #40
shaysmith CreditAttribution: shaysmith commentedTo 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.
Comment #41
Drupa1ish CreditAttribution: Drupa1ish commentedIn 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()
Comment #42
epophoto CreditAttribution: epophoto commentedAttaching 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.
Comment #43
epophoto CreditAttribution: epophoto commentedNow available as a sandbox project here: https://drupal.org/sandbox/epo/2202473
Comment #44
knalstaaf CreditAttribution: knalstaaf commented… and as a project by now: https://www.drupal.org/project/domain_analytics