Hi,

I just heard about Domain Access and I think about a new feature regarding analytics. Is there a way that on each domain generated by Domain Access a new analytics account could be used. Just like Domain Menu wherein each domain could have different primary and secondary menus.

Thanks a lot.

Comments

hass’s picture

I don't know "Domain Access", but isn't it a multi-site logic? By this way it already works this way.

hass’s picture

Project: Google Analytics » Domain
Version: 5.x-1.4 » 5.x-1.2

Moving this to Domain Access module. What you are requesting here is allow switching of "googleanalytics_account" variable value.

I know there is a possible workaround in GA with custom JS code that switch the ga account number based on domain name. On the other side you could overwrite this variable via settings.php, but i think the Domain Access module should do this variable switching for you like "Localizer" or "i18n".

I see Domain Access only as a hack and I'm sure - if you cannot develop modules and themes yourself, this is the wrong module for you. The Domain Access maintainers should support you here, but the GA module is not going to implement core hacks.

hass’s picture

Title: Analytics and Domain Module integration » Add domain based variable switching
nonsie’s picture

You can achieve this by using hook_domainconf. There's more on it here: http://drupal.org/node/242453. I added this to one of my sites and it works without any problems.

agentrickard’s picture

Status: Active » Closed (works as designed)

nonsie is correct. hook_domainconf() supports this integration. It can either be added to the Google Analytics module, or included inside a custom domain_conf.inc file.

Since this is not a core Drupal feature, I will not be adding it to the Domain Access release directly.

See http://therickards.com/api/function/hook_domainconf/Domain

amariotti’s picture

This info is all great, but it would be nice to see exactly what the function should look like for the Google Analytics Accounts to work on different domains independently. Does someone have the function that can be posted here. With analytics becoming so popular something like this could be very beneficial to have documented somewhere permanently. Thanks!

nonsie’s picture

Actually if you just need statistics by subdomain you can use a single Google Analytics account and use Google Analytics advanced segments. That's the route we decided to go.

amariotti’s picture

Good to know! Thanks.

jamesfk’s picture

Hi amariotti,

I got this to work with the following code in domain_conf.inc as my clients wanted separate accounts for each of their domains - good luck!


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

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

  $form['account']['googleanalytics_account'] = array(
    '#type' => 'textfield',
    '#title' => t('Google Analytics account number'),
    '#default_value' => variable_get('googleanalytics_account', '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 Go
ogle Analytics account next to the appropriate profile on the <strong>Analytics Settings</strong> page, then select <strong>C
heck 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;
}

agentrickard’s picture

The solution in #9 is the correct implementation of the API. (Though I would change 'account' to 'google_analytics' in the $form arrays.) This should work for D5 or D6.

Nice work.

amariotti’s picture

Wow jamesfk, thanks so much! I will give this a shot once I get SMB access to my webserver again.

amariotti’s picture

Well, I added the code above to my domain_conf.inc file in /sites/all/modules/domain/domain_conf. Is that where I should be adding that file? I made the changes suggested in #10 and here's what mine looks like.

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

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

  $form['account']['google_analytics'] = 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 Go
ogle Analytics account next to the appropriate profile on the <strong>Analytics Settings</strong> page, then select <strong>C
heck 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;
}

After I did this it still retains the changes that I make on any of my domains. What am I missing here?

agentrickard’s picture

Your function is named incorrectly. My comment was a bit vague, I guess.

