Advertisement
nicolaslagios

Forminator WP trigger event

Jul 3rd, 2024 (edited)
537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.91 KB | Source Code | 0 0
  1. var fbtrigger = false;
  2. const observer = new MutationObserver(() => {
  3.     const element = document.getElementsByClassName('forminator-success')[0];
  4.     if (element && element.style.display === 'block') {
  5.         fbtrigger = true;
  6.         proxy.value = fbtrigger;
  7.     }
  8. });
  9. observer.observe(document.body, { childList: true, subtree: true });
  10. const proxy = new Proxy({ value: fbtrigger }, {
  11.     set: function(target, prop, value) {
  12.         if (prop === 'value' && target.value !== value) {
  13.             target.value = value;
  14.             if (value === true) {
  15.                 //fb lead event
  16.                 fbq('track', 'Lead');
  17.  
  18.                 //ga4 lead event
  19.                 gtag("event", "generate_lead", {
  20.                     currency: "EUR",
  21.                     value: 1,
  22.                     lead_source: "Forminator Lead",
  23.                   });
  24.             }
  25.         }
  26.         return true;
  27.     }
  28. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement