Topics covering webhook creation & management, event handling, Pub/Sub, and Eventbridge, in Shopify apps.
Hello,
we have problems getting some Parameters filled in the json returned by a webhook (order creation webhook)
Following szenario:
We have an affiliate System.
Visitor A is sent to the shop By Affilita A with a special link (the link is created by our shortener). Now if Visitor A is ordering, we need the referring URL (so the shortener url) OR the ?ref=xyz parameter. (The Shortener redirects to ourshopifyshop.com/product/?ref=xyz). (So far we dont even get this information from the webhook)
Now 2 hours later Visitor A (the same person as before) is sent to the shop by Affiliate B and orders something new .. now we need of course again the referring URL OR the NEW ?ref=zyx parameter.
As i got explained from the customer service, the ref parameter will be the same until the visitor cleans his cookies .. but thats not really what a normal person is doing.. so ..
how can i solve this problem? The best way would be to geht the referring url .. so i can filter my params out..
Thank you very much for help
The `?ref=xyz` -parameter do not work for me, too. You could try my little workaround:
Insert a Shopify-Scripttag:
'scripttags' => [
[
'src' => 'https://{domain}/scripttags/dummy.js',
'event' => 'onload',
'display_scope' => 'online_store'
]
]
dummy.js:
// some cookie functions
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
//get params
const url_string = window.location.href;
const url_object = new URL(url_string);
const my_param = url_object.searchParams.get("my_param");
if (my_param != null) {
//set cookie
setCookie('my_param', my_param);
}else{
//get cookie
let my_param_cookie = getCookie('my_param');
if (my_param_cookie) {
//set params from cookie
let url_all_params = '';
const url_pathname = url_object.pathname;
const url_params = url_object.search;
const url_seperator = url_params == '' ? '?' : '&';
const url_my_param = my_param == null ? 'my_param=' + my_param_cookie : my_param;
url_all_params = url_pathname + url_params + url_seperator + url_my_param;
if (history.pushState) {
window.history.pushState({}, "", url_all_params);
} else {
document.location.href = url_all_params;
}
}
}
To the code above:
This will make the referring_site look like this in the order webhook:
"referring_site": https://{shop}.myshopify.com/products/testprodukt-1/?myparam=1
Now you can do what you want with the parameter in the backend, I hope I could help or provide inspiration.
hello, please how do i add these codes