In this article you’ll discover how to capture google’ cookie and save client id into a custom field.

REQUIRED:

  1. In this example we are using a custom field called ‘clientid’. Be sure to create clientid field.
  2. Using GA
<script>
    function getCookie(name) {
        const value = document.cookie;
        const parts = value.split(`; ${name}=`);
        if (parts.length === 2) return parts.pop().split(';').shift();
    }
    
    let interval = setInterval(function (){
        if (getCookie('_ga')) {
            LH.setField('clientid', getCookie('_ga').slice(6)); 
            clearInterval(interval);
        }
    }, 1000);
</script>

STEP 1: Please ensure GA has been setup correctly.

STEP 2: Add script to first node and fire on entry as shown below.

This will save clientid from Google’s cookie into the custom field, ‘clientid’.

STEP 3: Do a quick test through your DT and you should see the clientid saved with visitor/lead record.

Leave a Reply

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