Skip to content

Instantly share code, notes, and snippets.

@homm
Created March 3, 2017 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homm/b2d8e6a5f35811084894106f421d1f58 to your computer and use it in GitHub Desktop.
Save homm/b2d8e6a5f35811084894106f421d1f58 to your computer and use it in GitHub Desktop.
window.getDevicePixelRatio = function () {
var ratio = 1;
// To account for zoom, change to use deviceXDPI instead of systemXDPI
if (window.screen.systemXDPI !== undefined && window.screen.logicalXDPI !== undefined && window.screen.systemXDPI > window.screen.logicalXDPI) {
// Only allow for values > 1
ratio = window.screen.systemXDPI / window.screen.logicalXDPI;
}
else if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
}
return ratio;
};
ga('create', '{{ settings.GOOGLE_ANALYTICS_TRACKING_ID }}', 'auto', opt_configObject);
ga('set', 'dimension2', getDevicePixelRatio().toFixed(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment