Skip to content

Commit

Permalink
Split JS functions, change the JSON content type to x-www-form-urlenc…
Browse files Browse the repository at this point in the history
…oded

Split JS functions, change the JSON content type to x-www-form-urlenc…
  • Loading branch information
ZoomREI authored Nov 21, 2024
2 parents 33b5cc0 + bcf5078 commit a15feb2
Show file tree
Hide file tree
Showing 8 changed files with 256 additions and 243 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => 'b0c5e04d7738918af100');
<?php return array('dependencies' => array(), 'version' => 'fa24eef6983052c7667c');
247 changes: 131 additions & 116 deletions wp-content/plugins/chris-buys-blocks/build/lead-form/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export function populateUtms(form, formData) {
let utms = {
'utm_source': 'utm',
'utm_term': 'utm',
'utm_campaign': 'utm',
'utm_medium': 'utm',
'utm_content': 'utm',
'device': 'utm',
'gclid': 'utm',
'fbclid': 'utm',
'msclkid': 'utm',
'page_url': ()=>{
return document.location.href
},
'lead_source': ()=>{
return localStorage.getItem('Initial_Lead_Source') || ''
},
'timestamp': ()=>{
return (new Date()).getTime()
},
'client_id': ()=>{
return '??'
},
'session_id': ()=>{
return '??'
},
'form_name': form.name,
}
let getParams = new URLSearchParams(window.location.search)

Object.keys(utms).forEach(function (utmName) {
if(utms[utmName] === 'get'){
if(getParams.get(utmName)) {
formData.set(utmName, getParams.get(utmName))
}
} else if(utms[utmName] === 'utm'){
let utmFromQuery= getParams.get(utmName);
let utmFromSession = sessionStorage.getItem(formConfig.storagePrefix + utmName);

if(utmFromQuery) {
formData.set(utmName, utmFromQuery)
} else if(utmFromSession){
formData.set(utmName, utmFromSession)
}
} else if(typeof utms[utmName] === 'function'){
formData.set(utmName, utms[utmName]())
} else {
formData.set(utmName, utms[utmName])
}
})

return formData;
}
export function getRedirectParams(formData, queries) {
let query = {}

queries.forEach(function (fieldData) {
let inputName = fieldData.field
let propName = fieldData.key

if(inputName === 'country'){
query[propName] = 'United States'
} else if(formData.get(inputName)) {
query[propName] = formData.get(inputName)
}
})

return new URLSearchParams(query).toString()
}
Loading

0 comments on commit a15feb2

Please sign in to comment.