Advertisement
NikolayBezay

High-q double integration to Adoric Leads.

Nov 27th, 2021
1,338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.50 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         function getLbIdentifier() {
  4.             var lbData = null;
  5.             window.adoric && adoric.lightboxes.forEach(function(item) {
  6.                if (item.options.campaignId === self.campaignId) {
  7.                    lbData = item;
  8.                 }
  9.             });
  10.             return lbData;
  11.         }
  12.         try {
  13.             var allCampaignData = getLbIdentifier();
  14.             var form = document.querySelector('.' + self.identifier + ' form.inner-element');
  15.             form.addEventListener('submit', function() {
  16.                 var allFormInputs = form.querySelectorAll('INPUT');
  17.                 var formData = {};
  18.                 for (var i = 0; i < allFormInputs.length; i++) {
  19.                    if (allFormInputs[i].getAttribute('name') !== 'sumbit') {
  20.                        fieldName = allFormInputs[i].getAttribute('name');
  21.                        fieldValue = allFormInputs[i].value;
  22.                        formData[fieldName] = fieldValue;
  23.                        console.log(fieldName, '=', fieldValue);
  24.                    }
  25.                }
  26.                var data = {
  27.                    subscribe: formData,
  28.                    referrer: document.referrer,
  29.                    country: sessionStorage.getItem('country_code_cache'),
  30.                    campaignData: {
  31.                        options: {
  32.                            id: allCampaignData.id,
  33.                            userId: '5cff9fa94bd8540390fe7115',
  34.                            domainId: '5d0f5befc004f30274c87b2c',
  35.                            campaignId: allCampaignData.options.campaignId,
  36.                            accountId: allCampaignData.options.userId,
  37.                            campaignTitle: allCampaignData.options.campaignTitle,
  38.                            title: allCampaignData.options.title,
  39.                            type: allCampaignData.options.type
  40.                        }
  41.                    }
  42.                };
  43.                var xhr = new XMLHttpRequest();
  44.                xhr.addEventListener('readystatechange', function() {
  45.                    if (this.readyState === 4) {
  46.                        console.log('response - ', this.responseText);
  47.                    }
  48.                });
  49.                xhr.open('POST', 'https://app.adoric-om.com/v1/forms/leads/subscribe', true);
  50.                xhr.send(JSON.stringify(data));
  51.            });
  52.        } catch (error) {
  53.            console.log(error);
  54.        }
  55.    })();
  56. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement