How to pass a parameter and its value from url to liquid

Is there any way i can get the parameter and its value from url. For example,

www.test.com/?parameter=value

I should get parameter and value to a variable in liquid.

What’s the use case? In most cases expect the answer to be no but there’s some hacky approaches that can work depending on where you want this to happen.

Here is my case, hopefully this example applies.

  1. Customer is sent to the site via affiliate in the cj network.
  2. Within the URL, there is a “cjevent=ABC123” parameter.
  3. I want to store that as a cart attribute or in a cookie, somewhere that is readable later in the customer’s journey.
  4. Customer checks out.
  5. I pass the given parameter in the response to the cj tracking pixel, listed in the additional scripts in checkout.

Any help here would be appreciated! Cheers!

Hey Nelson, did you ever get any insight into this from folks? Or perhaps figure it out on your own? We’re trying to do the same CJEVENT update, but can’t get it to work. Any insight would be greatly appreciated!

Hi Interstellar,

I solved it by installing GTM and using Javascript to handle it.

If you have Shopify Plus:Use this to install GTM: https://help.shopify.com/en/manual/reports-and-analytics/google-analytics/google-tag-manager (You’ll have to ask your account manager to give you access to the checkout template.)

If you do not have plus, you’ll have to figure out a different way to install GTM. I’m sure there are apps that’ll help you do it.

Then just create the following tags, variables, and triggers.

cjevent - Tag

Tag firing priority of 99

cjevent trigger

Page URL contains cjevent

cjevent purchase Tag (replace *** with your CID & Type)

Tag firing priority (silly I know) :1000000000000000000

cjevent purchase trigger

Page URL contains thank_you

1st Party Cookie Variable

Variable type=1st party cookie

Cookie Name: cjevent

URL- cjevent

Variable Type: URL

Query Key: cjevent

Hey here is a way we can achieve the same

https://freakdesign.com.au/blogs/news/get-the-url-querystring-values-with-liquid-in-shopify

Is there any update on this? This is a basic back end function and to have no access to it in Liquid really limits customization options when passing variables.

try this :slightly_smiling_face:

{%- capture contentForQuerystring -%}{{ content_for_header }}{%- endcapture -%}
{%- assign plan_name = contentForQuerystring | split:'"pageurl":"' | last | split:'"' | first |
   replace:'\/','/' |
   replace:'%20',' ' |
   replace:'\u0026','&' |
   split: "?" | last
-%}

how to get the content_for_header?

:clap:t2: Lot of resources on the Internet say it’s not possible to get URL parameters on Shopify without ugly JS hacks etc, this answer is perfect and was the end of hours of searching trying to solve an issue with hreflang tags and pagination - thank you Tom!!