Output the amount of selected facets

<?php
// Outputs the number of active/selected facets in use.
// Optionally exclude your pager and/or sort facets (or any other facet)

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 );