Our development process is that we have local dev, live dev and the production. We can remove the tracking code in dev environments. But, without having to remember to add and take away tracking code within the module on every site every time we restore data, how do we specifically track the live domain and not dev's?

I would assume that we use a single domain but this tracks code from the the live development environment as well as production.

So should we use "One domain with multiple subdomains" or "Multiple top-level domains"

...and how to make sure we capture WWW and non-WWW.

Comments

hass’s picture

Status: Active » Fixed

Prepare a drush script and run it on dev.

crutch’s picture

sounds easy enough but drush is not part of our process at this time

crutch’s picture

Status: Fixed » Active
hass’s picture

Status: Active » Fixed

Than you need to change your process.

crutch’s picture

If were up to me I would. Guess will get no help on this one.

ultimateboy’s picture

crutch, the easiest way is to override the variables used by this module in settings.php with something along the following lines:

global $conf;
$conf['googleanalytics_account'] = '';

You can either specify a different ga account or leave it blank which should stop it from firing.

You'll need to wrap this in a condition, but that's a pretty common thing to when working with multiple environments. There are two common methods, the first is to define an apache environment variable which you can use in a switch statement to change various configurations depending on environment (Pantheon does this for example). The second is to include a settings.local.php file at the end of your settings.php and include environment specific configurations there. This then opens up the possibility of checking your settings.php in to git, free of your database credentials of course, which are then re-located (along with other configs such as google analytics) to your settings.local.php.

Of course, a drush script and a scripted deployment process could do this as well, but thought I'd share my methods for achieving this.

Food for thought.

crutch’s picture

thanks UB! That gives me some goods to move forward here.

Status: Fixed » Closed (fixed)

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

interestingaftermath’s picture

Issue summary: View changes

Following the example of the solution in #6, I wrote this little one liner that you can use from command prompt. Just cd into the default directory and run this. It will add the line compatible with Drupal 7 to the end of the settings.php file.

echo $'\r'$'\r'"# Disable Google Analytics on local environment"$'\r'"\$conf['googleanalytics_account'] = '';" >> settings.php
kopeboy’s picture

Title: Live Development & www vs. non www » Automatic disabling on DEV environment
Version: 7.x-1.3 » 7.x-2.1
Priority: Minor » Normal
Status: Closed (fixed) » Needs review

The configuration at the Pantheon page you linked is a bit different than in comment #6
They use conf instead of vars, like this:

if (PANTHEON_ENVIRONMENT == 'dev') {
    // Google Analytics.
    $conf['googleanalytics_account'] = 'UA-XXXXXXXX-X';
}

Should I use conf or vars now?
Some documentation (on the module page?) would be useful..

hass’s picture

Status: Needs review » Fixed

$conf is correct in settings.php in all releases.

Or you better use drush and delete the variable in DEV.

drush vdel -y googleanalytics_account

I hope this gives you more ideas what typically need to be changed when moving live systems to DEV.

drush cc all
drush vset file_temporary_path C:\xampp\xampplite_php54\tmp
drush vset file_private_path D:\InetPub\wwwroot\example.com\sites\default\private
drush vset cache 0
drush vset block_cache 0
drush vset cache_lifetime 0
drush vset page_cache_maximum_age 0
drush vset page_compression 0
drush vset preprocess_css 0
drush vset preprocess_js 0
drush vdel -y googleanalytics_account
drush en -y --skip devel
drush en -y reroute_email
drush vset reroute_email_enable 1
drush vset reroute_email_address "foo@example.com"
drush vset site_mail "foo@example.com"
drush cc all

Status: Fixed » Closed (fixed)

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

ExTexan’s picture

In case anyone else finds this issue, but are needing the syntax for D8, this worked for us...

$config['google_analytics.settings']['account'] = '';  (or 'UA-XXXXXXXX-X' if you prefer)
newaytech’s picture

does anyone know the syntax here for setting two accounts in config? Wanting to run UA and GA4 at the same time?