Tracking
Astro user identification
Tell analytics who signed in to your Astro app, after consent, so one person's visits on every device make one profile.
Updated
In Astro, call identify with your own user id once the person is signed in, in a script on a page that knows the user. It works only after consent.
How does it look?
src/pages/account.astro
---
const user = Astro.locals.user // however your app keeps the signed-in user
---
<div id="me" data-id={user?.id} data-plan={user?.plan}></div>
<script>
import { identify } from '@nextanalytica/tag'
const el = document.getElementById('me')
if (el?.dataset.id) identify(el.dataset.id, { plan: el.dataset.plan ?? '' })
</script>On sign-out, call reset() from @nextanalytica/tag.
What can you ask your agent?
- "What did user u_4821 do this week?"
- "Which plans do the people who came back belong to?"