Any ideas on how to implement Mixpanel analytics through segment.io, that can track for all production and non-production environments.
Right now I have created 3 different projects (dev, staging and production) on both mixpanel & segment.io. And traking them. But when I'm changing dev code and pushing to staging and prouction, it overwrites analytics main code.
I am not using ruby....I'm using javascript. Any suggestions? Will a config file that substitutes token work?
Thanks. I did some research. I do have a simpler way of implementing this if someone is not familiar with config files or not having access to those files.
I can have a if condition that I can use when initializing segment i/o.
var apikey;
if (window.location.host === "dev.xyz.com") {
apikey = <api_key>;
} else if (window.location.host === "staging.xyz.com") {
apikey = <api_key>;
} else if (window.location.host === "prod.com") {
apikey = <api_key>;
}
analytics.load(apikey);
Replace with respective api_keys from segment I/o . This works well.
A config file that substitutes tokens is the perfect solution.
You'll want to do something like this in the javascript snippet:
analytics.load("<%= config.segmentio.apiKey %>");
Where config is your dev settings on your dev machine, and staging/prod settings on staging and prod.
I would suggest that as part of your build step , you bake in a configuration variable that identifies the environment which your code is running inside - eg ['Dev', 'Staging', 'Production']
.
You would then do something similar to what @monical has suggested except without using URL's in the mix:
var token;
switch(environment) {
case 'Staging':
token = 'TOKEN_STAGE';
break;
case 'Production':
token = 'TOKEN_PROD';
break;
default:
token = 'TOKEN_DEV';
}
analytics.load(token);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.