Comments (9)
Hey!
We're currently working on server-side events and they are already available on the beta package.
npm i @vercel/analytics@beta
.
After that it should work like that:
import { track } from "@vercel/analytics/server"
// pages/some-route.js
export async function getServerSideProps(ctx) {
if (await shouldRedirect()) {
await track("Redirecting", {
destination: "",
}, {
headers: ctx.req.headers
})
return {
destination: 'https://my.destination',
permanent: false
}
}
return {
props: {}
}
}
Be sure to pass the headers to track, this will link the custom event to the pageviews from the users before.
Let me know if that works!
from analytics.
After that it should work like that:
@tobiaslins Thanks for your reply! The track feature looks good, but let me be more clear about my question. I'm not trying to track a "Redirecting" event, but to track the visit to this "/some-route" path, so that it's counted in the Web Analytics visitors/pageviews chart.
How am I supposed to do that?
from analytics.
Oh sorry, I misunderstood this. The visit to the /some-route
path is automatically tracked by Web Analytics (we track all pages that are visited by the client automatically)
Are you not seeing it on the dashboard?
from analytics.
Are you not seeing it on the dashboard?
No, I'm not seeing it on the dashboard.
The visit to the
/some-route
path is automatically tracked by Web Analytics (we track all pages that are visited by the client automatically)
Let me make this clear...IIUC the tracking is done by using @vercel/analytics
in Next.js app. Do you mean that it's actually handled by the Vercel server so using Vercel Analytics SDK is not even required? (That doesn't explain me not seeing it on dashboard though)
from analytics.
Sorry for not being clear. @vercel/analytics
is still required and does the automatic pageview tracking when adding <Analytics />
component to your layout/app.tsx.
Where have you placed the component?
from analytics.
Sorry for not being clear.
@vercel/analytics
is still required and does the automatic pageview tracking when adding<Analytics />
component to your layout/app.tsx. Where have you placed the component?
I placed <Analytics />
in pages/_app.tsx
as the documentation says (I'm not using app dir) and it tracks pageviews as expected. What I'm looking for with this issue is how to track pageview in redirect routes, where the client React app does not even render?
from analytics.
Oh, so instead of
await track("Redirecting", {
destination: "",
}, {
headers: ctx.req.headers
})
you would want to do something like pageview("/redirected-route")
from the server?
We don't support this yet, but could also be added most probably!
from analytics.
you would want to do something like
pageview("/redirected-route")
from the server?
That's right. I want to track users' visits to this /some-route
path, where they will be redirected to another destination - this is done in getServerSideProps
thus /some-route
does not render a client-side page. Not to track the destinations they are redirected to.
We don't support this yet, but could also be added most probably!
Alright I'll keep an eye on this.
from analytics.
Would also be interested in this functionality. Assume it's still not available?
from analytics.
Related Issues (20)
- Error 400 when using analytics/server track in server actions HOT 2
- Vercel build failed with Turborepo and multiple apps deployed HOT 5
- Vercel Analytics Endpoints HOT 1
- Docs: Specify if `track` runs in development mode or not HOT 1
- Page changes are no longer tracked in SvelteKit 2 HOT 9
- Feature Request: Allow nonce as optional prop in analytics component for content security policy HOT 1
- Integration with Docusaurus HOT 1
- Module resolution warnings under Yarn PnP: `Unable to resolve path to module '@vercel/analytics/react'.eslintimport/no-unresolved` HOT 5
- City-Level analytics HOT 3
- CJS files are missing in 1.2.0 HOT 10
- Feature request: Exports HOT 3
- Cannot install the latest version of `@vercel/analytics` with `[email protected]` HOT 2
- Vercel Analytics being blocked by AdBlockers HOT 1
- SvelteKitError: Not found: /_vercel/insights/script.js with playwright/test HOT 2
- Use process.env.ASSET_PREFIX when sending tracking data #63 HOT 1
- Version Compatibility
- CORS errors HOT 1
- script.js doesn't load with Next.js Dyamic Routes? [Error on build only] HOT 2
- unclear how to view and export custom events + properties? HOT 1
- Access-Control-Allow-Origin header won't attached when reverse-proxying
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from analytics.