Skip to content

Instantly share code, notes, and snippets.

@barzik
Created December 20, 2018 13:24
Show Gist options
  • Save barzik/dce35bba7adad346c1a233893cb92c04 to your computer and use it in GitHub Desktop.
Save barzik/dce35bba7adad346c1a233893cb92c04 to your computer and use it in GitHub Desktop.
How to load Google Analytics without Google script with webpack
const analyticsId = 'XX-XXXXXX';
window.ga = window.ga || ((...args) => (ga.q = ga.q || []).push(args));
ga('create', `UA-${analyticsId}-Y`, 'none');
const gaLoader = document.createElement('script');
gaLoader.src = 'https://www.google-analytics.com/analytics.js';
gaLoader.async = true;
document.querySelector('head').appendChild(gaLoader);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment