Module Configuration

You can even use this to set module configuration per-environment. One reason you might do this is to set your Google Analytics Key on production, but leave it blank in development and staging environments.

I'll install and enable Google Analytics real quick just to show you where to find the configuration values for contributed modules.

  • composer require "drupal/google_analytics:^2.0"
  • drush en -y google_analytics

With Google Analytics installed, we can take a look in its module directory for the schema file. So, it'll be in the "drupal-root/modules/contrib/google_analytics/config/schema/" directory and be named "google_analytics.schema.yml"

The "Web Property ID" is at the top of the file, so it'll be pretty easy to get. Here's the pattern:

$config['google_analytics.settings']['account'] = "UA-XXXXXXXX-XX";

I'll enter a fake account number just to test it out.

 * Google Analytics Overrides
$config['google_analytics.settings']['account'] = "UA-99999999-99";

Now, when we refresh the page, we can view source, or search in the inspector window to see the code "UA-99999999-99" is being used.

Commit Updates to Git

We've installed Google Analytics and enabled Twig debugging since our last commit. I'll go ahead and just commit all of these files for the sake of brevity. Normally, I'd make each commit individually so that they could be reverted one-by-one if something went wrong.

git add .
git commit -m "Installed google_analytics and enabled twig debugging"
git push

Awesome! Now, we have a clean working directory in Git, our settings.local.php file is being ignored, we've exported our config to code using Configuration Management and we're overriding select configuration with our settings.local.php file.

At this point, everything is basically setup and we can walk through a typically workflow of installing modules and themes, changing configuration (like creating a view), and overriding configuration in settings.local.php. Then pushing all of that up to production.