I'm trying to set up a page so that it will personalize some content based on the query string. For example, if the query string is ?company=xyz, I would want the H1 to show up as "Welcome XYZ"
Here are the steps I took
1) Add custom HubL to a template: <h1>Welcome {{ request.query.company|default('Acme Corp')}}</h1>
2) Add the query string of ?company=xyz to the end of the url and test
The result is always the default of "Acme Corp" instead of what is in the query string. Any idea what I am doing wrong?
Fact is there aren't to many things that can go wrong with something simple like this so strip it down to its most basic. It could possibly have something to do with the missing space in your h1.
Is there an easy to way pass the query string to other pages as well? For example, they arrive at acme.com/product?company=test and they then click on pricing in the nav. I'd like the personalization to continue to that page so I would need the url to be acme.com/pricing?company=test.
You should be able to add a variable behind your urls so that the urls always have the current query appended. This might be more difficult for advanced menus. You could also use javascript to capture the query and append it to all links on the page.
var params = window.location.search, dest = $(this).attr('href') + params;
// in my experience, a short timeout has helped overcome browser bugs window.setTimeout(function() { window.location.href = dest; }, 100); }); </script>