Personalize Landing Pages Using MailChimp Merge Tags or Merge Fields

Updated June 10th, 2020
Updated June 10th, 2020
Share this post:

Below you will find Javascript code that will help you personalize landing pages using MailChimp merge tags. We do this pulling a URL parameter and inserting the value of that parameter into the page. This is a really easy way to personalize landing pages on your site with your subscriber’s information.

There are 4 things you need to do to make this code work for you. First, you have to place this Javascript on form page. You can paste it right into the HTML editor in WordPress below the form or add it to a specific page using the functions.php file.

Then you need to update 3 things in the script:

Advertisement
  1. VARIABLE
  2. PARAMETER
  3. INPUT-FIELD-ID

These are explained in the video, so be sure to watch it closely.

<script text="text/javascript">
var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;
    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');
        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};

var VARIABLE = getUrlParameter('PARAMETER');

if (VARIABLE != null) {
     document.getElementById('INPUT-FIELD-ID').innerHTML = VARIABLE;
}

</script>
Share this post:

Responses

Your email address will not be published. Required fields are marked *

  1. Hi Bjorn,

    I’m curious. Will this code work with any form creator? As you know, I’m using Elementor and they have a form in their arsenal. This would be awesome if your code could be used with any form. But mean not knowing enough to do this on my own, I’m curious. Thanks and keep the videos coming!

    1. Hi John,

      Yes, this code should work with any form builder. You would have to update the selectors to “choose” the right places on the page the place the data. But it’ll work on pretty much any type of page or form where you can add Javascript.

      If you need help share a link and I’ll take a look!

  2. we want to thank you for the content you have created. There are always useful pages like yours, where you can find quality marketing information.
    Kind regards.

WPLearningLab