docusaurus/packages/docusaurus-plugin-google-an.../src/analytics.js
Endi 046a53ebf4
perf(v2): more performant gtag and analytics plugin (#2070)
* perf(v2): more performant gtag and analytics plugin

* more spec compliant

* optimize n refactor

* typo

* review
2019-12-01 19:55:21 +07:00

23 lines
652 B
JavaScript

/**
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
export default (function() {
if (typeof window === 'undefined') {
return null;
}
return {
onRouteUpdate({location}) {
// Set page so that subsequent hits on this page are attributed
// to this page. This is recommended for Single-page Applications.
window.ga('set', 'page', location.pathname);
// Always refer to the variable on window in-case it gets overridden elsewhere.
window.ga('send', 'pageview');
},
};
})();