Webhook Parameters always null

1 0 0


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

Replies 2 (2)

Shopify Partner
16 1 2

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'



// 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);


    //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:

  1. Find the parameter you are looking for
  2. When you find it, save it in a cookie
  3. If you haven't found it, see if the cookie exists
  4. If the cookie exists, get the parameter you are looking for and add it to the URL
  5. If the cookie doesn't exist, do nothing

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.

Click to expand...
Shopify Partner
2 0 0

hello, please how do i add these codes