Jawad_Khan

cHTML - Elementor Form Tracking

Jan 5th, 2026
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. <script>
  2. (function() {
  3. var origXMLHttpRequest = XMLHttpRequest;
  4. XMLHttpRequest = function() {
  5. var requestURL;
  6. var requestMethod;
  7. var requestBody;
  8.  
  9. var xhr = new origXMLHttpRequest();
  10. var origOpen = xhr.open;
  11. var origSend = xhr.send;
  12.  
  13. // Override the `open` function.
  14. xhr.open = function(method, url) {
  15. requestURL = url;
  16. requestMethod = method;
  17. return origOpen.apply(this, arguments);
  18. };
  19.  
  20. xhr.send = function(data) {
  21. // Only proceed if the request URL matches what we're looking for.
  22. if (/.+\/admin-ajax\.php/.test(requestURL)) {
  23. xhr.addEventListener('load', function() {
  24. if (xhr.readyState === 4) {
  25. if (xhr.status === 200) {
  26. var response = JSON.parse(xhr.responseText);
  27.  
  28. if (response.success && (data instanceof FormData)) {
  29. requestBody = {};
  30. data.forEach(function(value, key) {
  31. requestBody[key] = value;
  32. });
  33.  
  34. if(requestBody.action === "elementor_pro_forms_send_form") {
  35. window.dataLayer = window.dataLayer || [];
  36. dataLayer.push({
  37. event: 'elementor_form_submit',
  38. inputs: requestBody
  39. });
  40. }
  41. }
  42. }
  43. }
  44. });
  45. }
  46.  
  47. return origSend.apply(this, arguments);
  48. };
  49.  
  50. return xhr;
  51. };
  52. })();
  53.  
  54. </script>
  55.  
Advertisement
Add Comment
Please, Sign In to add comment