Netlify Connector Setup Guide

The LeadMachine Connector for Netlify connects your Netlify-hosted website to LeadMachine — the static-site counterpart of the WordPress plugin. It works with any framework deployed on Netlify (Astro, Next.js, Hugo, Eleventy, or plain HTML) and gives you three features:

  • Lead Capture - Send form submissions to LeadMachine from any form on your site
  • Attribution Tracking - Capture Google Ads clicks (gclid), UTM parameters, and Facebook/Microsoft/LinkedIn/TikTok click IDs, with first-touch memory so the ad click that first brought a visitor is remembered even if they return days later to sign up
  • Conversion Tracking - Fire your Google Ads conversion (and optionally a GA4 purchase event with real revenue) when a visitor completes a form or checkout, gated on a confirmation page so abandoned checkouts are never counted

Your LeadMachine API key stays on the server (in a Netlify environment variable) and never appears in your website's source code.


New to Netlify? Two concepts

  1. Your site's files live in a Git repository (usually GitHub). Netlify rebuilds and publishes your site whenever that repository changes. "Installing" this connector means adding two small files to that repository.
  2. Netlify Functions are small pieces of server code that run at yoursite.com/.netlify/functions/<name>. The connector uses one so your LeadMachine API key stays secret on the server.

If your developer manages the website, hand them this guide and the downloaded connector — steps 1, 3, and 4 are theirs; step 2 (adding your credentials) can be done by anyone with access to the Netlify dashboard.


Prerequisites

  • Active LeadMachine account
  • A website hosted on Netlify, connected to a Git repository
  • Access to the site's Netlify dashboard
  • Your LeadMachine Company ID
  • Your LeadMachine API Key

Step 1: Get Your Credentials

Both come from the Integrations page in LeadMachine.

Finding Your Company ID

  1. Log in to your LeadMachine dashboard
  2. Go to Integrations from the sidebar
  3. Your Company ID is displayed at the top of the page

Getting Your API Key

  1. On the Integrations page, find the Netlify card (search "Netlify" or use the Lead Capture filter)
  2. Click the card to open its settings panel
  3. Copy the Site API Key shown (if none exists yet, click Generate Key)

Note: This is the same key used by the WordPress plugin. If you already use the WordPress connector, you can reuse the same key — you don't need a separate one.


Step 2: Download the Connector

  1. On the Integrations page, find the Netlify card and click Connector to download leadmachine-netlify-connector.zip
  2. Unzip it. Inside you'll find:
- functions/lm-lead.mjs — the server function - public/leadmachine.js — the browser script - README.md — a copy of these instructions - netlify.toml.example — only needed for non-standard setups


Step 3: Add the Two Files to Your Site

Copy the files into your website's repository:

The netlify/functions/ folder is Netlify's default location — create it if it doesn't exist. No extra configuration is needed for the function to deploy.


Step 4: Add Your Credentials in Netlify

In the Netlify dashboard for your site: Site configuration → Environment variables → Add a variable. Add these two:

Optional third variable, only if LeadMachine support tells you to use a different server:

Important: environment variables only apply to builds that happen after you add them. After saving, trigger a redeploy (Deploys → Trigger deploy) so the new values take effect.


Step 5: Load the Script and Connect Your Form

Load the script

In your site's shared layout (Astro: your src/layouts/ file; plain HTML: every page's <head>), just before the closing </body> tag:

html
<script>
  window.leadmachineData = {
    // Google Ads conversion — optional. From Google Ads > Goals >
    // Conversions > your action > Tag setup. Omit if you're not tracking conversions.
    gads_conversion_id: "AW-XXXXXXXXX",
    gads_conversion_label: "xxxxxxxxxxxx",
    // Only count checkouts that finish: the conversion fires when the visitor
    // reaches a URL containing this text (e.g. your thank-you page).
    gads_conversion_page: "thank-you",
    // Also send a GA4 purchase event carrying the revenue amount:
    ga4_purchase: "1"
  };
</script>
<script src="/leadmachine.js" defer></script>

Your existing Google tag (gtag.js / GA4) must already be installed on the site for conversion firing — the connector uses your tag rather than loading its own.

Connect your form — Option A: automatic

Add data-leadmachine to any form and name the inputs conventionally:

html
<form data-leadmachine data-lm-tags="Website,Contact" data-lm-redirect="/thanks/">
  <input name="name" placeholder="Your name" required>
  <input name="email" type="email" placeholder="Email" required>
  <input name="phone" placeholder="Phone">
  <textarea name="message"></textarea>
  <!-- Honeypot: keep it hidden. Bots fill it, humans don't. -->
  <input name="website_url" style="display:none" tabindex="-1" autocomplete="off">
  <button type="submit">Send</button>
</form>

Recognized input names: name (or separate first_name / last_name), email, phone, company, message.

Optional form attributes:

  • data-lm-tags — tags applied to the lead in LeadMachine
  • data-lm-redirect — page to send the visitor to on success
  • data-lm-form-type — e.g. contact (default) or newsletter
  • data-lm-conversion — also fire the Google Ads conversion when this form succeeds

Connect your form — Option B: from your own JavaScript

For custom or multi-step flows (for example, a subscription builder), call the connector directly:

