Advertisement
NikolayBezay

Leader integration for the Hight-q example embed..

Aug 18th, 2022 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.61 KB | None | 0 0
  1. <script>
  2. (function() {
  3. const FIELD_OF_INTEREST = 'פסיכומטרי';
  4. const LEAD_ORIGIN_SOURCE = 'Home_Site';
  5. const DOMAIN_ID = '5d0f5befc004f30274c87b2c';
  6. const ACTION_URL = 'https://us-east4-adoric-production.cloudfunctions.net/Support_leaderIntegration';
  7.  
  8. function sendWebhookLead(formData) {
  9. var data = {
  10. subscribe: formData,
  11. referrer: document.referrer,
  12. country: sessionStorage.getItem('country_code_cache'),
  13. action: ACTION_URL,
  14. enctype: '#',
  15. method: 'GET',
  16. campaignData: {
  17. options: {
  18. id: allCampaignData.id,
  19. userId: allCampaignData.options.userId,
  20. domainId: DOMAIN_ID,
  21. accountId: allCampaignData.options.userId,
  22. campaignTitle: allCampaignData.options.campaignTitle,
  23. title: allCampaignData.options.title,
  24. type: allCampaignData.options.type
  25. }
  26. }
  27. };
  28. var xhr = new XMLHttpRequest();
  29. xhr.addEventListener('readystatechange', function() {
  30. if (this.readyState === 4) {
  31. console.log('response - ', this.responseText);
  32. if (window.obApi) {
  33. obApi('track', 'Lead Artical');
  34. }
  35. }
  36. });
  37. xhr.open('POST', 'https://app.adoric-om.com/v1/forms/webhook');
  38. xhr.setRequestHeader('cache-control', 'no-cache');
  39. xhr.send(JSON.stringify(data));
  40. }
  41.  
  42. function sendAdoricLead(formData) {
  43. var data = {
  44. subscribe: formData,
  45. referrer: document.referrer,
  46. country: sessionStorage.getItem('country_code_cache'),
  47. campaignData: {
  48. options: {
  49. id: allCampaignData.id,
  50. userId: allCampaignData.options.userId,
  51. domainId: DOMAIN_ID,
  52. campaignId: allCampaignData.options.campaignId,
  53. accountId: allCampaignData.options.userId,
  54. campaignTitle: allCampaignData.options.campaignTitle,
  55. title: allCampaignData.options.title,
  56. type: allCampaignData.options.type
  57. }
  58. }
  59. };
  60. var xhr = new XMLHttpRequest();
  61. xhr.addEventListener('readystatechange', function() {
  62. if (this.readyState === 4) {
  63. console.log('response - ', this.responseText);
  64. }
  65. });
  66. xhr.open('POST', 'https://app.adoric-om.com/v1/forms/leads/subscribe', true);
  67. xhr.send(JSON.stringify(data));
  68. }
  69.  
  70. function getCookie(cname) {
  71. var name = cname + "=";
  72. var decodedCookie = decodeURIComponent(encodeURIComponent(document.cookie));
  73. var ca = decodedCookie.split(';');
  74. for (var i = 0; i < ca.length; i++) {
  75. var c = ca[i];
  76. while (c.charAt(0) == ' ') {
  77. c = c.substring(1);
  78. }
  79. if (c.indexOf(name) == 0) {
  80. return c.substring(name.length, c.length);
  81. }
  82. }
  83. return "";
  84. }
  85.  
  86. function getLbIdentifier() {
  87. var lbData = null;
  88. adoric.lightboxes.forEach(function(item) {
  89. if (item.options.campaignId === self.campaignId) {
  90. lbData = item;
  91. }
  92. });
  93. return lbData;
  94. }
  95. var form = document.querySelector('.' + self.identifier + ' [tabindex] form');
  96. var allCampaignData = getLbIdentifier();
  97. form.addEventListener('submit', function() {
  98. var name = form.querySelector('INPUT[name="fname"]');
  99. var phone = form.querySelector('INPUT[name="phone"]');
  100. var email = form.querySelector('INPUT[type="email"]');
  101. var apiKey = form.querySelector('INPUT[type="adoricApiKey"]');
  102. const DYNAMIC_FIELDS_LIST = ['utm_source', 'utm_campaign', 'utm_term', 'utm_content', 'utm_medium', 'AdPos', 'device', 'GeoLoc', 'content_site', 'AgId', 'cid', 'gclid', 'fbclid'];
  103. var formData = {
  104. field_of_interest: FIELD_OF_INTEREST,
  105. Formtype: 'Adoric',
  106. theurl: window.location.href,
  107. lead_origin_source: LEAD_ORIGIN_SOURCE,
  108. agree: 1
  109. };
  110. if (name) {
  111. formData.Fname = name.value;
  112. }
  113. if (phone) {
  114. formData.Phone = phone.value;
  115. }
  116. if (email) {
  117. formData.Email = email.value;
  118. }
  119. DYNAMIC_FIELDS_LIST.forEach(item => {
  120. if (getCookie('cc_' + item)) {
  121. formData[item] = getCookie('cc_' + item);
  122. }
  123. });
  124. if (apiKey) {
  125. formData.adoricApiKey = apiKey;
  126. } else {
  127. formData.adoricApiKey = '1637152141706';
  128. }
  129. formData.userId = allCampaignData.options.userId;
  130. formData.adoricSessionParams = '{}';
  131. formData.header = '{}';
  132. sendWebhookLead(formData);
  133. sendAdoricLead(formData);
  134. });
  135. })();
  136. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement