Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const setHiddenInputValues = function(form, params) {
- const inputs = form.elements;
- inputsArr = Array.apply(null, inputs);
- hiddenInputs = inputsArr.filter(function(i) {
- return i.type === 'hidden';
- });
- // set value of inputs to the params passed in
- hiddenInputs.forEach(function(i) {
- key = i.name;
- val = params[key];
- if (val) {
- i.value = val;
- }
- });
- };
- analytics.ready(function() {
- console.log("SEGMENT READY")
- const params = {
- path: window.location.pathname,
- url: window.location.href,
- search: window.location.search,
- referrer: document.referrer,
- title: document.title,
- anonymousId: analytics.user().anonymousId(),
- sessionId: amplitude.getSessionId(),
- userId: analytics.user().id()
- };
- // Grab all forms on the page, loop through them,
- // and set their hidden fields to the corresponding params.
- const $forms = document.getElementsByTagName("form");
- const formsArr = Array.apply(null, $forms);
- formsArr.forEach(function(f) {
- setHiddenInputValues(f, params)
- });
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement