Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Using swetrix tracking as an NPM package

Blue Mouseba156130c795
diff --git a/package.json b/package.json
index a54263c12..6d2c7478b 100644
--- a/package.json
+++ b/package.json
@@ -37,6 +37,7 @@
"redux": "^4.1.1",
"redux-auth-wrapper": "^3.0.0",
"redux-saga": "^1.1.3",
+ "swetrix": "^1.0.3",
"web-vitals": "^1.1.2"
},
"scripts": {
diff --git a/public/index.html b/public/index.html
index a5077006e..7b97f75f9 100644
--- a/public/index.html
+++ b/public/index.html
@@ -13,17 +13,9 @@
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>Swetrix Analytics</title>
- <script src="https://cdn.jsdelivr.net/gh/Swetrix/swetrix-js@main/dist/swetrix.js" defer></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
-
- <script>
- document.addEventListener('DOMContentLoaded', () => {
- swetrix.init('STEzHcB1rALV')
- swetrix.trackViews()
- })
- </script>
</body>
</html>
diff --git a/src/index.js b/src/index.js
index 682dbf20d..5cfa60b5f 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,6 +4,7 @@ import { BrowserRouter } from 'react-router-dom'
import { store } from 'redux/store'
import { Provider } from 'react-redux'
import { transitions, positions, Provider as AlertProvider } from 'react-alert'
+import * as Swetrix from 'swetrix'
import * as Sentry from '@sentry/react'
import { Integrations } from '@sentry/tracing'
import 'billboard.js/dist/billboard.min.css'
@@ -14,6 +15,12 @@ import App from './App'
import reportWebVitals from './reportWebVitals'
import './index.css'
+Swetrix.init('STEzHcB1rALV', {
+ debug: true,
+})
+
+Swetrix.trackViews()
+
Sentry.init({
dsn: 'https://[email protected]/5865898',
integrations: [new Integrations.BrowserTracing()],