1

Im working on this bit, its fully functional, what it does is to write a cookie and pass it to a hidden field:

// part 1 - get and parse cookie string
$(window).load(function(){

        var cookieString = document.cookie;
        var parsedCookie = cookieString.split(";");
        var hutk = '';
        for(var i=0; i<parsedCookie.length; i++){
            var eachCookie = parsedCookie[i].split('=');
            if(eachCookie[0] == ' hubspotutk'){
                hutk += eachCookie[1];
            }
        }
// part 2 - populate the cookie string into hidden field name contextJSON
        var context = new Object();
        context.hutk = hutk;
        context.pageUrl = window.location.href;
        context.pageName = document.title;
        context.redirectUrl = 'https://info.cos.net.au/thank-you';

        document.getElementById('contextJSON').value = JSON.stringify(context);

});

how can i get the customer's ipAddress by javasccript or jquery and add it on top of the existing string in part 2? many thanks

Zen
  • 11
  • 1
  • 2
    I would use PHP for this. See https://stackoverflow.com/questions/1634782/what-is-the-most-accurate-way-to-retrieve-a-users-correct-ip-address-in-php for more information – AlexH Sep 21 '19 at 00:02
  • 1
    Check out the second answer here if you want to do it on the client side, although it is likely not possible in up-to-date browsers: https://stackoverflow.com/questions/391979/how-to-get-clients-ip-address-using-javascript – j3py Sep 21 '19 at 00:07

0 Answers0