Passing UTM Parameters To Modify Page In WordPress

I’m trying to modify the way my WordPress template displays content depending on the URL parameters. The first stage is to catch variables and store them for subsequent pageviews so that the user has a consistent layout of the site for their entire session.

<script>
// Parse the URL
function getURLParameter(name) {
name = name.replace(/[[]/, “[“).replace(/[]]/, “]”);
var regex = new RegExp(“[?&]” + name + “=([^&#]*)”),
results = regex.exec(location.search);
return results === null ? “” : decodeURIComponent(results[1].replace(/+/g, ” “));
}

islayout = getURLParameter(‘layout’);

if(islayout == “layout1”) {
localStorage.setItem(“layoutvalue”, 1);
}
else if(islayout == “layout2”) {
localStorage.setItem(“layoutvalue”, 2);
}
else if(islayout == “reset”) {
localStorage.setItem(“layoutvalue”, 0);
}
else {
var layoutvalue = 0;
}
</script>

Now, I just need to know how to pass these variables to the PHP level in wordpress so certain segments in the PHP code don’t load on the site. However, the tricky part comes into play because my site is cached.

When I tried passing the variables through PHP and had caching enabled…
User 1 (URL parameter = layout1) would set the settings for all following pageviews and seesions from other users. Then when user 2 would come along, they’d see the cached page layout which was set by user 1.

How can I have caching enabled but still allow them to all see a layout that’s unique to them.

Thanks.

Read more here:: Passing UTM Parameters To Modify Page In WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *