For example, let's say you want to embed a snippet of the tag manager into the production environment plus other environments for testing.
In the past I have implemented the following.
<% if Rails.env.production? <%# snippet for production %> <% else %> <%# snippet for other environments %> <% end %>
Hmmm. There was a problem with this.
RAILS_ENV=production
, we don't know what impact it will have elsewhere.What about using environment variables instead?
<%= sanitize ENV[:GTM_HEAD_SNIPPET] %>
Good!