Problem/Motivation

Currently, the google_tag module allows the usage of variable realms, however, if you are using domain access and domain_conf module you won't be able to set values per domain.

Proposed resolution

If Variable Realm isn't active and domain conf is enabled, use the current domain as the realm.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

samt2497 created an issue. See original summary.

samt2497’s picture

samt2497’s picture

samt2497’s picture

Assigned: samt2497 » Unassigned
solotandem’s picture

This is a duplicate issue to #2816177: Make Google Tag work with Domain Access module.

Does the domain variable project provide the necessary realm support for domain? If so, have you tried it? If yes, then what are your reasons for not using it?

Your patch (and all the others for domain) adds special one-off exception code for domain. This seems hardly warranted if the general solution using realms is available to solve the task. Please explain.

samt2497’s picture

This is not a duplicate, this issue address compatibility with domain_conf module which stores variables per domain.

Using a domain variable is not an option if the site is already using domain_conf since the modules aren't compatible.

solotandem’s picture

Please revisit the last paragraph of #5. I am not interested in supporting this one-off exception.

Three options are:

1 -- Convert to using domain_variable (which seems the preferred approach from the domain project home page)
May I assume you have not tried domain_variable module? Have you read #1593548: Migration path from domain_conf and tried migration project? It would appear to convert the variables stored by domain_conf and domain_settings.

2 -- Apply the alterations in your patch to your custom code (or domain_conf)
You can implement hook_google_tag_realm_alter and hook_form[_FORM_ID]_alter for this purpose.

3 -- Apply your patch to this module in your site code base

solotandem’s picture

Status: Needs review » Closed (works as designed)
mycw1991’s picture

For the people who do not wish to wish to migrate from domain_conf,
I would like to share a patch that works with the following contrib https://www.drupal.org/project/domain_google_tag

mycw1991’s picture

titouille’s picture

Hi,

Sorry to re-open this thread but it's just to add my two cents... It seems that like solotandem explains in #7, we can use the hook_google_tag_realm_alter to change the script to use. In my case, with a multilingual / multidomain website, the first realm used is the language (weight 100 against 110 for domain). The module try to load sites/default/files/google_tag/language/google_tag.[current_language].script.js instead of using the "domain" version. After some debug I found this information and hope this can help other to correctly use the module.

My config: domain access, domain conf (yes, it is enabled...) and other domain modules enabled. In domain variables, GTM container ID is checked and I can set each ID by domain. I implemented the hook like this:

function MY_MODULE_google_tag_realm_alter($realm_values) {
  global $_domain;
  $realm_values['name'] = 'domain';
  $realm_values['key'] = $_domain['machine_name'];
}

to force the "domain" realm instead of another and all work perfectly (after a cache clear). GTM now load 'google_tag.[domain_machine_name].script.js' file from sites/default/files/google_tag/domain directory.

I think this kind of information could be added to README.txt to allow non-expert users using the module correctly ;-)

pedrosp’s picture

#11 comment really helped me to solve my issue however I needed to add an "&" to the function values as stated on the api php file.

For clarity:

function MY_MODULE_google_tag_realm_alter(&$realm_values) {
  global $_domain;
  $realm_values['name'] = 'domain';
  $realm_values['key'] = $_domain['machine_name'];
}