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?
We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024