How to integrate GA Connector with Typeform

Add Google Analytics data to Typeform with GA Connector’s Typeform integration.

Prerequisites

  • Installed either the GA Connector WordPress plugin or GA Connector script on your website:
HTML
<script data-cfasync="false" type="text/javascript" src="https://tracker.gaconnector.com/gaconnector.js"></script>
<script>
function setGaconnectorHiddenFields() {
    var gaFields = gaconnector.getCookieValues();
    for (var fieldName in gaFields) {
        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 + '"],';
        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+"']";
        var inputs = document.querySelectorAll(selectors);
        if (inputs === null) {
            continue;
        } else if (typeof inputs.length === 'undefined') {
            inputs.value = gaFields[fieldName];
        } else {
            for (var i = 0; i < inputs.length; i++) {
                inputs[i].value = gaFields[fieldName];
            }
        }
    }
}

gaconnector.setCallback(setGaconnectorHiddenFields);
setInterval(setGaconnectorHiddenFields, 1000);
</script>

Add Hidden Fields to your Typeform

  1. Open your typeform from your workspace and click Logic on the right panel. Select Personalize with data then click on Hidden Fields.

    This will open a pop-up where you can type and add Hidden Fields

  2. You'll need to add the ID of the GA Connector field that you want to track and press enter. (E.g. If you want to track Last Click Source, you need to input lc_source). For the full list of GA Connector fields that you can track and their respective IDs, refer to the table below.

    GA Connector adds UTM information, geolocation, referral information to your Typeform leads.
    See below for all the information that you can add to your leads to help you find out which of your marketing activities drive sales.

    Label Input ID Label Input ID
    All Traffic Sources all_traffic_sources Last Click Campaign lc_campaign
    Browser browser Last Click Channel lc_channel
    City (from IP address) city Last Click Content lc_content
    Country (from IP address) country Last Click Landing Page lc_landing
    First Click Campaign fc_campaign Last Click Medium lc_medium
    First Click Channel fc_channel Last Click Referrer lc_referrer
    First Click Content fc_content Last Click Source lc_source
    First Click Landing Page fc_landing Last Click Term lc_term
    First Click Medium fc_medium Last Click Timestamp lc_timestamp
    First Click Referrer fc_referrer Longitude longitude
    First Click Source fc_source Latitude latitude
    First Click Term fc_term Number of Website Visits page_visits
    First Click Timestamp fc_timestamp Operating System OS
    Google Analytics CID GA_Client_ID Device device
    Google Analytics Measurement ID GA_Measurement_ID Region region
    Google Analytics Session ID GA_Session_ID Pages Visited pages_visited_list
    Google Click Identifier gclid Time Spent on Website time_passed
    IP Address ip_address Time Zone time_zone

    Note: You can add all of these fields or choose only what you need.
    For more information regarding adding hidden fields on Typeform, please see this article.

Embedding your Typeform to your website

  1. Get your latest embed code from Typeform and paste it on your website but omit the <script>... part of the code. Make sure that your code ends on the closing </div>
  2. Right after your embed code (without the <script> part), add the code below
HTML
<script>window.addEventListener("DOMContentLoaded",t=>{var e,n=0,o=document.querySelectorAll("[data-tf-widget]");
function d(){for(i=0;i<o.length;++i){var t=o[i].dataset.tfHidden?o[i].dataset.tfHidden.split(","):[],n=[];for(var d in e)-1!==t.indexOf(d+"=")?t[t.indexOf(d+"=")]=d+"="+e[d]:n.push(d+"="+e[d]);
var c=[...n,...t];o[i].dataset.tfHidden=c.toString()}r()}function r(){let t=document.createElement("script");t.src="//embed.typeform.com/next/embed.js",document.body.appendChild(t)}function c(){try{if(e=gaconnector.getCookieValues(),"function"!=typeof ga)return!!e.lc_source;
if("function"==typeof ga.getAll)return!!e.lc_source&&ga.getAll()[0].get("clientId")}catch(t){console.log("GA Connector script not found")}}var f=setInterval(function(){c()?(d(),clearInterval(f)):n>5&&(r(),clearInterval(f)),n++},100)});
</script>

Note: If you have multiple Typeforms on one page, you can just place this code right after your last form. No need to repeat.