SOLVED

UTM parameters not populating into utm fields

Go to solution
Julz_James
Level 10

Re: UTM parameters not populating into utm fields

Hi Sanford,

There is no special code being used, just the UTM parameters in the URL and then the hidden fields on the forms.  It seems to be an intermittent problem where sometimes it works if the lead has visited the site a number of times, but all the time if it's a new lead into Marketo.  The only parameters we want to capture is when they fill in a form, and for the parameters to change on each form fill (as long as they are present in the URL).

Can I message you privately to show you some examples?

Thanks

Julz

SanfordWhiteman
Level 10 - Community Moderator

Re: UTM parameters not populating into utm fields

How are you verifying that the UTM params were in the URL at the time the form was rendered?

The new/old lead doesn't make sense -- for the purposes of hidden fields, the form doesn't care whether the session was previously associated or not unless you're using Known Visitor HTML ("If Known Visitor, show Custom HTML" in Form Editor).

Julz_James
Level 10

Re: UTM parameters not populating into utm fields

I'm looking in the activity log for a lead I know that has filled in the form using the UTM params (such as my test account), and it shows the referring URL and the Query params showing the correct UTM information.  That's as far as it's got so far.

SanfordWhiteman
Level 10 - Community Moderator

Re: UTM parameters not populating into utm fields

What's an example of an exact page URL, including UTM params?

Also, are ​you using KV HTML?

Julz_James
Level 10

Re: UTM parameters not populating into utm fields

Here is the one of the URLs: Orchestrating Immersive CX in Your Contact Center | NICE inContact

As for KV HTML, I'm going to say no.

Julz_James
Level 10

Re: UTM parameters not populating into utm fields

And when I fill in a form using this URL, this is showed on the record, ad this didn't update from previous tests:

UTM Campaign: utm_campaign

UTM Content: utm_content

UTM Medium: Social

UTM Source: inContact

SanfordWhiteman
Level 10 - Community Moderator

Re: UTM parameters not populating into utm fields

Except you aren't using only Marketo's built-in parameter autofill: you are using third-party JS to manipulate form and cookie values. That's exactly what this broken JS library does, or tries to do. But it suffers from exactly what I predicted above -- it isn't Marketo-literate and has a quite obvious race condition (it doesn't use the Marketo Forms API to know when the form is ready, and furthermore doesn't use the right way of setting values).

Anonymous
Not applicable

Re: UTM parameters not populating into utm fields

Hi Juli,

We set up additional UTM parameters using the "fm_utm_medium", etc. We then built code that then holds the cookied value within these fields for a longer period of time, these fields then write to our original utm fields (utm_medium, etc.). This helps solve the issue of utm values dropping off as they move from page to page.

There are still situations where the person could drop of the utm values off the URL.

Here's the code we implemented:

<script>

/*

* BEGIN CAPTURE UTM PARAMETERS FROM FIRST TOUCH AND LAST TOUCH

* Copyright (c) 2017, Yanir Calisar, Tel Aviv, Israel (ycalisar at gmail.com)

*

* Permission is hereby granted, free of charge, to any person obtaining a copy of this code and associated documentation files, to deal in the code without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the code.

* The user assumes responsibility for determining appropriate use of the code, for consequences of its use, and for checking functionality against other reliable sources.

* We suggest citation in publications as with any code developement work. No warrantee is given.

* Please help improve the code by sending suggestions or new code back.

*/

