Output the amount of selected/active facets in use

<?php
// Outputs the number of active/selected facets in use.
// Optionally exclude your Pager and/or Sort facets (or any other facet)
// Also see:
// https://facetwp.com/help-center/developers/javascript-reference/js-objects-and-functions/#output-the-number-of-active-facets
// To out the number of active facet choices instead, see:
// https://facetwp.com/help-center/developers/javascript-reference/js-objects-and-functions/#output-the-number-of-active-facet-choices

add_action( 'wp_head', function() {
  ?>
    <script>
      document.addEventListener('facetwp-loaded', function() {
        var count = 0;
        Object.entries(FWP.facets).forEach(([name, val]) => {
          if (name !== 'mypagerfacetname' && name !== 'mysortfacetname' && val.length > 0) {
            count ++;
          }
        });
        console.log(count);
      });
    </script>
  <?php
}, 100 );