{# Shared signup tracking trigger; heavy lifting lives in static/js/signup_tracking.js #}
{% if show_signup_tracking and environment.is_production and settings.GOBII_PROPRIETARY_MODE %}
<script>
(function() {
  function fireSignupTracking() {
    if (!window.GobiiSignupTracking || typeof window.GobiiSignupTracking.fetchAndFire !== 'function') {
      return;
    }
    window.GobiiSignupTracking.fetchAndFire({
      endpoint: '{% url "pages:clear_signup_tracking" %}',
      source: '{{ signup_tracking_source|default:"unknown" }}'
    });
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', fireSignupTracking, { once: true });
  } else {
    fireSignupTracking();
  }
})();
</script>
{% endif %}
