feat: integrate Rybbit analytics alongside OpenPanel
Some checks failed
Build and Deploy / build (push) Has been cancelled

- Add RybbitService for tracking e-commerce events
- Update useAnalytics hook to track with both OpenPanel and Rybbit
- Add Rybbit script to layout for page view tracking
- Track all applicable store events: product views, cart, checkout, orders, search, etc.
This commit is contained in:
Unchained
2026-03-31 00:38:38 +02:00
parent 044aefae94
commit b3efebd3e4
11 changed files with 1422 additions and 118 deletions

137
scripts/test-frontend.mjs Normal file
View File

@@ -0,0 +1,137 @@
const SALEOR_API_URL = 'https://api.manoonoils.com/graphql/';
async function saleorFetch(query, variables = {}) {
const response = await fetch(SALEOR_API_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query, variables }),
});
const result = await response.json();
if (result.errors) {
console.error('GraphQL Errors:', JSON.stringify(result.errors, null, 2));
throw new Error(JSON.stringify(result.errors));
}
return result.data;
}
async function test() {
// Create checkout
const createResult = await saleorFetch(`
mutation {
checkoutCreate(input: {
channel: "default-channel"
email: "test@test.com"
lines: [{ variantId: "UHJvZHVjdFZhcmlhbnQ6Mjk0", quantity: 1 }]
languageCode: SR
}) {
checkout {
id
token
totalPrice { gross { amount } }
subtotalPrice { gross { amount } }
}
errors {
field
message
code
}
}
}
`);
if (createResult.checkoutCreate.errors?.length > 0) {
console.error('Checkout creation errors:', createResult.checkoutCreate.errors);
throw new Error('Checkout creation failed');
}
if (!createResult.checkoutCreate.checkout) {
console.error('Create result:', createResult);
throw new Error('Checkout creation returned null');
}
const checkout = createResult.checkoutCreate.checkout;
const token = checkout.token;
console.log('Created checkout:');
console.log(' ID:', checkout.id);
console.log(' Token:', token);
console.log(' Initial Total:', checkout.totalPrice.gross.amount);
// Set address
await saleorFetch(`
mutation {
checkoutShippingAddressUpdate(
checkoutId: "${checkout.id}"
shippingAddress: {
firstName: "Test"
lastName: "User"
streetAddress1: "123 Street"
city: "Belgrade"
postalCode: "11000"
country: "RS"
phone: "+38160123456"
}
) {
checkout {
shippingMethods { id name price { amount } }
}
}
}
`);
// Query by token (what refreshCheckout does)
const tokenQuery = await saleorFetch(`
query {
checkout(token: "${token}") {
id
token
totalPrice { gross { amount } }
subtotalPrice { gross { amount } }
shippingPrice { gross { amount } }
shippingMethods { id name price { amount } }
}
}
`);
console.log('\nQuery by token (before shipping method):');
console.log(' Total:', tokenQuery.checkout.totalPrice.gross.amount);
console.log(' Subtotal:', tokenQuery.checkout.subtotalPrice.gross.amount);
console.log(' Shipping:', tokenQuery.checkout.shippingPrice.gross.amount);
console.log(' Methods:', tokenQuery.checkout.shippingMethods.length);
if (tokenQuery.checkout.shippingMethods.length > 0) {
const methodId = tokenQuery.checkout.shippingMethods[0].id;
// Set shipping method
await saleorFetch(`
mutation {
checkoutShippingMethodUpdate(
checkoutId: "${checkout.id}"
shippingMethodId: "${methodId}"
) {
checkout {
totalPrice { gross { amount } }
subtotalPrice { gross { amount } }
shippingPrice { gross { amount } }
}
}
}
`);
// Query by token again (what should happen after refreshCheckout)
const afterMethod = await saleorFetch(`
query {
checkout(token: "${token}") {
totalPrice { gross { amount } }
subtotalPrice { gross { amount } }
shippingPrice { gross { amount } }
}
}
`);
console.log('\nQuery by token (AFTER shipping method):');
console.log(' Total:', afterMethod.checkout.totalPrice.gross.amount);
console.log(' Subtotal:', afterMethod.checkout.subtotalPrice.gross.amount);
console.log(' Shipping:', afterMethod.checkout.shippingPrice.gross.amount);
}
}
test().catch(console.error);