What's your biggest current challenge? Have your say in Community Polls along the right column.

Track page history

Solved

Track page history

ariba-s
Tourist
8 0 2

I have two headers for two business categories, for the common pages such as contact-us, search, etc. I need to track the last page the user was on to know which header to show (header of category 1 or header of category 2). Is there a way to track visited pages in Shopify ?

Accepted Solution (1)
namphan
Shopify Partner
2044 269 297

This is an accepted solution.

Hi @ariba-s,

I understand your request, there will be 2 ways for you to do it:

1: You will always show 2 headers and use sessionStorage to check history, then add code to hide or show 1 of the 2 headers.

2: You use the cart properties object to add history and check it with Liquid code, and saving properties is also added by JS fetch.

I hope it helps!

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com

View solution in original post

Replies 7 (7)

namphan
Shopify Partner
2044 269 297

Hi @ariba-s,

You can just use Javascript for it, you can refer to sessionStorage

I hope it helps!

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com
ariba-s
Tourist
8 0 2

@namphan How can I access the session storage inside the liquid code. The way I do to change the header is like this inside theme.liquid
{% if home_pages contains template %}
     {% sections 'home-header-group' %}
{% else %}
     {% sections 'header-group' %}
{% endif %}

namphan
Shopify Partner
2044 269 297

Hi @ariba-s,

Both headers have links like contact-us, search, etc.

Sorry, I don't really understand your request, can you send me an example and send me the store link? I will check it again

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com
ariba-s
Tourist
8 0 2

for example contact-us will show the business header if the user was in a business page before clicking contact-us. However, if the user comes from a page of category home contact-us should show the home header. 

namphan
Shopify Partner
2044 269 297

This is an accepted solution.

Hi @ariba-s,

I understand your request, there will be 2 ways for you to do it:

1: You will always show 2 headers and use sessionStorage to check history, then add code to hide or show 1 of the 2 headers.

2: You use the cart properties object to add history and check it with Liquid code, and saving properties is also added by JS fetch.

I hope it helps!

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com
ariba-s
Tourist
8 0 2

Thank you @namphan 
I am using the first solution and it seems to be working for now. The only thing that I don't like is that I had to create two arrays one for the first category page templates and one for all the common page templates. Which I will have to update manually whenever we add a page to the website.  Also, I have to check the href based on a key word connected to the first category. All this make me feel that this solution is not robust even though it's working. 

How can I add history to the cart properties object ?

namphan
Shopify Partner
2044 269 297

Hi @ariba-s,

You can refer link

I hope it helps!

Coffee tips fuels my dedication.
Shopify Development Service
PageFly Page Builder Optimize your Shopify store (Free plan available)
Need help with your store? namphan992@gmail.com