mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-30 01:17:07 +02:00
refactor(plugin-google-gtag, plugin-google-analytics): migrate packages to TS (#5561)
* migration * Move to devDeps * Use type assertion
This commit is contained in:
parent
2ef70cb806
commit
19b27ef73b
13 changed files with 128 additions and 30 deletions
25
packages/docusaurus-plugin-google-analytics/src/analytics.ts
Normal file
25
packages/docusaurus-plugin-google-analytics/src/analytics.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
||||
export default (function () {
|
||||
if (!ExecutionEnvironment.canUseDOM) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
onRouteUpdate({location}: {location: 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');
|
||||
},
|
||||
};
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue