Advertisement
NikolayBezay

Ilmakiage form integration code.

Nov 17th, 2021
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.24 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         var productCodes = {
  4.             CNICON: 'ICON MASCARA',
  5.             CNLIP: 'LIP COLOR',
  6.             CNINK: 'INKLINER',
  7.             CNEYE: 'EYE PENCIL',
  8.             CNBROW: 'BROW PEN',
  9.             CNINF: 'INFINITY'
  10.         };
  11.  
  12.         function getLbIdentifier(campaignId) {
  13.             var lbIdentifier = null;
  14.             window.adoric && adoric.lightboxes.forEach(function(item) {
  15.                if (item.options.campaignId === campaignId) {
  16.                    lbIdentifier = item;
  17.                 }
  18.             });
  19.             return lbIdentifier;
  20.         }
  21.         var userCoupone = window.adoricUserCoupone;
  22.         var allCampaignData = getLbIdentifier(self.campaignId);
  23.         var form = document.querySelector('.' + self.identifier + ' FORM.inner-element');
  24.         var firstNameField = form.querySelector('INPUT[name="firstName"]');
  25.         var emailField = form.querySelector('INPUT[name="email"]');
  26.         var phoneField = form.querySelector('INPUT[name="phone"]');
  27.         var tagsField = form.querySelector('INPUT[name="tags"]');
  28.         tagsField.value = 'ADORIC GIFT - ' + productCodes[userCoupone];
  29.         try {
  30.             form.addEventListener('submit', function() {
  31.                 var data = {
  32.                     subscribe: {
  33.                         firstName: firstNameField.value,
  34.                         email: emailField.value,
  35.                         tags: tagsField.value,
  36.                         properties: {
  37.                             phone: phoneField.value,
  38.                         },
  39.                         userId: '5d21a205eff2e800127a41bb',
  40.                         adoricApiKey: "1564327075730"
  41.                     },
  42.                     referrer: '',
  43.                     country: '',
  44.                     action: 'https://app.remarkety.com/api/v1/stores/RmxBBbaY/contacts',
  45.                     enctype: '#',
  46.                     method: 'POST',
  47.                     campaignData: {
  48.                         options: {
  49.                             id: allCampaignData.id,
  50.                             userId: '5d21a205eff2e800127a41bb',
  51.                             domainId: '5d2326f79c71fc00b2f83099',
  52.                             accountId: allCampaignData.options.userId,
  53.                             campaignTitle: allCampaignData.options.campaignTitle,
  54.                             title: allCampaignData.options.title,
  55.                             type: allCampaignData.options.type
  56.                         }
  57.                     }
  58.                 };
  59.                 var xhr = new XMLHttpRequest();
  60.                 xhr.addEventListener('readystatechange', function() {
  61.                     var response = JSON.parse(this.responseText);
  62.                     if (this.readyState === 4) {
  63.                         var response = JSON.parse(this.responseText);
  64.                         console.log('response - ', response);
  65.                     }
  66.                 });
  67.                 xhr.open('POST', 'https://app.adoric-om.com/v1/forms/webhook');
  68.                 xhr.setRequestHeader('cache-control', 'no-cache');
  69.                 xhr.send(JSON.stringify(data));
  70.             });
  71.         } catch (error) {
  72.             console.log('Error - ', error);
  73.         }
  74.     })();
  75. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement