Enrich Every Segment identify() Call with Email Risk Data

Segment sits at the center of your data stack. Every identify() call flows through it — and if you enrich those calls with email risk signals at the source, every downstream destination (your data warehouse, ad platforms, CRMs, email tools) automatically receives the enriched data without any additional integration work.

How it Works

Segment's Destination Functions let you run custom JavaScript before forwarding events. Add an Emailyze check inside onIdentify, and the enriched traits propagate to every connected destination.

// Segment Destination Function
async function onIdentify(event, settings) {
  const email = event.traits?.email;
  if (!email) return;

  let riskData = {};
  try {
    const resp = await fetch(
      `https://api.emailyze.xyz/v1/check/?email=${encodeURIComponent(email)}`,
      {
        headers: { "X-API-Key": settings.apiKey },
        signal: AbortSignal.timeout(3000),
      }
    );
    if (resp.ok) riskData = await resp.json();
  } catch {
    // Fail open — forward event without enrichment on error
  }

  return {
    ...event,
    traits: {
      ...event.traits,
      emailyze_risk_score: riskData.risk_score ?? null,
      emailyze_is_disposable: riskData.is_disposable ?? null,
      emailyze_provider_type: riskData.provider_type ?? null,
    },
  };
}

Add your Emailyze API key as a Function Setting named apiKey. Every identify() call that includes an email will be enriched automatically.

What Flows Downstream

Once enriched, the three new traits appear everywhere Segment sends data:

| Destination | How to use the data | |-------------|---------------------| | Data warehouse (BigQuery, Snowflake, Redshift) | emailyze_risk_score appears in the users table — query disposable rates over time | | HubSpot / Salesforce | Risk score appears as a contact property — use in lead scoring and workflows | | Klaviyo / Mailchimp | emailyze_is_disposable drives suppression — automatically exclude from campaigns | | Facebook / Google Ads | Exclude disposable-flagged users from Custom Audiences and lookalike seeds | | Amplitude / Mixpanel | Segment by email quality — compare retention of real vs disposable users |

Setting Up the Destination Function

1. In Segment, go to Connections → Catalog → Functions → New Function 2. Select Destination and paste the code above 3. Under Settings, add a setting called apiKey (type: string, sensitive: true) 4. Enter your Emailyze API key from the dashboard 5. Connect the function to your sources

Audience Segmentation

Once the traits are in your warehouse or analytics tool, build segments:

These audiences feed directly into ad suppression lists, email campaign segments, and churn analysis cohorts.

Requirements