js
// Send the lead whenever your flow captures it:
LeadMachine.submitLead({
  name: "Jane Doe",
  email: "[email protected]",
  phone: "555-0100",
  tags: "Subscribe Flow",
  form_type: "subscription"
});

// Arm the purchase conversion when checkout begins; it fires only when the // visitor lands on the confirmation page (gads_conversion_page): LeadMachine.markConversion({ value: 84.00, currency: "USD", transaction_id: "sub_123" });

If your confirmation page URL already carries the amount (for example /thanks/?value=84.00&currency=USD&transaction_id=sub_123), you don't need to pass a value to markConversion() — the connector reads value, currency, and transaction_id from the URL.


What Data is Captured?

Alongside the form fields, the connector sends attribution data — gclid and other ad click IDs, UTM parameters, first-touch landing page, referrer, and device details — so leads are attributed to the campaign that produced them.


Conversion & ROAS Tracking

The connector fires conversions the same way the WordPress plugin does — with dynamic values and a confirmation-page gate so only completed checkouts count.

How the value is provided (never hard-coded)

  • Pass it in code: LeadMachine.markConversion({ value: 84.00, currency: "USD" })
  • Pass it on the confirmation URL: redirect to …/thanks/?value=84.00&currency=USD. The keys must be exactly value and currency.

If no value is provided, the Google Ads conversion still fires and Google Ads uses the conversion action's own default value.

The confirmation-page gate

Set gads_conversion_page to a piece of text that appears in your success/thank-you page URL (e.g. success or thank-you). The conversion is armed when the visitor submits or begins checkout, but only fires once they reach a URL containing that text — so people who abandon checkout are never counted. Leave it blank to fire immediately on the next page load.

Verify

Run a test submission (and a test purchase, if applicable), then open Google Tag Assistant or GA4 DebugView on your confirmation page — you should see a conversion event, and a purchase event if you enabled ga4_purchase, with value and currency populated.


Testing the Connection

  1. Push your changes — Netlify deploys automatically.
  2. Visit your site with a test ad click in the URL: yoursite.com/?gclid=TEST123&utm_source=test
  3. Submit your form.
  4. Within seconds, check Leads in LeadMachine — you should see the new lead, with the source URL and TEST123 gclid attached.


Troubleshooting

"Connector not configured" error on submit

The environment variables from Step 4 aren't set, or were added after the last deploy.

  1. Confirm LEADMACHINE_COMPANY_ID and LEADMACHINE_API_KEY exist under Site configuration → Environment variables.
  2. Trigger a redeploy so the new values take effect.

Leads arrive but conversions don't fire

  1. Confirm your site's Google tag (gtag) loads on the confirmation page.
  2. Check that gads_conversion_page matches text that actually appears in your confirmation page's URL.
  3. Confirm gads_conversion_id and gads_conversion_label are correct (Google Ads > Goals > Conversions > Tag setup).

Nothing happens when I submit the form

  1. Open your browser's Network tab and confirm leadmachine.js loads without error.
  2. For automatic forms, confirm the form has the data-leadmachine attribute.
  3. For custom flows, confirm your code calls LeadMachine.submitLead(...).

Where to see server logs

Netlify dashboard → Logs → Functions → lm-lead. Failed submissions are logged here with the reason.


Updating the Connector

When a new version is available:

  1. Download the latest leadmachine-netlify-connector.zip from the Integrations page.
  2. Replace netlify/functions/lm-lead.mjs and public/leadmachine.js in your repository with the new files.
  3. Commit and push — Netlify redeploys automatically. Your environment variables and script configuration are preserved.


Netlify Connector vs. WordPress Plugin

From the downloadInto your site repository
----------------------------------------------
functions/lm-lead.mjsnetlify/functions/lm-lead.mjs
public/leadmachine.jspublic/leadmachine.js (or wherever your static assets live)
Variable nameValue
----------------------
LEADMACHINE_COMPANY_IDYour Company ID from Step 1
LEADMACHINE_API_KEYYour Site API Key from Step 1
Variable nameValue
----------------------
LEADMACHINE_API_URLhttps://app.leadmachine.fyi (this is the default)
Form FieldLeadMachine Field
-------------------------------
First Name / NameFirst Name
Last NameLast Name
EmailEmail (primary contact)
PhonePhone (contact)
CompanyCompany Name
MessageLead Notes
Netlify ConnectorWordPress Plugin
---------------------------------------
Best forStatic sites (Astro, Next, Hugo, plain HTML)WordPress sites
InstallCopy two files into your repoUpload a plugin zip
CredentialsNetlify environment variablesPlugin settings screen
Lead captureYesYes
Attribution (gclid/UTM)Yes, with first-touch memoryYes
Conversion & GA4 trackingYesYes
Blog post sync for newslettersNo (WordPress-only feature)Yes

Both send to the same LeadMachine account using the same API key. If you run both a WordPress site and a Netlify site, they can share one key.


Getting Help

If you encounter issues:

  • Email: [email protected]
  • Include your Company ID and the name of your website framework (Astro, Next, etc.)
  • Describe the issue and include anything from the Netlify function logs (Logs → Functions → lm-lead)

Last Updated: August 2026