You can create a goal that would fire only when a product with a certain SKU is purchased.
For this, you would need to install the following JavaScript code in the same way that the manual revenue tracking is installed on Shopify. You could append the code along the manual revenue tracking code, making a goal for general revenue tracking and one for a specific SKU.
You would only need to change the id, to the revenue goal that you create for this on the Convert app.
<script>
total_sku_revenue = 0;
total_sku_products = 0;
function reportRevenue(revenue,product_count) {
_conv_q = window._conv_q || [];
// Replace the number for your Revenue Goal Id
_conv_q.push(["pushRevenue", revenue, product_count, "100134184"]);
console.log('SKU Specific Report:revenue='+revenue+': Product Count='+product_count);
}
Shopify.checkout.line_items.forEach(product => {
if (product.sku.includes('rose')){
total_sku_revenue = product.line_price + total_sku_revenue;
total_sku_products = 1 + total_sku_products;
}
})
if (total_sku_products > 0) {
reportRevenue(total_sku_revenue,total_sku_products)
}total_sku_revenue = 0;
total_sku_products = 0;
function reportRevenue(revenue,product_count) {
_conv_q = window._conv_q || [];
// Replace the number for your Revenue Goal Id
_conv_q.push(["pushRevenue", revenue, product_count, "100134184"]);
console.log('SKU Specific Report:revenue='+revenue+': Product Count='+product_count);
}
Shopify.checkout.line_items.forEach(product => {
if (product.sku.includes('rose')){
total_sku_revenue = product.line_price + total_sku_revenue;
total_sku_products = 1 + total_sku_products;
}
})
if (total_sku_products > 0) {
reportRevenue(total_sku_revenue,total_sku_products)
}
</script>
To separate subscriptions from non-subscriptions you can use the following code:
<script>
document.addEventListener("DOMContentLoaded", function() {
convertRevenueCurrency = false;
currencyToConvertTo = 'USD';
function reportRevenue(revenue, product_count, goal_id, purchase_type, Currency) {
_conv_q = window._conv_q || [];
// Enable next line if currency conversion is needed.
if (convertRevenueCurrency) {
revenue = Currency.convert(revenue, Shopify.checkout.currency, currencyToConvertTo);
}
_conv_q.push(["pushRevenue", revenue, product_count, goal_id]);
console.log(purchase_type + ' Report:revenue=' + revenue + ': Product Count=' + product_count);
}
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://cdn.shopify.com/s/javascripts/currencies.js');
xhr.onload = function() {
console.log('xhr status' + xhr.status);
if (xhr.status === 200) {
eval(xhr.responseText);
total_subs_revenue = 0;
total_subs_products = 0;
total_non_subs_revenue = 0;
total_non_subs_products = 0;
Shopify.checkout.line_items.forEach(product => {
// Following line checks if it is a subscribed product by query a specific property of the product
if (product.selling_plan_allocation.selling_plan.recurring_deliveries)
total_subs_revenue = product.line_price - product.line_level_total_discount + total_subs_revenue;
total_subs_products = 1 + total_subs_products;
} else {
total_non_subs_revenue = product.line_price - product.line_level_total_discount + total_non_subs_revenue;
total_non_subs_products = 1 + total_non_subs_products;
}
})
if (total_subs_products > 0) {
// Change goal id to the one created for subscriptions
reportRevenue(total_subs_revenue, total_subs_products, '10044705', 'subscriptions', Currency);
}
if (total_non_subs_products > 0) {
// Change goal id to the one created for non subscriptions
reportRevenue(total_non_subs_revenue, total_non_subs_products, '10044706', 'non subscription', Currency);
}
}
};
xhr.send();
});
</script>
Comments