/**
* 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']['google_analytics'] = 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;
}

amariotti’s picture

Thanks agentrickard!

amariotti’s picture

So... now I'm seeing the Analytics Code field on my Domain Settings page but it's not actually working. I changed the account number on one of my domains and went and loaded the page and viewed the source and it's still showing the Account Code for the primary domain. What gives?

agentrickard’s picture

Did you follow the instructions for installing Domain Conf?

Are you viewing cached pages?

agentrickard’s picture

Title: Add domain based variable switching » Domain based variable switching
Category: feature » support
Status: Closed (works as designed) » Active

Bump status on active issues, please.

amariotti’s picture

Title: Domain based variable switching » Add domain based variable switching
Category: support » feature
Status: Active » Closed (works as designed)

I just took another look at this again this morning and after uninstalling the Google Analytics Module and re-installing it now the analytics code snippet doesn't show up at all on any of my pages. When I go to Site Configuration it shows the "UA-" which proves to me that without a code in there the module doesn't work in the first place. Can anybody shed any more light on this? This is really weird.

nonsie’s picture

Just my 2 cents - I was doing it on 6.x version a while back (using custom snippet in domain_conf). However after we decided the scrap this feature the variables created by the snippet were still in the db and getting loaded on pages even though we had changed it to a single GA account.
So, when you uninstall Google Analytics make sure you remove all variables in the db, not just for the default domain. If nothing else it will make debugging easier.

amariotti’s picture

Title: Add domain based variable switching » Domain based variable switching
Version: 5.x-1.2 » 6.x-2.0-rc5

Thanks for the advice nonsie. When I uninstalled the module and reinstalled it I went back to the Site Config page to see if it was empty and it was. There's something that I'm missing here... arg...

agentrickard, I just read through the installation stuff on the rc5 and it is installed correctly. And I also cleared my cache on Safari to see if that was my problem and still the same result. Is this working for everyone else?

amariotti’s picture

Category: feature » support
Status: Closed (works as designed) » Active

Fixing what I messed up.

agentrickard’s picture

Do the keys that you save using Domain Conf get stored and shown back on the domain configuration form? These are stored in the {domain_conf} table and loaded per domain. If empty, the domain should use the site default.

batigolix’s picture

creating segments in google analytics is a far better solution than making changes to the module

amariotti’s picture

#22: Yes, the GA key does get saved to the domain configuration page.

#23: While it might be a better solution for one person, it might not be for another. I'd like to keep my accounts separate to make reporting much easier. My main concern was to keep the secondary sites away from the main site. Not a huge deal, but it is the way I'd like it to be configured, and it sounds like we're really close with our solution here.

agentrickard’s picture

Perhaps a caching issue? Also, be sure that the variable is named correctly.

amariotti’s picture

I tried it on multiple computers/browsers and still get the same thing. Not sure what's going on here, but it's kind of frustrating.

Here's my 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']['google_analytics'] = 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;
}
agentrickard’s picture

In between #9 and #12 you transposed the variable name incorrectly and we didn't catch it.

The proper name of the variable seems to be 'googleanalytics_account', so you need:

  ...
  $form['googleanalytics']['googleanalytics_account'] = array(
  ...
amariotti’s picture

Excellent! Thank you SOOOOO much! I'm going to go and blog about this for those who want to do this in the future.

agentrickard’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

amariotti’s picture

Version: 6.x-2.0-rc5 » 6.x-2.0-rc6
Status: Closed (fixed) » Active

With the most recent "6.x-2.0-rc6" this appears to still be working, but for some reason when you save the settings page it defaults back to displaying "UA-" in the Google Analytics Code field. Any ideas why this would be happening? As I said before, the feature still works but for some reason the settings page isn't displaying the saved code on each individual domain settings page.

awolfey’s picture

subscribe

agentrickard’s picture

Status: Active » Closed (fixed)

This has been cleaned up signifcantly in rc7.

lets open a new issue if this recurs.

amariotti’s picture

Just updated, and I'm still seeing the "UA-" show up as the default.

agentrickard’s picture

lets open a new issue if this recurs.

With details.

newbie999’s picture

Hello nonsie. I tried the route you suggested - 1 google analytics account for my main domain and its subdomains. However, when I go to my google analytics reports and add advanced segments by 'domain' (specifically, by sub1.domain.com, sub2.domain.com), no data is reported. Would you be able to point me in a direction where I can get a clue as to why google analytics is not seeing any subdomain data? I use the domain access module and I have configured all domains to use the same google analytics account.

Thank you so much for any help you can provide.