Skip to Content

Mailchimp

Mailchimp is one of the most popular email marketing platforms, used by millions of businesses to manage mailing lists, send newsletters, and build email automations. Mailchimp’s embedded signup forms render as standard HTML <form> elements in the page DOM.

Because Mailchimp embeds are standard HTML forms, AttributionHub’s standard forms handler detects and populates them automatically. You just need to add hidden fields to your Mailchimp form embed code so the attribution data has somewhere to be captured.

Prerequisites

Before you begin, make sure:

  • The AttributionHub tracking script is installed on your site (see Installation)
  • You have a Mailchimp account with at least one Audience (email list)
  • You have access to your website’s code or CMS to modify the embed code

Step 1: Create Merge Fields in Mailchimp

Mailchimp uses “merge fields” (also called merge tags) to store subscriber data. You need to create merge fields for each attribution value you want to capture.

  1. In Mailchimp, go to Audience > Audience dashboard
  2. Click Manage Audience (or Settings) > Audience fields and *|MERGE|* tags
  3. Click Add A Field
  4. For each attribution field:
    • Choose Text as the field type
    • Set the Field label to something descriptive (e.g., “Attribution Channel”)
    • Note the Merge tag that Mailchimp generates (e.g., MERGE3, MERGE4). You will use this in the next step
  5. Click Save Changes after adding all fields

Alternatively, you can create merge fields using custom tag names by clicking on the merge tag and editing it to something like AHCHANNEL.

Step 2: Add Hidden Fields to Your Embed Code

Mailchimp’s embedded form code is an HTML form. You need to add hidden input fields that match your merge field tags.

  1. In Mailchimp, go to Audience > Signup forms > Embedded forms
  2. Copy the generated embed code
  3. Paste it into your website
  4. Add hidden input fields to the form for each attribution value. The name attribute must match the Mailchimp merge tag format — MERGE3, MERGE4, etc., or the custom tag name you specified

Here is an example with hidden fields added:

<!-- Mailchimp embedded form (simplified) --> <form action="https://yourcompany.us1.list-manage.com/subscribe/post?u=XXXX&amp;id=XXXX" method="post" class="mc-embedded-subscribe-form" > <!-- Visible fields --> <input type="email" name="EMAIL" placeholder="Email Address" required /> <input type="text" name="FNAME" placeholder="First Name" /> <!-- Attribution hidden fields --> <input type="hidden" name="AHCHANNEL" value="" /> <input type="hidden" name="AHSOURCE" value="" /> <input type="hidden" name="AHMEDIUM" value="" /> <input type="hidden" name="AHCAMPAIGN" value="" /> <input type="hidden" name="AHLANDING" value="" /> <input type="hidden" name="AHFTCHAN" value="" /> <input type="hidden" name="AHFTSRC" value="" /> <input type="hidden" name="AHVISITOR" value="" /> <button type="submit">Subscribe</button> </form>

Step 3: Configure Field Mapping

Because Mailchimp merge tags have different names than AttributionHub’s defaults, you need to configure the field mapping:

<script> window.attrhub = { settings: { fieldMapping: { "latest.attribution.channelGroup": "AHCHANNEL", "latest.attribution.source": "AHSOURCE", "latest.attribution.medium": "AHMEDIUM", "latest.attribution.campaign": "AHCAMPAIGN", "latest.attribution.landingPageUrl": "AHLANDING", "first.attribution.channelGroup": "AHFTCHAN", "first.attribution.source": "AHFTSRC", visitorId: "AHVISITOR", }, }, }; </script>

The fieldMapping keys are AttributionHub’s internal data paths. The values must match the name attributes on your hidden <input> fields.

See Configuration for the full mapping reference.

Step 4: Test the Integration

  1. Visit a page on your site that contains the Mailchimp form
  2. Open your browser’s DevTools (F12)
  3. In the Elements panel, inspect the hidden <input> elements inside the form — they should have attribution values populated
  4. Subscribe with a test email address
  5. In Mailchimp, go to Audience > All contacts and find the test subscriber. The merge field values should contain attribution data

For a full testing walkthrough, see Verify It Works.

How It Works

Mailchimp embedded forms render as standard HTML <form> elements on the page, typically with the class .mc-embedded-subscribe-form. AttributionHub’s standard forms handler:

  1. Discovers the form using the default form selector
  2. Finds hidden fields whose name attributes match the field mapping
  3. Sets the attribution values on those fields
  4. When the form is submitted, Mailchimp includes the hidden field values as merge field data for the new subscriber

Tips

  • Mailchimp segments — Create audience segments based on attribution merge fields. For example, create a segment of all subscribers who came from “Paid Search” and send them a targeted follow-up sequence.
  • Automations — Use merge field values as triggers or conditions in Mailchimp automation workflows. Send different welcome sequences based on how the subscriber found your site.
  • Tags vs. merge fields — Merge fields store the attribution values as subscriber data. If you prefer to use Mailchimp tags for segmentation, you can set up an automation that adds tags based on merge field values.
  • Double opt-in — Attribution data is captured at the time of form submission, before the subscriber confirms via double opt-in. The merge field values are stored regardless of whether the subscriber confirms.
  • Mailchimp landing pages — If you use Mailchimp’s built-in landing pages, you will need to add the AttributionHub script to the landing page’s custom HTML. Check if your plan supports custom HTML on landing pages.
  • Multiple signup forms — AttributionHub populates all Mailchimp forms on the page independently.

Troubleshooting

Merge fields are empty for new subscribers

  1. Verify the hidden <input> name attributes match your Mailchimp merge tag names.
  2. Confirm the fieldMapping in your settings correctly maps AttributionHub paths to your merge tag names.
  3. Inspect the hidden fields in DevTools before submitting — they should already have values.
  4. Enable logging (enableLogging: true in settings) and check the browser Console.

Mailchimp popup/modal forms

Mailchimp’s popup signup forms use a different embed mechanism and may render in an iframe or separate container. If the popup form uses a standard HTML form element on the page, the standard handler will pick it up. If it uses an iframe, add a custom form selector:

window.attrhub = { settings: { formSelectors: [".mc-modal form", "#mc_embed_signup form"], }, };

Merge tag naming limits

Mailchimp merge tags have length and character restrictions. Keep tag names short (10 characters max) and use only uppercase letters, numbers, and underscores. This is why the examples above use abbreviated names like AHCHANNEL instead of ah_lt_channel.