Cookie Consent Scan Project not detecting scripts on CMS templates

Description

When implementing cookie consent and using the app to scan the project it’s detecting all the scripts on the website except for the scripts that are on CMS pages. It seems to be scanning only the static pages.

Site URL

Required: Please provide a staging/production URL where we can see the issue

Steps to Reproduce

  1. [First step]
  2. [Second step]
  3. [Third step]

Expected Behavior

there are HubSpot forms on both Center and Center Program templates and they don’t seem to show up in the project scan.

Actual Behavior

I only see scripts from static pages and I think there should the ones from CMS pages too.

It looks like the forms that are not detected on the CMS templates are the same as the one on the Contact page.

Hello @Susan_MacPhee!

I am checking with the team on this.

In the meantime, you can manually add the categories to the script to make it compliant. To do this, make this the opening script tag in your current form code.

<script fs-consent-categories="essential" fs-consent-scripttype="text/javascript" type="fs-consent">

Basically, the embed code would go from this


<!--[if lte IE 8]>
  <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

<script>
  function createFkoHubspotForm() {
    pageUrlCrumb = window.location.href.split('/').slice(-1)[0];

    hbspt.forms.create({
      region: 'na1',
      portalId: '6951339',
      formId: '2b554793-235c-4b74-82f7-85e6963acae5',

      onFormReady: function ($form) {
        const selectedProgram = pageUrlCrumb;
        const selectedLocation = pageUrlCrumb.split('-')[0];

        $form.find('[name="form_submission_source_url"]').val(window.location.href);

        $('.hs_choose_program', $form).hide();
        const allProgramOptions = $('[name=choose_program]', $form).children();
        const allLocationOptions = $('[name=choose_location_contact_form]', $form).children();

        let currentLocation = null;

        $('[name=choose_location_contact_form]', $form).on('change', function (e) {
          currentLocation = this.value;
          currentLocationText = null;

          allLocationOptions.each(function (_, option) {
            if (option.value.startsWith(currentLocation)) {
              currentLocationText = option.innerHTML;
              console.log(currentLocationText);
            }
          });

          const currentProgramOptions = [];
          allProgramOptions.each(function (_, option) {
            if (option.value.startsWith(currentLocation)) {
              currentProgramOptions.push(option);
            }
          });

          $('[name=choose_program]', $form).empty();

          currentProgramOptions.forEach((option) => {
            option_updated = option;
            option_updated.innerHTML = option_updated.innerHTML.replace(currentLocationText, '');
            $('[name=choose_program]', $form).append(option_updated);
          });

          $('.hs_choose_program', $form).show();
        });

        if (selectedLocation) {
          console.log('selected location (hubspot form embed)', selectedLocation);
          $form
            .find('[name="choose_location_contact_form"]')
            .val(selectedLocation.toLowerCase())
            .change();
        }

        if (selectedProgram) {
          console.log('selected program (hubspot form embed)', selectedProgram);
          $('.hs_choose_program', $form).show();
          $form.find('[name="choose_program"]').val(selectedProgram.toLowerCase()).change();
        }
      },
    });
  }

  $(document).ready(function () {
    const selectedLocation = localStorage.getItem('selectedLocationSlug');
    const targetPaths = [
      '/center-programs/lynnwood-2soccer-01freekickoff',
      '/center-programs/lynnwood-2soccer-02individualtraining',
      '/events/lynnwood-free-kickoff',
    ];
    if ('lynnwood' === selectedLocation && targetPaths.indexOf(window.location.pathname) !== -1) {
      embedFkoIframe('#fko-contact-container', '528224');
    } else {
      createFkoHubspotForm();
    }
  });
</script>

To this

<!--[if lte IE 8]>
  <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2-legacy.js"></script>
<![endif]-->
<script
  charset="utf-8"
  type="fs-consent"
  src="//js.hsforms.net/forms/v2.js"
  fs-consent-categories="essential"
  fs-consent-scripttype="text/javascript"
></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>

<script fs-consent-categories="essential" fs-consent-scripttype="text/javascript" type="fs-consent">
  function createFkoHubspotForm() {
    pageUrlCrumb = window.location.href.split('/').slice(-1)[0];

    hbspt.forms.create({
      region: 'na1',
      portalId: '6951339',
      formId: '2b554793-235c-4b74-82f7-85e6963acae5',

      onFormReady: function ($form) {
        const selectedProgram = pageUrlCrumb;
        const selectedLocation = pageUrlCrumb.split('-')[0];

        $form.find('[name="form_submission_source_url"]').val(window.location.href);

        $('.hs_choose_program', $form).hide();
        const allProgramOptions = $('[name=choose_program]', $form).children();
        const allLocationOptions = $('[name=choose_location_contact_form]', $form).children();

        let currentLocation = null;

        $('[name=choose_location_contact_form]', $form).on('change', function (e) {
          currentLocation = this.value;
          currentLocationText = null;

          allLocationOptions.each(function (_, option) {
            if (option.value.startsWith(currentLocation)) {
              currentLocationText = option.innerHTML;
              console.log(currentLocationText);
            }
          });

          const currentProgramOptions = [];
          allProgramOptions.each(function (_, option) {
            if (option.value.startsWith(currentLocation)) {
              currentProgramOptions.push(option);
            }
          });

          $('[name=choose_program]', $form).empty();

          currentProgramOptions.forEach((option) => {
            option_updated = option;
            option_updated.innerHTML = option_updated.innerHTML.replace(currentLocationText, '');
            $('[name=choose_program]', $form).append(option_updated);
          });

          $('.hs_choose_program', $form).show();
        });

        if (selectedLocation) {
          console.log('selected location (hubspot form embed)', selectedLocation);
          $form
            .find('[name="choose_location_contact_form"]')
            .val(selectedLocation.toLowerCase())
            .change();
        }

        if (selectedProgram) {
          console.log('selected program (hubspot form embed)', selectedProgram);
          $('.hs_choose_program', $form).show();
          $form.find('[name="choose_program"]').val(selectedProgram.toLowerCase()).change();
        }
      },
    });
  }

  $(document).ready(function () {
    const selectedLocation = localStorage.getItem('selectedLocationSlug');
    const targetPaths = [
      '/center-programs/lynnwood-2soccer-01freekickoff',
      '/center-programs/lynnwood-2soccer-02individualtraining',
      '/events/lynnwood-free-kickoff',
    ];
    if ('lynnwood' === selectedLocation && targetPaths.indexOf(window.location.pathname) !== -1) {
      embedFkoIframe('#fko-contact-container', '528224');
    } else {
      createFkoHubspotForm();
    }
  });
</script>
1 Like

Thank you! I have replaced the your scripts with mine :wink:

1 Like