Track signups with Node.js and Express
Call identify from your signup route, right after the user is saved.
Before you start
The Chartsy script must already be on every page of your site, including the app where signup happens - it supplies where the visitor came from; this guide only adds the email. See the installation guides.
1Add your secret key
Copy the site's secret key from Settings → Domains in Chartsy and store it as CHARTSY_SECRET_KEY in your server's environment. It never goes in browser code or git.
CHARTSY_SECRET_KEY=your_secret_key2Add the Chartsy helper
One small file that reads the three Chartsy cookies from the request and posts them with the email. Needs Node 18+ for the built-in fetch. Details of the call are in the Identify API reference.
// chartsy.js
const readJson = (raw) => {
try { return JSON.parse(decodeURIComponent(raw || '')) || {}; } catch { return {}; }
};
export async function chartsyIdentify(email, cookies) {
// cookies: a function name => value (Express: n => req.cookies[n];
// Next.js: n => cookies().get(n)?.value)
const first = readJson(cookies('chartsy_attrib'));
const last = readJson(cookies('chartsy_attrib_last'));
try {
await fetch('https://dashboard.chartsy.app/api/attribution/identify/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.CHARTSY_SECRET_KEY}`,
},
body: JSON.stringify({
email,
attribution_first: first,
attribution_last: Object.keys(last).length ? last : first,
visitor_id: cookies('chartsy_visitor_id') || '',
}),
});
} catch (err) {
console.error('Chartsy identify failed', err); // never block signup on analytics
}
}3Call it after the user is saved
In your signup route, after the account exists. Needs cookie-parser so req.cookies is populated.
import { chartsyIdentify } from './chartsy.js';
app.post('/signup', async (req, res) => {
const user = await createUser(req.body); // your code
chartsyIdentify(user.email, (n) => req.cookies[n]); // no await needed
res.redirect('/welcome');
});4OAuth signups (Passport)
Make the same call in your verify callback, only in the branch that creates the user - not on every login.


