How it works without Apex
Add a single Auth0 Post-Login Action that posts to Apex's Server Events API with a 1.5-second timeout and a catch fallback so authentication never stalls. When event.stats.logins_count equals 1, send user_signed_up with a deterministic eventId keyed by Auth0's user_id; on later logins send user_identified so existing accounts reconcile automatically against ad clicks and Stripe revenue.
How Apex does it for you
Apex turns Auth0's stable user_id into internal_user_id, deduplicates retried sign-ups with eventId, maps profile pictures to avatar_url, routes staging Auth0 tenants into dev or beta environments, and connects paid invoices back to the acquisition click.
How to set this up in 5 steps
Generate a workspace server API key in Apex
Open Settings, then API keys in Apex and create a server key starting with apex_sk_. Store it as an encrypted secret named APEX_API_KEY inside your Auth0 Action.
Tag non-production Auth0 tenants with APEX_ENVIRONMENT
On your development or staging Auth0 tenant, add a second secret named APEX_ENVIRONMENT set to dev or beta so QA sign-ups never pollute production counts or ad platform conversions.
Create the Post-Login Action with a 1.5-second timeout
In Auth0 under Actions, Library, create a Login trigger that posts user_signed_up when event.stats.logins_count equals 1 and user_identified on every subsequent login, guarded by AbortSignal.timeout(1500) and a silent catch fallback.
Pass country, avatar_url, and deterministic eventId
Set eventId to signup- plus event.user.user_id on first sign-up so retries count once, forward event.request.geoip.countryCode for regional consent rules, and map event.user.picture to avatar_url.
Deploy to the Login flow and verify in Customers
Attach the Action to your Auth0 Login flow, deploy, and sign in with a test account to confirm the identified record appears under Customers within seconds.
Why Auth0 redirects break attribution
Most SaaS sign-up flows send visitors off your marketing site onto an Auth0 Universal Login page, bounce them through Google or Microsoft OAuth, and drop them into app.yourcompany.com. When browser cookies drop or a buyer switches from their work email on a demo form to a Google account at sign-up, browser-only analytics loses the link between the ad click and the Stripe subscription.
Running identity sync inside an Auth0 Post-Login Action closes that gap on the server. Because Auth0 runs the Action immediately after every successful sign-in (including the very first sign-up), one 35-line function handles new customer creation, returning login reconciliation, and profile photo mapping with zero extra backend endpoints to host.

The Post-Login Action code
In Auth0, open Actions, then Library, and create a custom Login Action using the exact server pattern documented in Connect Auth0:
exports.onExecutePostLogin = async (event) => {
const isSignup = event.stats.logins_count === 1;
await fetch("https://app.apex.inc/api/v1/events", {
method: "POST",
signal: AbortSignal.timeout(1500),
headers: {
"content-type": "application/json",
"x-api-key": event.secrets.APEX_API_KEY,
"x-apex-environment": event.secrets.APEX_ENVIRONMENT ?? "production",
},
body: JSON.stringify({
events: [
{
type: isSignup ? "user_signed_up" : "user_identified",
...(isSignup ? { eventId: `signup-${event.user.user_id}` } : {}),
email: event.user.email,
country: event.request.geoip?.countryCode,
data: {
userId: event.user.user_id,
name: event.user.name,
avatar_url: event.user.picture,
},
},
],
}),
}).catch(() => {});
};Three small details do the heavy lifting here:
- Deterministic sign-up deduplication: Passing
eventId: "signup-" + event.user.user_idwhenevent.stats.logins_count === 1guarantees a retried first login never counts as two sign-ups or fires a welcome journey twice. - Stable reconciliation key: Auth0's
user_idbecomesinternal_user_idin Apex, so even if a customer later changes their billing email in Stripe or switches OAuth providers, Apex keeps their timeline unified. - Automatic profile photos: Forwarding
event.user.pictureasavatar_urlpopulates real customer photos across Apex with no extra code.

Consent, staging, and latency safety
Auth0 waits for Post-Login Actions to finish before completing a login. Keep these three operational rules intact when deploying:
| Safeguard | How it works | Why it matters |
|---|---|---|
| 1.5-second timeout + catch | AbortSignal.timeout(1500) paired with .catch(() => {}) | An Apex hiccup never breaks or delays Auth0 login |
| Environment header | Set APEX_ENVIRONMENT to dev or beta on non-prod Auth0 tenants | Test sign-ups stay out of production metrics and ad platform feeds |
| GeoIP country + consent | Send event.request.geoip?.countryCode (and consent if collected) | Follows Server Events consent rules automatically |
Remember: If your workspace only asks for tracking consent where local law requires it, leavingcountryblank causes Apex to hold sign-ups back from ad platforms. Passing Auth0's built-ingeoip.countryCodesolves that in one line.
What this costs on Apex
Live Apex pricing · Pay-as-you-go
Estimated Apex cost for B2B SaaS app on Auth0 processing 2,400 new sign-ups and 18,000 returning logins per month
$0 / month
Covered by monthly free allowances.
| Apex meter / schedule | Scenario volume | Free allowance / basis | Rate | Apex cost |
|---|---|---|---|---|
Events Auth0 post-login identity and sign-up server events (2,400 first-time sign-ups plus 18,000 returning logins per month) | 20,400 / mo | 1M / month | $5 per 100K events | $0 |
Stripe billing sync and Apex attribution modeling run automatically once Auth0 user records arrive. History: 13 months no card, 3 years with card, 7 years once you've paid an invoice. Live pricing.
Third-party and campaign costs (not paid to Apex)
| Expense | Typical range | Notes |
|---|---|---|
| Auth0 Post-Login Actions | Included in Auth0 plans | Runs inside your existing Auth0 authentication pipeline with zero separate hosting |
Auth0 Actions execute inside your existing Auth0 plan, and Apex meters only the incoming server events on standard Web Measurement with zero per-seat fees or separate identity add-on charges.
