APIs & Integrations

b_sklodowski
Member

Personalization based on query string data

SOLVE

Hello!

Does anybody know how to personalize a landing page to display firstname and last name, by using query string info (?firstname=XXX&lastname=YYYY) rather than byusing existing contact properties (tokens).
Let's say I have a landing page at domain.com/123 that begins with

"Hello, "

What I want to achieve is for anyone that visits this landing page using the URL: domain.com/123?firstname=John&lastname=Smith the first line displays "Hello John Smith," rather than just "Hello"

I suppose it can be done using Java Script. Can anyone help with some ideas? :slight_smile:
Thanks

0 Upvotes
1 Accepted solution
Derek_Gervais
Solution
HubSpot Alumni
HubSpot Alumni

Personalization based on query string data

SOLVE

Hi @b.sklodowski,

If this is on a HubSpot page, you can use the default {{ request.query }} and/or {{ request.query_dict }} HubL variables. Some more info on these variables can be found in the designer docs:

View solution in original post

0 Upvotes
6 Replies 6
Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Personalization based on query string data

SOLVE

Hi @kaitmaag,

Query string parameters are simple key/value pairs added to the end of a URL, like this:

https://www.example.com/stuff?firstname=Derek

In this example, the key is firstname and the value is Derek. The aforementioned code snippet:

{{ request.query_dict.firstname }}

Would be replaced by Derek on a landing page. Does that answer your question?

b_sklodowski
Member

Personalization based on query string data

SOLVE

Thank you very much! This works 100%

Derek_Gervais
HubSpot Alumni
HubSpot Alumni

Personalization based on query string data

SOLVE

Hi @b.sklodowski,

That particular variable is a dictionary, so you should be able to select specific fields using dot notation:

{{ request.query_dict.firstname }}

0 Upvotes
kaitmaag
Member

Personalization based on query string data

SOLVE

Hey Derek - I was referred here by Hubspot chat support. I am trying to use a query string in the link of my Hubspot hosted landing page to populate the contact's first name into the landing page header. My example is very similar to what is listed above but I do not understand how to create the custom query string so that it pulls the appropriate name. Can you help?

0 Upvotes
Derek_Gervais
Solution
HubSpot Alumni
HubSpot Alumni

Personalization based on query string data

SOLVE

Hi @b.sklodowski,

If this is on a HubSpot page, you can use the default {{ request.query }} and/or {{ request.query_dict }} HubL variables. Some more info on these variables can be found in the designer docs:

0 Upvotes
b_sklodowski
Member

Personalization based on query string data

SOLVE

Hi Derek, thank you for the tip! This seems to bring me a little bit closer, but when I use {{ request.query_dict }} variable it displays the whole query string including utms and so on, so the first line looks like

Hello {firstname=John, lastname=Smith, utm_campaign=thecampaign...}

And furthermore it is all inside the { } brackets. Any ideas how to improve it ? :slight_smile:

0 Upvotes