All things Shopify and commerce
Is there any way i can get the parameter and its value from url. For example,
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.
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
<script>
var cookieName = "cjevent"; // Name of your cookie
var cookieValue = {{URL- cjevent}}; // Value of your cookie
var expirationTime = 604800; // in seconds
expirationTime = expirationTime * 1000; // Converts expirationtime to milliseconds
var date = new Date();
var dateTimeNow = date.getTime();
date.setTime(dateTimeNow + expirationTime); // Sets expiration time (Time now + expiration time)
var date = date.toUTCString(); // Converts milliseconds to UTC time string
document.cookie = cookieName+"="+cookieValue+"; expires="+date+"; path=/; domain=." + location.hostname.replace(/^www\./i, ""); // Sets cookie for all subdomains
</script>
Tag firing priority of 99
cjevent trigger
Page URL contains cjevent
cjevent purchase Tag (replace *** with your CID & Type)
<script type="text/javascript">
sendCJTracking();
function sendCJTracking() {
var cjEvent = {{1st Party Cookie}};
var purchase = Shopify.checkout;
var cart = purchase.line_items;
var queryString = "";
var itemsDiscounts = 0;
var j = 0;
var itemsDiscounts;
for (i = 0; i < cart.length; i++) {
j = j + 1;
if (j == 1) {
queryString = "CID=*******&OID=" + purchase.order_id.toString();
if (i == 0) {
if (purchase.discount.code) {
queryString += "&COUPON=" + purchase.discount.code.replace(";", ",");
}
}
}
if (!isNaN(parseFloat(purchase.discount.amount))) {
itemsDiscounts = purchase.discount.amount.toString();
}
queryString += "&ITEM" + (i + 1).toString() + "=" + cart[i].sku.toString()
+ "&AMT" + (i + 1).toString() + "=" + cart[i].line_price.toString()
+ "&QTY" + (i + 1).toString() + "=" + cart[i].quantity.toString();
if (j == 50) {
queryString += "&CURRENCY=GBP&METHOD=IMG";
if (i == cart.length) {
if (itemsDiscounts) {
queryString += "&DISCOUNT=" + itemsDiscounts;
}
}
j = 0;
if (cjEvent) {
queryString += "&CJEVENT=" + cjEvent + "&TYPE=******";
}
addCJTracking(queryString);
}
}
if (j != 50) {
queryString += "&CURRENCY=GBP&METHOD=IMG";
if (itemsDiscounts) {
queryString += "&DISCOUNT=" + itemsDiscounts;
}
if (cjEvent) {
queryString += "&CJEVENT=" + cjEvent + "&TYPE=******";
}
addCJTracking(queryString);
}
}
function addCJTracking(queryString) {
var url_src = '//www.emjcd.com/u?' + queryString;
var dcIMG = document.createElement('img');
dcIMG.setAttribute('src', url_src);
dcIMG.setAttribute('height','1');
dcIMG.setAttribute('width','1');
dcIMG.setAttribute('border','0');
dcIMG.setAttribute('style','display:none');
document.body.appendChild(dcIMG);
}
</script>
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 🙂
{%- 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?
👏🏻 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!!
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025