Skip to content

On routerMode: "history", Google Analytics plugin may send wrong page value #1374

Open
@rizdaprasetya

Description

@rizdaprasetya

Bug Report

Wrong page path/url value being sent by Docsify's Google Analytics plugins if config used is routerMode: "history".

Steps to reproduce

run/deploy docsify with the following config of history routerMode:

window.$docsify = {
  routerMode: 'history'
};

With Google Analytics plugin enabled

Check the Codesandbox example on the bottom, to see some demo.

What is current behaviour

Due to this line:

window.ga('set', 'page', location.hash);
window.ga('send', 'pageview');

On history routerMode, the location.hash value is always empty string "".
No matter which page visitor open, the value being sent as page is always empty string.

What is the expected behaviour

On history routerMode, the value of third param of window.ga('set', 'page', currentPageValue); should be the proper path of the current page opened by visitor.

Maybe first check what is the value of routerMode, then determine wether to use location.hash or not.

Other relevant information

ref to Google analytics for SPA guide:
https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

  • Your OS: Mac OS, any OS really.
  • Node.js version: any
  • npm/yarn version: any
  • Browser version: any
  • Docsify version: any
  • Docsify plugins: Google Analytics

Please create a reproducible sandbox

Edit 307qqv236

Mention the docsify version in which this bug was not present (if any)

none

Anyway thanks for this amazing project! 🚀

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions