mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-30 01:17:07 +02:00
feat(analytics): allow query/hash changes to be sent to GA (#7545)
Co-authored-by: Lane Goolsby <lanegoolsby@rocketmortgage.com>
This commit is contained in:
parent
f25ee0cbf5
commit
1efcfc4671
2 changed files with 18 additions and 13 deletions
|
@ -9,10 +9,19 @@ import type {ClientModule} from '@docusaurus/types';
|
|||
|
||||
const clientModule: ClientModule = {
|
||||
onRouteDidUpdate({location, previousLocation}) {
|
||||
if (previousLocation && location.pathname !== previousLocation.pathname) {
|
||||
if (
|
||||
previousLocation &&
|
||||
(location.pathname !== previousLocation.pathname ||
|
||||
location.search !== previousLocation.search ||
|
||||
location.hash !== previousLocation.hash)
|
||||
) {
|
||||
// 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);
|
||||
window.ga(
|
||||
'set',
|
||||
'page',
|
||||
location.pathname + location.search + location.hash,
|
||||
);
|
||||
// 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