Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. const setHiddenInputValues = function(form, params) {
  2. const inputs = form.elements;
  3. inputsArr = Array.apply(null, inputs);
  4.  
  5. hiddenInputs = inputsArr.filter(function(i) {
  6. return i.type === 'hidden';
  7. });
  8.  
  9. // set value of inputs to the params passed in
  10. hiddenInputs.forEach(function(i) {
  11. key = i.name;
  12. val = params[key];
  13. if (val) {
  14. i.value = val;
  15. }
  16. });
  17. };
  18.  
  19.  
  20. analytics.ready(function() {
  21. console.log("SEGMENT READY")
  22. const params = {
  23. path: window.location.pathname,
  24. url: window.location.href,
  25. search: window.location.search,
  26. referrer: document.referrer,
  27. title: document.title,
  28. anonymousId: analytics.user().anonymousId(),
  29. sessionId: amplitude.getSessionId(),
  30. userId: analytics.user().id()
  31. };
  32.  
  33. // Grab all forms on the page, loop through them,
  34. // and set their hidden fields to the corresponding params.
  35. const $forms = document.getElementsByTagName("form");
  36. const formsArr = Array.apply(null, $forms);
  37.  
  38. formsArr.forEach(function(f) {
  39. setHiddenInputValues(f, params)
  40. });
  41. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement