I would like to know how to apply google analytics id for local and production,
I have two ID
's, each for local and production.
I am using node.js
as a backend, and stored the google analytics key in config file using env
file.
How to pass:
- If local, pass google analytics id
ga_local
; - If prod, pass google analytics id
ga_pro
innode.js
in the startup.
.env
ga_local = "UA-XXXX-X",
ga_pro = "UA-YYYY-Y"
config.js
require('dotenv').config();
const config = {
ga_local: process.env.ga_local,
ga_pro: process.env.ga_pro
};
module.exports = config;
front end
<script async src='https://www.googletagmanager.com/gtag/js?id=${ga_local}'></script>