This guide is provided without our free support because setups vary from business to business. This guide is for a technical audience. Please contact us if you need our technical and development services.

In this article, you’ll learn how to pass any data from your website to LeadsHook as a custom field. You can pass any data such as tracking ids, customer info, or even cookie values.

STEP 1: Create a custom field for the data that you are passing to LeadsHook. You can click here to learn how to add a custom field.

STEP 2: Add the JavaScript code below to your website. Make sure to replace {customField} with the custom field name you created on step 1 and also replace {value} with the appropriate value that you need to pass. You can pass as much data as you want.

<script>
    LH.setField({customField1}, {value1});
    LH.setField({customField2}, {value2});
    LH.setField({customField3}, {value3});
</script>

Here is a short video on how to set it up.

Sample Scripts:

Grab URL parameters and push to LeadsHook

<script>
    const params = window.location.search.substring(1).split('&');
    for (let param of params) {
        console.log(param);
        let data = param.split('=');
        LH.setField(data[0], data[1]);
    }
</script>

Pass a specific value into a custom field based on page scroll.

<script>
      let notSet50 = true;
      let notSet100 = true;
      window.addEventListener('scroll', (event) => {
        let scrolledAt = window.scrollY / (pageViewHeight = document.body.scrollHeight - window.innerHeight);
        if (scrolledAt > 0.5 && notSet50) {
          LH.setField('scrolled50', 'Yes');
          notSet50 = false;
          console.log('Scrolled50 sent to LeadsHook.');
        }
        if (scrolledAt > 1 && notSet100) {
          LH.setField('scrolled100', 'Yes');
          notSet100 = false;
          console.log('Scrolled100 sent to LeadsHook.');
        }
      });
</script>

Grab specific cookies and push to LeadsHook.

<script>
      function getCookie(name) {
        const value = document.cookie;
        const parts = value.split(`; ${name}=`);
        if (parts.length === 2) return parts.pop().split(';').shift();
      }

      setTimeout(() => {
        console.log('grabing cookie from site and passing to LeadsHook');
        LH.setField('cookieFromSite_firstName', getCookie('_firstName'));
        LH.setField('cookieFromSite_lastName', getCookie('_lastName'));
        LH.setField('cookieFromSite_source', getCookie('_source'));
        LH.setField('cookieFromSite_fbp', getCookie('_fbp'));
      }, 1000);
</script>

Leave a Reply

Your email address will not be published.