(function() {

    var STORE_COOKIES = true;

    var STORE_LOCAL_STORAGE = true;

    function topDomain() {

        var i, h, top_level_cookie = 'top_level_domain=cookie', hostname = document.location.hostname

                .split('.');

        for (i = hostname.length - 1; i >= 0; i--) {

            h = hostname.slice(i).join('.');

            document.cookie = top_level_cookie + ';domain=.' + h + ';';

            if (document.cookie.indexOf(top_level_cookie) > -1) {

                document.cookie = top_level_cookie.split('=')[0] + '=;domain=.'

                        + h + ';expires=Thu, 01 Jan 1970 00:00:01 GMT;';

                return h;

            }

        }

    }

    var utmCookie = {

        cookieNamePrefix : "__lt_",

        cookieCumulativePrefix: "__cu_",

        cookieNameFirstTouchPrefix : "__ft_",

        utmParams : [ "utm_source", "utm_medium", "utm_campaign", "utm_term",

                "utm_content" ],

        cookieExpiryDays : 365,

        // From http://www.quirksmode.org/js/cookies.html

        createCookie : function(name, value, days) {

            if(STORE_COOKIES) {

                if (days) {

                    var date = new Date();

                    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));

                    var expires = "; expires=" + date.toGMTString();

                } else

                    var expires = "";

                document.cookie = this.cookieNamePrefix + name + "=" + value

                    + expires + ";domain=." + topDomain() + ";  path=/";

            }

            if(STORE_LOCAL_STORAGE) this.createLS(name, value);

        },

        createLS: function(name, value){

            localStorage[this.cookieNamePrefix+ name] = value;

        },

        readCookie : function(name) {

            if(STORE_COOKIES) {

                var nameEQ = this.cookieNamePrefix + name + "=";

                var ca = document.cookie.split(';');

                for (var i = 0; i < ca.length; i++) {

                    var c = ca[i];

                    while (c.charAt(0) == ' ')

                        c = c.substring(1, c.length);

                    if (c.indexOf(nameEQ) == 0)

                        return c.substring(nameEQ.length, c.length);

                }

                if(STORE_LOCAL_STORAGE) this.readLS(name);

                else return null;

            }

            if(STORE_LOCAL_STORAGE) this.readLS(name);

        },

        readLS: function(name){

            var val = localStorage[this.cookieNamePrefix + name];

            if(val == undefined) return null;

            else return val;

        },

        checkIfFirstTouch : function() {

            if(STORE_LOCAL_STORAGE) {

                var nameEQ = this.cookieNameFirstTouchPrefix + "utm_source=";

                var ca = document.cookie.split(';');

                for (var i = 0; i < ca.length; i++) {

                    var c = ca[i];

                    while (c.charAt(0) == ' ')

                        c = c.substring(1, c.length);

                    if (c.indexOf(nameEQ) == 0)

                        return c.substring(nameEQ.length, c.length);

                }

                if(STORE_LOCAL_STORAGE) this.readLS(this.cookieNameFirstTouchPrefix + "utm_source");

                else return null;

            }

            if(STORE_LOCAL_STORAGE) this.readLS(this.cookieNameFirstTouchPrefix + "utm_source");

        },

        eraseCookie : function(name) {

            if(STORE_COOKIES) this.createCookie(name, "", -1);

            if(STORE_LOCAL_STORAGE) delete localStorage[name];

        },

        getParameterByName : function(name) {

            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

            var regexS = "[\\?&]" + name + "=([^&#]*)";

            var regex = new RegExp(regexS);

            var results = regex.exec(window.location.search);

            if (results == null) {

                return "";

            } else {

                return decodeURIComponent(results[1].replace(/\+/g, " "));

            }

        },

        utmPresentInUrl : function() {

            var present = false;

            for (var i = 0; i < this.utmParams.length; i++) {

                var param = this.utmParams[i];

                var value = this.getParameterByName(param);

                if (value != "" && value != undefined) {

                    present = true;

                }

            }

            return present;

        },

        writeUtmCookieFromParams : function() {

            for (var i = 0; i < this.utmParams.length; i++) {

                var param = this.utmParams[i];

                var value = this.getParameterByName(param);

                if(STORE_COOKIES) this.createCookie(param, value, this.cookieExpiryDays);

                if(STORE_LOCAL_STORAGE) localStorage[param] = value;

            }

        },

        writeCookieOnce : function(name, value) {

            if (STORE_COOKIES && !this.readCookie(name)) {

                this.createCookie(name, value, this.cookieExpiryDays);

            }

            if(STORE_LOCAL_STORAGE && this.readLS(name) == null){

                this.createLS(name,value);

            }

        },

        writeReferrerOnce : function() {

            var value = document.referrer;

            if (value === "" || value === undefined) {

                this.writeCookieOnce("referrer", "direct");

            } else {

                this.writeCookieOnce("referrer", value);

            }

        },

        referrer : function() {

            return this.readCookie("referrer");

        }

    };

    if (!utmCookie.checkIfFirstTouch()) {

        utmCookie.cookieNamePrefix = utmCookie.cookieNameFirstTouchPrefix;

        utmCookie.writeReferrerOnce();

        if (utmCookie.utmPresentInUrl()) {

            utmCookie.writeUtmCookieFromParams();

        }

        utmCookie.cookieNamePrefix = "__lt_";

    }

    utmCookie.writeReferrerOnce();

    if (utmCookie.utmPresentInUrl()) {

        utmCookie.writeUtmCookieFromParams();

       

    }

})();       

/* END CAPTURE UTM PARAMETERS FROM FIRST TOUCH AND LAST TOUCH */

</script>

Julz_James
Level 10

Re: UTM parameters not populating into utm fields

Hi Laura

Thank you so much!  I'm going to look into the code and cookies being used to see if that is an issue as well.  I didn't implement the system so I'm trying to troubleshoot as I go!

Thanks again

Julz

Zach_Rogers2
Level 2

Re: UTM parameters not populating into utm fields

Hi Juli,

You probably already know this since you're the best (loved your talk at Summit this year!) but we had this same problem and realized we had to ensure to disable autoform fill on our hidden UTM fields.