Skip to content

@vuepress/google-analytics does not add tracking code as window is undefined? #1286

@daKmoR

Description

@daKmoR
  • I confirm that this is a issue rather than a question.

Bug report

if I am building via vuepress build docs but window is undefined.
not really suprising as it does not run in the browser?
However there is this check

export default ({ router }) => {
  console.log(typeof window);  // undefined
  // Google analytics integration
  if (process.env.NODE_ENV === 'production' && GA_ID && typeof window !== 'undefined') {

from this change a while back:
ca618e4

I'm still not sure why a check for window is there?

Version

every version? I know it worked before so I'm baffled how?

tested in:

$ npm ls vuepress
@open-wc/root@ [...]/open-wc/open-wc
└── vuepress@1.0.0-alpha.37

$ npm ls @vuepress/plugin-google-analytics
@open-wc/root@ [...]/open-wc/open-wc
└── @vuepress/plugin-google-analytics@1.0.0-alpha.37

Steps to reproduce

add to your config.js

  plugins: [
    '@vuepress/google-analytics',
    {
      'ga': 'UA-131782693-1'
    }
  ],

live version:

git clone git@github.com:open-wc/open-wc.git
cd open-wc
npm i
npm run site:build
// search for "google-analytics" in the "_site" folder

What is expected?

tracking via analytics e.g. js tracking code get's inserted

What is actually happening?

no tracking code

Other relevant information

$ node --version
v11.7.0

$ npm --version
6.6.0

$ cat /proc/version:
It is a WSL (Windows Subystem Linux)
Linux version 4.4.0-17134-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) ) #523-Microsoft Mon Dec 31 17:49:00 PST 2018

$ lsb_release -a:
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
  • Is this a global or local install? local
  • Which package manager did you use for the install? yarn or npm didn't matter

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions