Home > Questions and Answers > General Questions

Geo-Targeted Landers with PHP Code (15)


01-16-2019 04:40 PM #1 tihkal (Member)
Geo-Targeted Landers Question

Hey guys,

I've been trying to figure out how to make lander headlines and images change based on a user's GEO location. I would very much like to be able to change them based on the state they live in. I use Wordpress or ClickFunnels for all my landers. From what I've researched, it has something to do with changing the PHP code for the lander. Could anyone assist? I would greatly appreciate it.

Ryan


01-16-2019 04:56 PM #2 twinaxe (Senior Moderator)

Nice nick you have
Well, you could add the states to the lander URL, grab the values with PHP $_GET["value"] and then use if/else statements to display different headlines based on the state.


01-16-2019 08:19 PM #3 tihkal (Member)

Thanks twinaxe! In the lander URL, what format would I be adding the states? Something like ?value=Oregon if I wanted Oregon inserted into my headline and then add the PHP $ GET["value"] code into the lander headline where I want the state added?


01-16-2019 08:25 PM #4 matuloo (Legendary Moderator)

You can also do this with the help of some trackers, I assume you are using some. Most of them have pretty good GEO detection and most offer the option to pass this info into the lander URL by using the custom tokens. And from there, it only takes a simple php script to grab that info. My coder is doing this for me all the time.


01-16-2019 09:09 PM #5 tihkal (Member)

Sweet, thanks for the tip matuloo. I use Binom so I suppose I could just pass the GEO location using their custom tokens. Only thing I need to figure out still is the actual PHP script lol. Can't be anything too cosmic at all but I'm a novice at code as of now.


01-16-2019 11:00 PM #6 vortex (Senior Moderator)

This may help:

https://jennamolby.com/how-to-displa...rl-parameters/

Let me also find that post by caurmen for you...

Update: Found it here it is:

https://stmforum.com/forum/showthread.php?t=23109


Amy

Sent from my SM-G930W8 using STM Forums mobile app


01-16-2019 11:26 PM #7 tihkal (Member)

That's awesome! Thank you so much, Amy! Much obliged


01-16-2019 11:54 PM #8 Mr Baffoe (Veteran Member)

Here's a tutorial for a no code method built into Prosper202 http://prosper.tracking202.com/blog/...s-huge-results

To dynamically display the country you would do the following

Code:
Welcome I see you are reading this from <span name="t202Country" t202Default='Your Country'>Your Country</span>


01-17-2019 05:00 AM #9 erikgyepes (Moderator)

Just use dynamic tokens from your tracker.

Then you can do it even in pure JavaScript, there is no need to use server resources and PHP.

Here is how you do it in Voluum for example:

Code:
<script type="text/javascript">function getURLParameter(r){for(var t=window.location.search.substring(1).split("&"),n=0;n<t.length;n++){var e=t[n].split("=");if(e[0]===r)return e[1]}return""}</script>
The funciton above reads the tokens from the URL query.

Code:
<script>document.write(getURLParameter('country'))</script>
And this one prints them out in the code.

To make it work you simply send the token in the url as: /lander/folder/index.html?country={country}

If you still want to use PHP, you can grab the parameters using this function:

Code:
<?php echo $_GET['country']; ?>
This code actually works for any tracker, so you can use it in Binom too, just make sure you send in the tokens in the URL.


01-17-2019 06:02 AM #10 twinaxe (Senior Moderator)

Sure you can let the tracker attach the values but mostly trackers only support country and city and I supposed he meant the different states in USA.

And when the only change in the headline should be to display the name of the state then for sure the JS works.
But when he wants to use completely different headlines based on the state then I think PHP would be easier, I thought he would like to use PHP anyway as he mentioned PHP files.


01-17-2019 12:42 PM #11 matuloo (Legendary Moderator)

Quote Originally Posted by twinaxe View Post
Sure you can let the tracker attach the values but mostly trackers only support country and city and I supposed he meant the different states in USA.

And when the only change in the headline should be to display the name of the state then for sure the JS works.
But when he wants to use completely different headlines based on the state then I think PHP would be easier, I thought he would like to use PHP anyway as he mentioned PHP files.
Yup, definitely depends on the tracker the OP uses, I'm used to Voluum and they have this info down to the state/city info so we're taking advantage of it when needed. And yes, we're using php to display what we need


01-17-2019 01:28 PM #12 erikgyepes (Moderator)

Yeah, the solution I showed above works with states as well (in Voluum as they have this DB available)


01-17-2019 02:42 PM #13 Mr Baffoe (Veteran Member)

Quote Originally Posted by twinaxe View Post
Sure you can let the tracker attach the values but mostly trackers only support country and city and I supposed he meant the different states in USA.

And when the only change in the headline should be to display the name of the state then for sure the JS works.
But when he wants to use completely different headlines based on the state then I think PHP would be easier, I thought he would like to use PHP anyway as he mentioned PHP files.
Hmm interesting which tracker doesn’t have support for states?

These days the need for php to power dynamic page content is not as critical.

Javascript can also display completely different headlines based on the state detected. The huge benefit of this is that your page works 100% perfectly when hosted on a cdn for super fast page loads.

The both the personalization and multivarate testing feature in Prosper202 are being built with JavaScript with an optional php component.

Because, you are right, the php method is sometimes better for stuff like AdWords where quality score may depend on actual content rendered in the source and not dynamically created client side.


01-18-2019 12:51 AM #14 tihkal (Member)

Thank you all for the help! Very much appreciated as I am still learning coding. Still having some issues getting this to work properly. I originally had code from caurmen from this thread (https://stmforum.com/forum/showthrea...ing-Parameters). Below is the code I used with span id="city">your city</span> utilized in place of city name in my Wordpress post headline. I added the code in the Footer Code section. Should I maybe put it in the "text" section of the post or upload it as a .js file to my server?

<script type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[[]/, "[").replace(/[]]/, "]");
var regex = new RegExp("[?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/+/g, " "));
}
document.getElementById('city').innerHTML = getParameterByName("city") ;
</script>

Does Wordpress not pick up the JS when I add it to their post Footer Code section? I also tried the above code from erikgyepes, but couldn't get it to work either.

Thanks again all of you for the help!

Ryan



01-24-2019 05:01 AM #15 vortex (Senior Moderator)

Quote Originally Posted by tihkal View Post
Thank you all for the help! Very much appreciated as I am still learning coding. Still having some issues getting this to work properly. I originally had code from caurmen from this thread (https://stmforum.com/forum/showthrea...ing-Parameters). Below is the code I used with span id="city">your city</span> utilized in place of city name in my Wordpress post headline. I added the code in the Footer Code section. Should I maybe put it in the "text" section of the post or upload it as a .js file to my server?

<script type="text/javascript">
function getParameterByName(name) {
name = name.replace(/[[]/, "[").replace(/[]]/, "]");
var regex = new RegExp("[?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/+/g, " "));
}
document.getElementById('city').innerHTML = getParameterByName("city") ;
</script>

Does Wordpress not pick up the JS when I add it to their post Footer Code section? I also tried the above code from erikgyepes, but couldn't get it to work either.

Thanks again all of you for the help!

Ryan


I'm not a coder - but will bump this and hopefully someone else will help.

Perhaps try putting it in the header file?



Amy


Home > Questions and Answers > General Questions