{"id":1553,"date":"2018-05-27T21:29:27","date_gmt":"2018-05-27T21:29:27","guid":{"rendered":"https:\/\/gaconnector.com\/docs\/?p=1553"},"modified":"2026-09-04T05:48:17","modified_gmt":"2026-09-04T05:48:17","slug":"connect-mailchimp-forms-ga-connector-cookie-based","status":"publish","type":"post","link":"https:\/\/gaconnector.com\/docs\/connect-mailchimp-forms-ga-connector-cookie-based\/","title":{"rendered":"Add Lead Source Tracking to Mailchimp Embedded Forms"},"content":{"rendered":"<p>Mailchimp embedded forms can carry GA Connector attribution data into your audience, so every new contact arrives with UTM information, geolocation, referral data and Google Analytics identifiers already attached. What you need to set up depends on which GA Connector integration type your account uses.<\/p>\n<p>Not sure which one you have? Start here: <a href=\"https:\/\/gaconnector.com\/docs\/how-to-check-which-ga-connector-integration-type-youre-using\/\">How to Check Which GA Connector Integration Type You&#8217;re Using<\/a>.<\/p>\n<h2>API-based integration<\/h2>\n<p>There is nothing to configure on the Mailchimp side. The GA Connector script already captures the email address submitted through your form, and the attribution data is synced to your CRM a few minutes after the contact is created. Skip the rest of this article.<\/p>\n<h2>Cookie-based integration<\/h2>\n<p>Cookie-based integration writes attribution data into hidden fields on your form at the moment of submission. Mailchimp stores those values as merge fields on the contact, so you need to create the fields first, then add them to your embedded form.<\/p>\n<h3>Step 1: Replace the GA Connector script on your website<\/h3>\n<p>The standard GA Connector script fills hidden fields that match GA Connector&#8217;s own field names. Mailchimp uses merge tags instead, and those tags are capped at 10 characters, so the script below fills both naming conventions. Replace your existing GA Connector script with this version on every page.<\/p>\n<pre class=\"lang:default decode:true \">&lt;script data-cfasync=\"false\" type=\"text\/javascript\" src=\"https:\/\/tc.gaconnector.com\/gaconnector.js\"&gt;&lt;\/script&gt;\r\n&lt;script&gt;\r\n    function setGaconnectorHiddenFields() {\r\n        var gaFields=gaconnector.getCookieValues(),GAC_TAGS={ga_measurement_id:\"GAC_GA4MID\",ga_client_id:\"GAC_GA4CID\",ga_session_id:\"GAC_GA4SID\",gclid:\"GAC_GCLID\",fc_source:\"GAC_FCSRC\",lc_source:\"GAC_LCSRC\",fc_medium:\"GAC_FCMED\",lc_medium:\"GAC_LCMED\",fc_campaign:\"GAC_FCCMP\",lc_campaign:\"GAC_LCCMP\",fc_term:\"GAC_FCTRM\",lc_term:\"GAC_LCTRM\",fc_content:\"GAC_FCCON\",lc_content:\"GAC_LCCON\",fc_landing:\"GAC_FCLND\",lc_landing:\"GAC_LCLND\",fc_channel:\"GAC_FCCHN\",lc_channel:\"GAC_LCCHN\",fc_referrer:\"GAC_FCREF\",lc_referrer:\"GAC_LCREF\",fc_timestamp:\"GAC_FCTS\",lc_timestamp:\"GAC_LCTS\",ip_address:\"GAC_IPADDR\",city:\"GAC_CITY\",country:\"GAC_CNTRY\",country_code:\"GAC_CCODE\",region:\"GAC_REGION\",time_zone:\"GAC_TZ\",latitude:\"GAC_LAT\",longitude:\"GAC_LNG\",OS:\"GAC_OS\",device:\"GAC_DEVICE\",browser:\"GAC_BROWSR\",all_traffic_sources:\"GAC_ALLSRC\",pages_visited_list:\"GAC_PGLIST\",page_visits:\"GAC_PGVIS\",time_passed:\"GAC_TPASS\"},mailchimpFields={};for(var fieldName in gaFields)mailchimpFields[GAC_TAGS[fieldName]]=gaFields[fieldName];var mergedFields={...gaFields,...mailchimpFields};\r\n\r\n        for (var fieldName in mergedFields) {\r\n            var selectors = 'form input[name=\"' + fieldName + '\"], form input#' + fieldName + ', form input#field_' + fieldName + ', form input[name=\"' + fieldName.toLowerCase() + '\"], form input#' + fieldName.toLowerCase() + ', form input#field_' + fieldName.toLowerCase() + ', input[value=\"gaconnector_' + fieldName + '\"],';\r\n            selectors += 'form textarea[name=\"'+fieldName+'\"], form textarea#'+fieldName+', form textarea#field_'+fieldName + ', form textarea[name=\"'+fieldName.toLowerCase()+'\"], form textarea#'+fieldName.toLowerCase()+', form textarea#field_'+fieldName.toLowerCase()+', form textarea.'+fieldName+', form textarea[name=\"param['+fieldName+']\"]'+\", form textarea[id^='field_\"+fieldName+\"']\";\r\n            var inputs = document.querySelectorAll(selectors);\r\n            if (inputs === null) {\r\n                continue;\r\n            } else if (typeof inputs.length === 'undefined') {\r\n                inputs.value = mergedFields[fieldName];\r\n            } else {\r\n                for (var i = 0; i &lt; inputs.length; i++) {\r\n                    inputs[i].value = mergedFields[fieldName];\r\n                }\r\n            }\r\n        }\r\n    }\r\n\r\n    gaconnector.setCallback(setGaconnectorHiddenFields);\r\n    setInterval(setGaconnectorHiddenFields, 1000);\r\n&lt;\/script&gt;<\/pre>\n<h3>Step 2: Decide which fields you need<\/h3>\n<div class=\"gac-callout gac-warning\">\n<p><span class=\"gac-label\">Heads up<\/span>A Mailchimp audience holds a maximum of 30 fields per contact, and five of those are taken by the default fields. On a Premium plan the limit is 80. GA Connector offers 36 data points, so on most plans you cannot add all of them. Pick the ones you will actually segment or report on.<\/p>\n<\/div>\n<p>A workable starting set is First Click Source, First Click Medium, First Click Campaign, Last Click Source, Last Click Medium, Last Click Campaign, Google Click Identifier, Google Analytics CID and First Click Landing Page. That covers attribution for most reporting without spending your whole field budget.<\/p>\n<h3>Step 3: Create the fields in Mailchimp<\/h3>\n<p><!-- SCREENSHOT 01: The path to the fields screen. Capture the Audience page with the horizontal three-dot menu open and \"Audience fields and merge tags\" visible in it. Crop to the menu. Suggested alt: \"Audience fields and merge tags option in the Mailchimp audience menu\". Filename: mailchimp-audience-menu.png --><\/p>\n<p>Click <strong>Audience<\/strong>, choose your audience if you have more than one, then click the horizontal three-dot icon and choose <strong>Audience fields and merge tags<\/strong>. For each field you want, click <strong>Create a new field<\/strong> and fill in the modal:<\/p>\n<ul>\n<li>Enter a name for the field. This is the label, and it is yours to choose.<\/li>\n<li>Set <strong>Data type<\/strong> to <strong>Text<\/strong>.<\/li>\n<li>Enter the merge tag from the table below.<\/li>\n<li>Leave the required checkbox unchecked.<\/li>\n<li>Click <strong>Save<\/strong>.<\/li>\n<\/ul>\n<p><!-- SCREENSHOT 02: The \"Create a new field\" modal filled in for one GA Connector field, showing the name, the Data type dropdown set to Text, and the merge tag field. Suggested alt: \"Creating a GA Connector text field in Mailchimp\". Filename: mailchimp-create-field.png --><\/p>\n<div class=\"gac-callout gac-note\">\n<p><span class=\"gac-label\">Note<\/span>The field name is yours to choose, but the merge tag has to match the table below exactly. The script looks up fields by merge tag, not by label. Mailchimp merge tags allow uppercase letters, numbers and underscores only, up to 10 characters, which is why the GA Connector tags are abbreviated.<\/p>\n<\/div>\n<p>Leave the fields visible on your signup forms. A field hidden at the audience level will not appear in the generated embed code, and the script has nothing to fill. You hide them with CSS in step 5 instead.<br \/>\n\n<table id=\"tablepress-20\" class=\"tablepress tablepress-id-20\">\n<thead>\n<tr class=\"row-1 odd\">\n\t<th class=\"column-1\">Label<\/th><th class=\"column-2\">Input ID<\/th><th class=\"column-3\">Label<\/th><th class=\"column-4\">Input ID<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-hover\">\n<tr class=\"row-2 even\">\n\t<td class=\"column-1\"><strong>All Traffic Sources <\/strong><\/td><td class=\"column-2\">GAC_ALLSRC<\/td><td class=\"column-3\"><strong>Last Click Campaign<\/strong><\/td><td class=\"column-4\">GAC_LCCMP<\/td>\n<\/tr>\n<tr class=\"row-3 odd\">\n\t<td class=\"column-1\"><strong>Browser<\/strong><\/td><td class=\"column-2\">GAC_BROWSR<\/td><td class=\"column-3\"><strong>Last Click Channel<\/strong><\/td><td class=\"column-4\">GAC_LCCHN<\/td>\n<\/tr>\n<tr class=\"row-4 even\">\n\t<td class=\"column-1\"><strong>City (from IP address)<\/strong><\/td><td class=\"column-2\">GAC_CITY<\/td><td class=\"column-3\"><strong>Last Click Content<\/strong><\/td><td class=\"column-4\">GAC_LCCON<\/td>\n<\/tr>\n<tr class=\"row-5 odd\">\n\t<td class=\"column-1\"><strong>Country (from IP address)<\/strong><\/td><td class=\"column-2\">GAC_CNTRY<\/td><td class=\"column-3\"><strong>Last Click Landing Page<\/strong><\/td><td class=\"column-4\">GAC_LCLND<\/td>\n<\/tr>\n<tr class=\"row-6 even\">\n\t<td class=\"column-1\"><strong>First Click Campaign<\/strong><\/td><td class=\"column-2\">GAC_FCCMP<\/td><td class=\"column-3\"><strong>Last Click Medium<\/strong><\/td><td class=\"column-4\">GAC_LCMED<\/td>\n<\/tr>\n<tr class=\"row-7 odd\">\n\t<td class=\"column-1\"><strong>First Click Channel<\/strong><\/td><td class=\"column-2\">GAC_FCCHN<\/td><td class=\"column-3\"><strong>Last Click Referrer<\/strong><\/td><td class=\"column-4\">GAC_LCREF<\/td>\n<\/tr>\n<tr class=\"row-8 even\">\n\t<td class=\"column-1\"><strong>First Click Content<\/strong><\/td><td class=\"column-2\">GAC_FCCON<\/td><td class=\"column-3\"><strong>Last Click Source<\/strong><\/td><td class=\"column-4\">GAC_LCSRC<\/td>\n<\/tr>\n<tr class=\"row-9 odd\">\n\t<td class=\"column-1\"><strong>First Click Landing Page<\/strong><\/td><td class=\"column-2\">GAC_FCLND<\/td><td class=\"column-3\"><strong>Last Click Term<\/strong><\/td><td class=\"column-4\">GAC_LCTRM<\/td>\n<\/tr>\n<tr class=\"row-10 even\">\n\t<td class=\"column-1\"><strong>First Click Medium <\/strong><\/td><td class=\"column-2\">GAC_FCMED<\/td><td class=\"column-3\"><strong>Last Click Timestamp<\/strong><\/td><td class=\"column-4\">GAC_LCTS<\/td>\n<\/tr>\n<tr class=\"row-11 odd\">\n\t<td class=\"column-1\"><strong>First Click Referrer<\/strong><\/td><td class=\"column-2\">GAC_FCREF<\/td><td class=\"column-3\"><strong>Longitude<\/strong><\/td><td class=\"column-4\">GAC_LNG<\/td>\n<\/tr>\n<tr class=\"row-12 even\">\n\t<td class=\"column-1\"><strong>First Click Source<\/strong><\/td><td class=\"column-2\">GAC_FCSRC<\/td><td class=\"column-3\"><strong>Latitude<\/strong><\/td><td class=\"column-4\">GAC_LAT<\/td>\n<\/tr>\n<tr class=\"row-13 odd\">\n\t<td class=\"column-1\"><strong>First Click Term<\/strong><\/td><td class=\"column-2\">GAC_FCTRM<\/td><td class=\"column-3\"><strong>Number of Website Visits<\/strong><\/td><td class=\"column-4\">GAC_PGVIS<\/td>\n<\/tr>\n<tr class=\"row-14 even\">\n\t<td class=\"column-1\"><strong>First Click Timestamp<\/strong><\/td><td class=\"column-2\">GAC_FCTS<\/td><td class=\"column-3\"><strong>Operating System<\/strong><\/td><td class=\"column-4\">GAC_OS<\/td>\n<\/tr>\n<tr class=\"row-15 odd\">\n\t<td class=\"column-1\"><strong>Google Analytics CID<\/strong><\/td><td class=\"column-2\">GAC_GA4CID<\/td><td class=\"column-3\"><strong>Device<\/strong><\/td><td class=\"column-4\">GAC_DEVICE<\/td>\n<\/tr>\n<tr class=\"row-16 even\">\n\t<td class=\"column-1\"><strong>Google Analytics Measurement ID<\/strong><\/td><td class=\"column-2\">GAC_GA4MID<\/td><td class=\"column-3\"><strong>Region<\/strong><\/td><td class=\"column-4\">GAC_REGION<\/td>\n<\/tr>\n<tr class=\"row-17 odd\">\n\t<td class=\"column-1\"><strong>Google Analytics Session ID<\/strong><\/td><td class=\"column-2\">GAC_GA4SID<\/td><td class=\"column-3\"><strong>Pages Visited <\/strong><\/td><td class=\"column-4\">GAC_PGLIST<\/td>\n<\/tr>\n<tr class=\"row-18 even\">\n\t<td class=\"column-1\"><strong>Google Click Identifier<\/strong><\/td><td class=\"column-2\">GAC_GCLID<\/td><td class=\"column-3\"><strong>Time Spent on Website <\/strong><\/td><td class=\"column-4\">GAC_TPASS<\/td>\n<\/tr>\n<tr class=\"row-19 odd\">\n\t<td class=\"column-1\"><strong>IP Address<\/strong><\/td><td class=\"column-2\">GAC_IPADDR<\/td><td class=\"column-3\"><strong>Time Zone <\/strong><\/td><td class=\"column-4\">GAC_TZ<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-20 from cache --><\/p>\n<h3>Step 4: Add the fields to your embedded form<\/h3>\n<p>Click <strong>Forms<\/strong>, then <strong>Other forms<\/strong>, then <strong>Create new form<\/strong> and <strong>Create embedded form<\/strong>. Name the form, choose your audience, and click <strong>Continue to builder<\/strong>.<\/p>\n<p><!-- SCREENSHOT 03: The embedded form builder with the Form Fields tab open and several GA Connector fields added to the form preview. Suggested alt: \"GA Connector fields in the Mailchimp embedded form builder\". Filename: mailchimp-form-builder.png --><\/p>\n<p>On the <strong>Form Fields<\/strong> tab, add the GA Connector fields you created. Click <strong>Continue<\/strong>, then <strong>Copy Code<\/strong> and paste the code onto your site.<\/p>\n<h3>Step 5: Hide the GA Connector fields<\/h3>\n<p>The generated form displays every field you added, which is not what you want for attribution data. Add this style block at the start of your embed code to hide them from visitors while leaving them in the form for the script to fill.<\/p>\n<pre class=\"lang:default decode:true\">&lt;style&gt;\r\n    .mc-field-group:has(input[name*=\"GAC_\" i]) {\r\n        display: none !important;\r\n    }\r\n&lt;\/style&gt;<\/pre>\n<p><!-- SCREENSHOT 04: Before and after of the live form on your site, first with the GA Connector fields rendered visibly, then with only the normal fields. Same page and width in both. Suggested alt: \"Mailchimp form before and after hiding GA Connector fields\". Filename: mailchimp-hidden-fields-before-after.png --><\/p>\n<h3>Check that it works<\/h3>\n<p>Visit a page with the form using a URL that carries UTM parameters, submit a test entry, then open that contact in your Mailchimp audience. The GA Connector merge fields should be populated with source, medium, campaign and the rest of the data you enabled.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mailchimp embedded forms can carry GA Connector attribution data into your audience, so every new contact arrives with UTM information, geolocation, referral data and Google Analytics identifiers already attached. What you need to set up depends on which GA Connector integration type your account uses. Not sure which one you have? Start here: How to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[],"_links":{"self":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/1553"}],"collection":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/comments?post=1553"}],"version-history":[{"count":35,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/1553\/revisions"}],"predecessor-version":[{"id":3886,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/posts\/1553\/revisions\/3886"}],"wp:attachment":[{"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/media?parent=1553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/categories?post=1553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gaconnector.com\/docs\/wp-json\/wp\/v2\/tags?post=1553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}