You have the ability to add in a code to display the brand and the name/model of your visitor's device if you wish to pass those variables over to your landing page URL.
This code can be found under Landing Pages > Get LP Code > Recommended code Specifically for Calling Out Device.
Let's go over this a little more in detail to get you started:
Example PHP Code to Call Out Device
In this example, we will be using the following variables to pass into our landing page URL:
- b={devicebrand}
- n={devicename}
- m={devicemodel}
Please make sure that you ensure that the parameters you are using in the script (brand, name, model) are strings that match your variables in your actual lander URL.
Example of how my lander URL would look when using the above parameters:
<?php
function getDeviceInfoFromQueryString($brand=null, $name=null, $model=null) {
if($brand === null || !isset($_GET[$brand]) || $_GET[$brand] == '') {
$out = array('device');
} else {
$out = array($_GET[$brand]);
}
if($name !== null && isset($_GET[$name]) && $_GET[$name] != '') {
$out[] = $_GET[$name];
} elseif($model !== null && isset($_GET[$model]) && $_GET[$model] != '') {
$out[] = $_GET[$model];
}
return implode(' ', $out);
}
// call the getDeviceInfoFromQueryString function with the names of your variables ('b', 'n', 'm') or whatever you had in place of
// b={brand}, n={name}, and m={model}
echo getDeviceInfoFromQueryString('b', 'n', 'm');
?>
Notes:
If brand is blank, then "device" will be used instead
If name is blank, then whatever is in the model will be used
If model is also blank, then nothing will be used for the name or model, a.k.a. the brand will be used only
Example JavaScript Code to Call Out Device
In this example, we will be using the following variables to pass into our landing page URL:
- b={devicebrand}
- n={devicename}
- m={devicemodel}
Place the below script in the header of your page after the opening <head> tag.
<script type="text/javascript">
var getDeviceInfoFromQueryString = function (brand, name, model) {
var urlRaw = location.search.substring(1);
var b = "device";
var n = "";
var m = "";
var vars = urlRaw.split('&');
var pairs = {};
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
pair[1] = pair[1].replace(/(\+|%20)/g, ' ');
pairs[pair[0]] = pair[1];
}
console.log(pairs);
if (pairs[brand] != '') {
b = pairs[brand];
}
if (pairs[name] != '') {
n = pairs[name];
} else if (pairs[model] != '') {
m = pairs[model];
}
return b + ' ' + n + ' ' + m;
}
</script>
Note: Towards the top of the script that goes in the header where the variables are listed, you can add in default information here if you want it to include something in case the device information is not passed through.
Example:
var b = "Apple";
var n = "";
var m = "iPhone";
This allows you to define a default value in case the device information isn't passed to the landing page URL. When the expected values are passed to the LP URL, then they would replace those default values.
If you also want to add in a Pop-Up Alert, you can add this under the above information in the header of your page:
<script> alert("YOUR TEXT HERE " + getDeviceInfoFromQueryString('b', 'n', 'm') + " CONTINUE YOUR TEXT"); </script>
Then, in the body of your page, after the <body> tag, you will place the below script in any area that you want to call out the variable:
<script>document.write(getDeviceInfoFromQueryString('b','n','m'));</script>
Comments
0 comments
Please sign in to leave a comment.