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:
Lane Goolsby 2022-06-02 03:47:52 -07:00 committed by GitHub
parent f25ee0cbf5
commit 1efcfc4671
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 13 deletions

View file

@ -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');