Skip to main content

Non attributed fix

If you have a lot of non attributed orders, then this will fix your issue.

Moritz Fenske avatar
Written by Moritz Fenske
Updated over a week ago

This instruction has 2 steps:

Add this script to theme.liquid

Change YOURSHOPIFYNAME with your Shopify shop name.

<script async src="https://storage.googleapis.com/tp_script/YOURSHOPIFYNAME.myshopify.com/config.js"></script>

Example

This is your admin URL: https://admin.shopify.com/store/test

Then test is your Shopify shop name.

Then replace YOURSHOPIFYNAME with test.

So your final script that you need to add is:

<script async src="https://storage.googleapis.com/tp_script/test.myshopify.com/config.js"></script>

1. Go to Online shops → Themes

2. Click on three dots → Edit code

3. Go to layout → theme.liquid

4. Add it in the header at the top:

5. Then click on Save at the top right

When you're done with this, you just need to do step 2:

Add customer events

1. Go to Shopify settings (bottom left)

2. Go to Customer events

3. Add custom pixel

​​

4. Add name Venon

​​

5. Set settings

Permission: Not required

Data sale: Data collected does not qualify as data sale

​​

6. Add this code:

Replace YOURSHOPIFYNAME with your Shopify name here. So for example: const shopName = "test"; Keep the quotes before and after ("...").

analytics.subscribe("all_standard_events", async (event) => {
const shopName = "YOURSHOPIFYNAME";

let sessionId = null;

// Set a cookie with the standard API
const sessionCookie = await browser.cookie.get("dv_sessionId");
if (!sessionCookie) {
sessionId = generateSessionId();
let userData = {
sessionId: sessionId,
shopName: shopName,
};
browser.cookie.set("dv_sessionId", JSON.stringify(userData));
} else {
let obj = JSON.parse(sessionCookie);
sessionId = obj.sessionId;
}

let sendEvent = {};

console.log(event.name);

switch (event.name) {
case "page_viewed":
const url = new URL(init.context.document.location.href);
const hasQueryParams = url.searchParams.toString() !== "";
const referrer = init.context.document.referrer;
const hasReferrer = referrer !== "";
const sameDomainReferrer =
hasReferrer && new URL(referrer).hostname === url.hostname;
const includesCheckouts =
init.context.document.location.href.includes("checkouts");
const includesOrders =
init.context.document.location.href.includes("/orders/");

if (
!hasQueryParams &&
(!hasReferrer || sameDomainReferrer) &&
!includesCheckouts &&
!includesOrders
) {
// console.log('Page view event not sent');
return;
} else {
// console.log('page event sent')
}
break;
case "checkout_completed":
sendEvent.orderId = event.data.checkout.order.id;
sendEvent.browser_ip = event.browser_ip;
break;
case "product_added_to_cart":
sendEvent.value = event.data?.cartLine?.cost?.totalAmount?.amount;
break;
case "checkout_started":
sendEvent.checkoutId = event.data.checkout.token;
sendEvent.value = event.data?.checkout?.totalPrice?.amount;
break;
case "checkouts/update":
break;
}

sendEvent.name = event.name;
sendEvent.sessionId = sessionId;
sendEvent.shopName = shopName;
sendEvent.title = document.title;
sendEvent.clientId = event.clientId;
sendEvent.timestamp = event.timestamp;
sendEvent.page = init.context.document.location.href;
sendEvent.referrer = init.context.document.referrer;
sendEvent.cartId = await browser.cookie.get("cart");

console.log(JSON.stringify(sendEvent));

// Send events to third-party servers
fetch(
"https://backend-563597392989.europe-west3.run.app/receiveShopifyWebPixelEvents",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(sendEvent),
keepalive: true,
}
);
});

function generateSessionId() {
const array = new Uint8Array(16);
window.crypto.getRandomValues(array);
return Array.from(array, (byte) => ("0" + byte.toString(16)).slice(-2)).join(
""
);
}

7. Click 'Connect'

Did this answer your question?