NikolayBezay

Chef-lavan additional integration to marketing cloud.

May 21st, 2021
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.59 KB | None | 0 0
  1. <script>
  2.     (function() {
  3.         function getLbData() {
  4.             var lbData = null;
  5.             adoric.lightboxes.forEach(function(item) {
  6.                 if (item.options.campaignId === self.campaignId) {
  7.                     lbData = item;
  8.                 }
  9.             });
  10.             return lbData;
  11.         }
  12.         var form = document.querySelector('.' + self.identifier + ' [tabindex] form');
  13.         var allCampaignData = getLbData();
  14.         form.addEventListener('submit', function() {
  15.             var userName = form.querySelector('INPUT[name="firstName"]');
  16.             var email = form.querySelector('INPUT[name="emailAddress"]');
  17.             var checkBoxField = form.querySelector('INPUT[type="checkbox"]');
  18.             userName ? userName = userName.value : userName = '';
  19.             email ? email = email.value : email = '';
  20.             checkBoxField ? checkBoxField = checkBoxField.value : checkBoxField = '';
  21.             var data = {
  22.                 subscribe: {
  23.                     email: email,
  24.                     newsletterapproved: checkBoxField,
  25.                     firstname: userName,
  26.                     adoricApiKey: '1621416163064',
  27.                     userId: '5e4ea052e98c750012b2c583',
  28.                     header: '{}'
  29.                 },
  30.                 referrer: document.referrer,
  31.                 country: sessionStorage.getItem('country_code_cache'),
  32.                 action: 'https://us-east4-adoric-production.cloudfunctions.net/Support_chef_lavan_integration',
  33.                 enctype: '#',
  34.                 method: 'GET',
  35.                 campaignData: {
  36.                     options: {
  37.                         id: allCampaignData.id,
  38.                         userId: allCampaignData.options.userId,
  39.                         domainId: "5e66050a27c6d400185bf304",
  40.                         accountId: allCampaignData.options.userId,
  41.                         campaignTitle: allCampaignData.options.campaignTitle,
  42.                         title: allCampaignData.options.title,
  43.                         type: allCampaignData.options.type
  44.                     }
  45.                 }
  46.             };
  47.             var xhr = new XMLHttpRequest();
  48.             xhr.addEventListener('readystatechange', function() {
  49.                 if (this.readyState === 4) {
  50.                     console.log('response - ', this.responseText);
  51.                 }
  52.             });
  53.             xhr.open('POST', 'https://app.adoric-om.com/v1/forms/webhook');
  54.             xhr.setRequestHeader('cache-control', 'no-cache');
  55.             xhr.send(JSON.stringify(data));
  56.         });
  57.     })();
  58. </script>
Advertisement
Add Comment
Please, Sign In to add comment