Skip to content

Identity & Attribution

B2B SaaS

Connect Auth0 sign-ups to ad spend and Stripe revenue

Push verified Auth0 user_id records from a post-login Action into Apex with a 1.5-second timeout and fallback so every sign-up reconciles to prior ad visits and Stripe billing.

One Post-Login Action with fail-open timeout safety.

6 min read10 min setupUpdated
Two SaaS engineers sketching an Auth0 login flow with colored index cards on a bright studio whiteboard.
One Auth0 Post-Login Action bridges first sign-ups and returning logins directly into Apex without adding login risk.

Auth0 Post-Login Action simulator

Trace how Auth0 sign-ups and logins reconcile to revenue

Test first login vs returning login, toggle staging vs production tenants, and simulate a timeout to see why logins never stall.

Illustrative B2B SaaS · Auth0 Universal Login + Stripe
$65,000
ApexApex · Live Playbook Simulator

Verified monthly revenue

$65,000

100% reconciled to commerce / CRM

Discovery channel credit

$37,700

+$27,300 vs last-click

Branded search / direct credit

$9,750

15% of closed revenue

Revenue credit by funnel role

Touchpoint roleLast-clickSelected modelDifference
First discovery (ads, posts, QR)$10,400$37,700+$27,300
Mid-funnel nurture (email, retargeting)$15,600$17,550+$1,950
Final branded search / direct$39,000$9,750-$29,250

Credit restored to discovery touches

$37,700

Full multi-touch path kept on one stitched customer timeline

  • Switch attribution models in one click without re-tagging links or re-importing orders.
  • Compare first-touch, linear, time-decay, and last-touch on the exact same revenue.

Stitched buyer journey

  1. Day 1Discovery touch capturedFirst touch

    Apex stores first-touch source on the visitor ID.

  2. Day 11Email click + identity stitchStitched

    Visitor signs up; anonymous session merges onto the customer record.

  3. Day 19Direct checkout closesVerified

    Revenue credits cleanly across the chosen attribution model.

The complete playbook

Step-by-step setup, worked math, and real limits.

Steps, technical details, and live pricing.

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

Software architect and product lead discussing user onboarding stages over a printed flow chart at a bright studio table.
Separating first-time logins from returning sessions lets onboarding journeys fire once without double-counting sign-ups.

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:

  1. Deterministic sign-up deduplication: Passing eventId: "signup-" + event.user.user_id when event.stats.logins_count === 1 guarantees a retried first login never counts as two sign-ups or fires a welcome journey twice.
  2. Stable reconciliation key: Auth0's user_id becomes internal_user_id in Apex, so even if a customer later changes their billing email in Stripe or switches OAuth providers, Apex keeps their timeline unified.
  3. Automatic profile photos: Forwarding event.user.picture as avatar_url populates real customer photos across Apex with no extra code.
Growth operations lead pinning physical release checklist cards onto a cork wall in a sunlit office.
Tagging staging Auth0 tenants with x-apex-environment keeps QA sign-ups cleanly isolated from live customer cohorts and ad feeds.

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 / scheduleScenario volumeFree allowance / basisRateApex 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 / mo1M / 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)

ExpenseTypical rangeNotes
Auth0 Post-Login ActionsIncluded in Auth0 plansRuns 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.

Verify with your AI agent

Confirm Auth0 sign-up events and environment hygiene via MCP

After deploying your Auth0 Post-Login Action, ask your coding agent to inspect recent sign-up events and confirm staging logins stay isolated from production metrics.

1Add Apex to your editor

Install in Grok Build

Opens Grok Build and adds Apex. Nothing to configure.

2Tell your agent

Prompt for your AI editor

In my Apex workspace, call apex_recent_events to confirm user_signed_up and user_identified events are arriving with userId and country fields, then call get_identity_coverage to check our anonymous-to-known stitch rate.

The first time your agent calls Apex, it gives you a link to approve in the browser. There is no key to paste. In Grok Build you can also run /setup-apex.

See how editor setup works step by step

saas-auth · Grok BuildWaiting for approval
Agent
You

Set up Apex in this repo.

Set up Apex · 0 of 4
  • Signed in
  • Workspace named
  • Events arriving
  • Conversion picked
  • Stripe

Your move

Stop losing revenue credit at the Auth0 login redirect.

Stitch every Auth0 user_id back to their first ad click and forward into Stripe billing with one fault-tolerant Action.