Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a doc to teach how to let vitepress work with google analytics #1131

Closed
4 tasks done
Sepush opened this issue Aug 6, 2022 · 7 comments
Closed
4 tasks done

add a doc to teach how to let vitepress work with google analytics #1131

Sepush opened this issue Aug 6, 2022 · 7 comments
Labels
docs Improvements or additions to documentation

Comments

@Sepush
Copy link

Sepush commented Aug 6, 2022

Is your feature request related to a problem? Please describe.

hope to use google analytics with VitePress

Describe the solution you'd like

add a doc to introduce or just do it for the vitepress docs so that we can learn from the code

Describe alternatives you've considered

No response

Additional context

No response

Validations

@brc-dd brc-dd added the docs Improvements or additions to documentation label Aug 6, 2022
@brc-dd
Copy link
Member

brc-dd commented Aug 6, 2022

Refer https://vitepress.vuejs.org/config/app-configs.html#head

You'll need to do something like:

head: [
  ['script', {src: 'https://googletagmanager.com/...'}],
  ['script', {}, `gtag call here`]
]

@Sepush
Copy link
Author

Sepush commented Aug 6, 2022

What does the first script do here

@brc-dd
Copy link
Member

brc-dd commented Aug 6, 2022

It will be given in your analytics console. It loads gtag.js. If you have head like this:

[
  [
    'script',
    { async: '', src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX' }
  ],
  [
    'script',
    {},
    "window.dataLayer = window.dataLayer || [];\nfunction gtag(){dataLayer.push(arguments);}\ngtag('js', new Date());\ngtag('config', 'G-XXXXXXXXXX');"
  ]
]

Then this will be rendered:

<script async='' src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>

@Sepush
Copy link
Author

Sepush commented Aug 6, 2022

I got it!
Thank you for your patience.

@Zhengqbbb
Copy link
Contributor

Zhengqbbb commented Mar 9, 2023

update:

  [
    'script',
-   { async: true, src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX' }
+   { async: '', src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX' }
  ]

Get the real header like:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

@jasonraimondi
Copy link

update:

  [
    'script',
-   { async: true, src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX' }
+   { async: '', src: 'https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX' }
  ]

Get the real header like:

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

In my testing on vitepress@1.0.0-beta.1, passing an empty string yields the following:

<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

It would be great if booleans were allowed here, since async and defer are "Boolean attributes".

@brc-dd
Copy link
Member

brc-dd commented Jul 14, 2023

<script async="" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>

async, async="", async="any thing" all are equivalent, so that should not be an issue (https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML).

brc-dd added a commit that referenced this issue Jul 14, 2023
x-ref: #1131 (comment), #2607

Co-authored-by: CaptainTeemo <alittlebarney@gmail.com>
@brc-dd brc-dd closed this as completed in 7141b82 Aug 4, 2023
SeniorKyrylo pushed a commit to SeniorKyrylo/VitePress-Vue.js that referenced this issue Aug 11, 2023
x-ref: vuejs/vitepress#1131 (comment), #2607

Co-authored-by: CaptainTeemo <alittlebarney@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants