mardi 8 novembre 2016

Enable GA and other trackers only for production when assets are prebuilt with webpack

I'm shipping frontend application I want to track stats for (GA and other trackers). The app is prebuilt with webpack on CI and I'd like to have the same bundle to be shipped to both staging and prod environments. But there is an issue with that: if I enable trackers during build time they'll be enabled on both envs.

One way I see is to add set window.enableTrackers = true flag in index.html when sending app code from server and then decide whether to install trackers or not, but it seems to be pretty ugly solution.

Is there any other way u use to do it? Checking domain name on the client maybe? Something like:

if(document.location.hostname === 'prod.example.com') {
  // enable trackers
}




Aucun commentaire:

Enregistrer un commentaire