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!

track some additional events & metafields

Blue Mouse73c377b6ba65
diff --git a/app/pages/Blog/Post.tsx b/app/pages/Blog/Post.tsx
index 50b38710d..f5cfe2f3e 100644
--- a/app/pages/Blog/Post.tsx
+++ b/app/pages/Blog/Post.tsx
@@ -1,6 +1,7 @@
-import React from 'react'
-import { Link, useLoaderData } from '@remix-run/react'
+import React, { useEffect } from 'react'
+import { Link, useLoaderData, useLocation } from '@remix-run/react'
import NotFound from 'pages/NotFound'
+import { trackPageview } from 'utils/analytics'
interface IPost {
slug: string
@@ -14,8 +15,24 @@ interface IPost {
}
export default function PostSlug() {
+ const location = useLocation()
const post = useLoaderData() as IPost
+ useEffect(() => {
+ const meta = post.author
+ ? {
+ author: post.author,
+ }
+ : undefined
+
+ trackPageview({
+ payload: {
+ pg: location.pathname,
+ meta,
+ },
+ })
+ }, [post, location])
+
if (!post) {
return <NotFound />
}
diff --git a/app/pages/Project/View/ViewProject.tsx b/app/pages/Project/View/ViewProject.tsx
index 832e777b7..e755196c7 100644
--- a/app/pages/Project/View/ViewProject.tsx
+++ b/app/pages/Project/View/ViewProject.tsx
@@ -194,6 +194,7 @@ import NoErrorDetails from './components/NoErrorDetails'
import WaitingForAnError from './components/WaitingForAnError'
import NoSessionDetails from './components/NoSessionDetails'
import { ICustoms, IParams, IProperties, ITrafficLogResponse } from './interfaces/traffic'
+import { trackCustom } from 'utils/analytics'
const SwetrixSDK = require('@swetrix/sdk')
const CUSTOM_EV_DROPDOWN_MAX_VISIBLE_LENGTH = 32
@@ -2490,6 +2491,7 @@ const ViewProject = ({
}
try {
+ trackCustom('TRAFFIC_FORECAST')
const result = await getChartPrediction(chartData, periodToForecast, timeBucket)
const transformed = transformAIChartData(result)
setProjectForcastCache(id, transformed, key)
@@ -3716,6 +3718,10 @@ const ViewProject = ({
return
}
+ trackCustom('DASHBOARD_EXPORT', {
+ type: item.label === t('project.asCSV') ? 'csv' : 'extension',
+ })
+
item.onClick(panelsData, t)
}}
chevron='mini'
diff --git a/app/pages/UserSettings/UserSettings.container.tsx b/app/pages/UserSettings/UserSettings.container.tsx
index 9f316a06a..9c95e6b77 100644
--- a/app/pages/UserSettings/UserSettings.container.tsx
+++ b/app/pages/UserSettings/UserSettings.container.tsx
@@ -49,7 +49,9 @@ const mapDispatchToProps = (dispatch: AppDispatch) => ({
}),
),
() => {
- trackCustom('ACCOUNT_DELETED')
+ trackCustom('ACCOUNT_DELETED', {
+ reason_stated: deletionFeedback ? 'true' : 'false',
+ })
onSuccess()
},
deletionFeedback,
diff --git a/app/utils/analytics.ts b/app/utils/analytics.ts
index cb82a5f45..65e10b565 100644
--- a/app/utils/analytics.ts
+++ b/app/utils/analytics.ts
@@ -104,53 +104,71 @@ Swetrix.init(SWETRIX_PID, {
devMode: isDevelopment,
})
-const trackViews = () => {
- if (!isSelfhosted) {
- Swetrix.trackViews({
- callback: ({ pg, prev, ref }) => {
- const result = {
- pg,
- prev,
- ref,
- }
-
- result.pg = getNewPath(pg)
- result.prev = getNewPath(prev)
-
- if (checkIgnore(ref, REFS_TO_IGNORE)) {
- result.ref = undefined
- }
-
- return result
- },
- heartbeatOnBackground: true,
- })
+const BLOG_PAGE_REGEX = /^\/blog\/.+$/
+
+export const trackViews = () => {
+ if (isSelfhosted) {
+ return
}
+
+ Swetrix.trackViews({
+ callback: ({ pg, prev, ref }) => {
+ const result = {
+ pg,
+ prev,
+ ref,
+ }
+
+ if (pg && BLOG_PAGE_REGEX.test(pg)) {
+ return false
+ }
+
+ result.pg = getNewPath(pg)
+ result.prev = getNewPath(prev)
+
+ if (checkIgnore(ref, REFS_TO_IGNORE)) {
+ result.ref = undefined
+ }
+
+ return result
+ },
+ heartbeatOnBackground: true,
+ })
}
-const trackErrors = () => {
- if (!isSelfhosted) {
- Swetrix.trackErrors({
- callback: ({ message, pg }) => {
- if (_includes(message, 'Minified React error')) {
- return false
- }
-
- return {
- pg: getNewPath(pg),
- }
- },
- })
+export const trackPageview = (options: Swetrix.IPageviewOptions) => {
+ if (isSelfhosted) {
+ return
}
+
+ Swetrix.pageview(options)
}
-const trackCustom = (ev: string, meta?: any) => {
- if (!isSelfhosted) {
- Swetrix.track({
- ev,
- meta,
- })
+export const trackErrors = () => {
+ if (isSelfhosted) {
+ return
}
+
+ Swetrix.trackErrors({
+ callback: ({ message, pg }) => {
+ if (_includes(message, 'Minified React error')) {
+ return false
+ }
+
+ return {
+ pg: getNewPath(pg),
+ }
+ },
+ })
}
-export { trackViews, trackCustom, trackErrors }
+export const trackCustom = (ev: string, meta?: Swetrix.TrackEventOptions['meta']) => {
+ if (isSelfhosted) {
+ return
+ }
+
+ Swetrix.track({
+ ev,
+ meta,
+ })
+}
diff --git a/package.json b/package.json
index 09c65a8d4..48b4ea621 100644
--- a/package.json
+++ b/package.json
@@ -65,7 +65,7 @@
"remix-sitemap": "^3.2.0",
"remix-utils": "^7.6.0",
"spacetime": "^7.6.0",
- "swetrix": "^3.2.0",
+ "swetrix": "^3.2.1",
"timezone-soft": "^1.5.2"
},
"eslintConfig": {