Advertisement
orenchuck

send adoric lead collected all fields

Jul 15th, 2022 (edited)
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <script>
  2. (function() {
  3. const currentLB = document.querySelector('.' + self.identifier + '.__ADORIC__ [tabindex]');
  4.  
  5. function sendAdoricLead() {
  6. try {
  7. const inputs = currentLB.querySelectorAll('form input');
  8. const inputsData = {};
  9. Array.from(inputs).forEach(i => {
  10. const name = i.getAttribute('name');
  11. if (name !== 'submit') {
  12. inputsData[name] = currentLB.querySelector('INPUT[name="' + name + '"]').value;
  13. }
  14. });
  15. var currentCampaign = adoric.lightboxes.filter(function(lb) {
  16. return lb.id === self.versionId
  17. })[0];
  18. var data = {
  19. subscribe: inputsData,
  20. referrer: document.referrer,
  21. campaignData: {
  22. options: {
  23. id: self.versionId,
  24. userId: currentCampaign.options.userId,
  25. domainId: self.domainId,
  26. campaignId: currentCampaign.options.campaignId,
  27. accountId: currentCampaign.options.userId,
  28. campaignTitle: self.campaignTitle,
  29. title: self.versionTitle,
  30. type: currentCampaign.options.type,
  31. }
  32. }
  33. };
  34. var xhr = new XMLHttpRequest();
  35. xhr.addEventListener('readystatechange', function() {
  36. if (this.readyState === 4) {
  37. console.log('response - ', this.responseText);
  38. }
  39. });
  40. xhr.open('POST', 'https://app.adoric-om.com/v1/forms/leads/subscribe', true);
  41. xhr.send(JSON.stringify(data));
  42. } catch (error) {
  43. console.log(error);
  44. }
  45. }
  46. const form = currentLB.querySelector('form');
  47. form.addEventListener('submit', () => {
  48. sendAdoricLead();
  49. });
  50. })();
  51. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement