Adding analytics snippets only ot production build #8773
Answered
by
chenxch
easypay-mrosmane
asked this question in
Help/Questions
-
For my current project (vue3, SPA webapp), I'm required to add js snippets to the application for both Clarity & Mixpanel. I've for now added them to the main index.html fille that is the entry point for the application. However this results in them being loaded while running the app locally. I'm looking for a way satisfy all the below requirements but I have not found it yet.
Any pointers would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Answered by
chenxch
Jul 13, 2023
Replies: 1 comment 1 reply
-
several options
if(import.meta.PRO){
const script = document.createElement('script')
.....
}
// vite.config.js
import { createHtmlPlugin } from 'vite-plugin-html'
createHtmlPlugin({
inject: {
data: {
injectScript: process.env.NODE_ENV === 'production' ? '<script src="/xx/xxx.js"></script>': '',
},
},
}), <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<%- injectScript %>
</head>
<body>
<div id="app"></div>
</body>
</html> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
easypay-mrosmane
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
several options