but I still think you need to check if the url you...
# suitescript
c
but I still think you need to check if the url you are getting back is what you actually want. would add alert(url) the line before the document.getElementById('ns_form').action = url;
👍 1
p
Interesting, so I'm getting back undefined&leadsource=Test in the alert.
c
sounds right
function appendNSParams(url) { var nameEQ = "leadsource="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) url = 'https://forms.na3.netsuite.com/app/site/crm/externalleadpage.nl?compid=xxxx&amp;formid=xxxxxxxx' + '&' + nameEQ + c.substring(nameEQ.length, c.length); } document.getElementById('ns_form').action = url; }
here when the code is setting url, I changed the variable that was "undefined" to the url of your form action. you will need to adjust for your compid and form id of course
add the alert(url) again too, to validate the url
p
Not sure if that will work for me since we use different forms on different pages. The goal of this was to be able to be able to track google adwords campaigns back to individual form fills. Different pages may have a different formid and we just want to update the leadsource.
c
function appendNSParams(url) { var nameEQ = "leadsource="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) url = document.getElementById('ns_form').action + '&' + nameEQ + c.substring(nameEQ.length, c.length); } document.getElementById('ns_form').action = url; }
here it grabs the form's current action and then adds the param leadsource
do you have more than 1 form on a single page?
p
Nope
c
this should work dynamically then as long as the id you use for every form is id="ns_form"
hope it copy pastes ok, can't do snippets in the thread
p
Seems alright. I'll run a test
So it seems that when I actually have leadsource= in the URL it works (WOOHOO!). However, when I remove parameters and submit it tries to redirect to mywebsite.com/landing-page/undefined
c
my bad, I should have seen that coming.
function appendNSParams(url) { var nameEQ = "leadsource="; var url = document.getElementById('ns_form').action; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) url = url + '&' + nameEQ + c.substring(nameEQ.length, c.length); } document.getElementById('ns_form').action = url; }
p
No dice on that one. Doesn't seem to place the leadsource through. I do greatly appreciate all your help here.
c
sure you have a leadsource cookie?
p
Lol no I am not. I was just using the script that was provided in the help doc. I'm looking into how to create one now.
c
the script should be doing it, I was wondering if in your test if you had set leadsource=test in the url of the wordpress page
here's how you can tell if it is set in Chrome:
p
Oh yes I am. I'm actually replacing leadsource with campaignevent. The url is mywebsite.com/landing-page/?utm_souce=test&amp;campaignevent=560.
c
oh, so in the code you use campaignevent
p
Correct I am doing that. It was working no problem incognito mode, but that's when I started running into the /undefined issue as the browser was cookied.
c
in the trackNSParams function, you updated the word leadsource to campaignevent yes?
and the function I'm sending you?
p
yep
It does appear that the cookie is working
via the developer tools
c
ok, and when you submit, it alerts and there is nothing for campaignevent in the url that is alerted?
add the alert(url) and test both with and without the cookie and let me know the results
p
Doing that now
Alright dude I think it's working correctly. Did some testing and all seems to be in order. I was running into a couple of issues and it may have been related to needing to close and reopen incognito windows.
I can't thank you enough for your help. I definitely learned a lot from this.
P.S. where can I send the pizza?
c
That's awesome. I've gotten some good answers out of this slack group, just glad I could finally help someone with my domain knowledge.
p
Likewise I contribute where I can as well. This one was definitely among the more complicated for me.