Home > Technical & Creative Skills > Programming, Servers & Scripts

GetURLParameter problems. (8)


06-19-2018 02:34 PM #1 j80montes (AMC Alumnus)
GetURLParameter problems.

Hello everyone.
I've got some problems about getURLParameter. First of all,should I add ?brand=Whateverbrand&country_name=Whatevercountry and all of remaining parameters to my landing page URL for replacing it for me with the correct value automatically.And if it was right,is the writing of parameter like parameter=Whatever+the name of parameter.For instance,the parameter is isp so I should add isp=Whateverisp to my landing page URL.

Code:
<script>
function getURLParameter(name) {
    return decodeURI(
        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
    );
}
</script>
</head>
<body>
<div class="q"><div class="b r"><img src="cadeau.png">
<table class="c">
<tbody>
<tr>
<td>Date:</td>
<td><script>document.write(d());</script></td>
</tr>
<tr>
<td><b>User reference:</b></td>
<td>BeQuick-938123-47</td>
</tr>
<tr>
<td><b>Country:</b></td>
<td><script>document.write(getURLParameter("country"));</script>AU</td>
</tr>
</tbody>
</table></div>
<div id="copy">
<h1>Dear <script>document.write(getURLParameter("isp"));</script>Telstra Internet User, Now Is Your Chance To Win $15,000 cash, FREE!</h1>
<p>We want to thank you for being a loyal <script>document.write(getURLParameter("country"));</script>AU<script>document.write(getURLParameter("isp"));</script>Telstra Internet
user! Your IP address <script>document.write(getURLParameter("ip"));</script>144.138.238.128 has been randomly selected to receive <b>FREE $15,000 in cash!</b>.
</p><p>Every month we select a few <script>document.write(getURLParameter("isp"));</script>Telstra Internet users to receive premium gifts from our sponsors. This is our way of thanking and repaying you for choosing <script>document.write(getURLParameter("isp"));</script>Telstra Internet as your preferred service.


06-19-2018 02:58 PM #2 twinaxe (Senior Moderator)

No, you add the parameter plus the token from your tracker to the URL.
For example this is how a landing page URL from my tracker would look like

http://mylandingpagedomain.com/index.html?brand={device_brand}&model={device_mode l}&browser={browser_name}&browserversion={browser_ version}&os={os_name}&osversion={os_version}&isp={ isp}&city={city}&ip={ip}

The tracker then recognizes the tokens and replaces them with the appropriate values


06-19-2018 03:00 PM #3 platinum (Veteran Member)

Can you try replacing the following script:

Code:
<script>
    function getURLParameter(name) {
        return decodeURI(
            (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
        );
    }
    </script>

with this one?
Code:
<script>
function getURLParameter(name) {  
var query = window.location.search.substring(1);  
var vars = query.split("&");  
for (var i=0;i<vars.length;i++) {  
var pair = vars[i].split("=");  
if(pair[0] === name){return pair[1];}  
}  
return "";
}
</script>


06-20-2018 02:25 AM #4 j80montes (AMC Alumnus)

Quote Originally Posted by twinaxe View Post
No, you add the parameter plus the token from your tracker to the URL.
For example this is how a landing page URL from my tracker would look like

http://mylandingpagedomain.com/index.html?brand={device_brand}&model={device_mode l}&browser={browser_name}&browserversion={browser_ version}&os={os_name}&osversion={os_version}&isp={ isp}&city={city}&ip={ip}

The tracker then recognizes the tokens and replaces them with the appropriate values
Thanks for your help.So landing pages URL from tracker would look like http://mylandingpagedomain.com/index.html?brand={device_brand}&model={device_mode l}&browser={browser_name}&browserversion={browser _ version}&os={os_name}&osversion={os_version}&isp={ isp}&city={city}&ip={ip} whatever my tracker is?(My tracker is Voluum.)And should I delete the values like brand in the code?Last,country={country_name}?


06-20-2018 02:29 AM #5 j80montes (AMC Alumnus)

Quote Originally Posted by platinum View Post
Can you try replacing the following script:

Code:
<script>
    function getURLParameter(name) {
        return decodeURI(
            (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
        );
    }
    </script>

with this one?
Code:
<script>
function getURLParameter(name) {  
var query = window.location.search.substring(1);  
var vars = query.split("&");  
for (var i=0;i<vars.length;i++) {  
var pair = vars[i].split("=");  
if(pair[0] === name){return pair[1];}  
}  
return "";
}
</script>
Thanks for you help.In this way,I needn't add anything to my URL or not?And should I delete the values like brand in the code?


06-20-2018 06:18 AM #6 platinum (Veteran Member)

@j80montes you should keep the parameters appended in your url with the respective tokens as suggested by twinaxe. Those are the parameters that the script will read from and dynamically display the information in your lander.


Sent from my iPhone using STM Forums mobile app


06-20-2018 06:37 AM #7 twinaxe (Senior Moderator)

Yes, your landing page URL would look like this.
But you use Voluum and I use Binom so you need to change the tokens to the ones that Voluum uses.
Otherwise the tokens won't be interpreted correct.

And yes, you delete the actual values from the code but you keep the JS there so that the values will be inserted dynamically.

About the country token, I can't tell if it works or not in Voluum.
You better check Voluums documentation for it.

About the JS code platinum posted, of course you still need to add the parameters and tokens to the URL, otherwise it won't work because there would be no values to get from the URL.


06-20-2018 02:21 PM #8 j80montes (AMC Alumnus)

Thank you again!


Home > Technical & Creative Skills > Programming, Servers & Scripts