Skip to content

Conversation

@EqualMa
Copy link

@EqualMa EqualMa commented Feb 27, 2020

Summary

In this PR, @vuepress/plugin-google-analytics supports plugin option importScript which specifies how Google Analytics tracking code is imported.

/**
* @type {'webpack'|'head'|'head-alternative'} this option specifies how Google Analytics tracking code is imported
*/
const importScript = options.importScript || 'webpack'

This option accepts one of the following three values:

  1. webpack (default)

    imports the tracking code into webpack through enhanceAppFiles and the code will be transpiled and bundled. This is the behaviour of the current version plugin.

    This works fine, but in google search console, verification via ga tracking code requires the tracking code to be unmodified in <head>. That is why head and head-alternative are introduced, both of which import tracking code directly into <head> of html.

  2. head

    imports the tracking code as described in the_google_analytics_tag

  3. head-alternative

    imports the tracking code as described in alternative_async_tag

Usage:

[
  "@vuepress/google-analytics",
  {
    ga: GA_ID,
    importScript: "head", // default to 'webpack'
  },
]

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

If changing the UI of default theme, please provide the before/after screenshot:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

  • When resolving a specific issue, it's referenced in the PR's title (e.g. fix #xxx[,#xxx], where "xxx" is the issue number)

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome 80.0
  • Firefox
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

Other information:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant