Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
1.5 kB
2
Indexable
Never
<script>
  // Function to track button clicks
  function trackButtonClick(buttonName) {
    dataLayer.push({
      'event': 'buttonClick',
      'buttonName': buttonName
    });
  }

  // Function to track sidebar clicks
  function trackSidebarClick(sidebarItem) {
    dataLayer.push({
      'event': 'sidebarClick',
      'sidebarItem': sidebarItem
    });
  }

  // Assuming your form submission event is triggered by clicking a button with an ID of "submit-button"
  document.getElementById('submit-button').addEventListener('click', function() {
    // Get the user's name and phone number from form inputs
    var userName = document.getElementById('name-input').value;
    var userPhone = document.getElementById('phone-input').value;

    // Push an event to the data layer with the collected data
    dataLayer.push({
      'event': 'formSubmission',
      'userName': userName,
      'userPhone': userPhone
    });
  });

  // Track the initial page load
  dataLayer.push({
    'event': 'pageLoad',
    'pageLocation': window.location.href
  });

  // Track CTA button clicks
  document.getElementById('cta-button').addEventListener('click', function() {
    trackButtonClick('CTA Button Click');
  });

  // Track sidebar clicks
  document.getElementById('sidebar-item').addEventListener('click', function() {
    var sidebarItemText = this.textContent;
    trackSidebarClick(sidebarItemText);
  });

</script>