Skip to content

Instantly share code, notes, and snippets.

View ceaksan's full-sized avatar
🤹

Ceyhun Aksan ceaksan

🤹
View GitHub Profile
@ceaksan
ceaksan / shopify-quantity-limit.md
Last active January 3, 2025 10:14
This code prevents unrealistic quantity values (e.g., thousands or millions) in GA4 reports by dynamically setting min and max limits for product quantity fields. Using Liquid, it assigns values from quantity_rule or defaults to 1 and 10, ensuring valid inputs and maintainable logic.

If you notice unusually large quantity values (e.g., thousands or millions) in item details within your GA4 reports, it might be caused by the lack of a maximum quantity limit. Visitors can manipulate this to trigger exaggerated “Add to Cart” events, distorting your analytics data. To prevent such issues, you can set minimum and maximum quantity limits in your input fields.

This implementation ensures valid input values for product quantity fields in an e-commerce environment by dynamically assigning min and max values using Liquid. The limits are derived from the product’s quantity_rule or default to 1 and 10, respectively, if no rules are defined. By using Liquid’s assign, the logic remains clean, reusable, and maintainable.

Below is an example implementation:

{% assign min_quantity = product.selected_or_first_available_variant.quantity_rule.min | default: 1 %}
{% assign max_quantity = product.selected_or_first_available_variant.quantity_rule.max | default: 10 %}

ShopifyQL Query Gist

This Gist contains a collection of ShopifyQL queries designed for in-depth analysis of sales, customer behavior, and channel performance metrics. Each query focuses on a specific aspect of e-commerce analytics, offering insights into trends and operational efficiency.

1. Daily Orders by Sales Channel (Online Store)

Description: Analyzes daily orders for the Online Store sales channel, including totals and averages for the past 7 days.

FROM sales
SHOW orders, average_order_value, shipping_charges, taxes, total_sales
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('View more cell actions')
.addItem('Convert table to Markdown', 'convertTableToMarkdown')
.addToUi();
}
function convertTableToMarkdown() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const range = sheet.getDataRange();
gtag("event", "view_item_list", {
event_action: "Product Impressions",
event_category: "Enhanced Ecommerce - Stores",
items: [{
id: "85b88ed8-d2bf-491c-bbd5-9ea60c2dc2b4",
name: "Bu bir ürün",
list_name: "Slider Gallery",
category: "All Products",
list_position: 0,
price: 80.75
dataLayer.push({
event: "productImpression",
origin: "Stores",
event_category: "Enhanced Ecommerce - Stores",
ecommerce: {
impressions: [
{
id: "85b88ed8-d2bf-491c-bbd5-9ea60c2dc2b4",
name: "Bu bir ürün",
list: "Slider Gallery",
dataLayer.push({
event: "select_content",
eventModel: {
event_action: "Product Click",
event_category: "Enhanced Ecommerce - Stores",
event_label: "Bu bir ürün",
content_type: "product",
items: [
{
id: "1917d53b-2528-476d-8f9c-45424a839971",
(function () {
var urlParams = new URLSearchParams(window.location.search);
var paramsToAppend = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'ref', '_gl'];
var formButton = document.querySelector('.button_class');
if (formButton) {
var dataUrl = formButton.getAttribute('data-url');
if (dataUrl) {
var url = new URL(dataUrl);
<script src="https://quick.vidalytics.com/js/conversion.min.js"></script><script>
(function (v, i, d, a, l, y, t, c, s) {
s=function(){t=i.createElement('div');t.setAttribute('style','display:none;');t.setAttribute('class',d);i.body.appendChild(t);
y=new v[a]['ConversionTracking']({url:'https://stats.vidalytics.com'},t);y.track('<account-id>',{conversionId: '<conversion-id>'});};
if(v.addEventListener){v.addEventListener('load',s,false);}else if(v.attachEvent){v.attachEvent('onload',s);}
}) (window, document, 'vidalytics-tracker', 'VidalyticsC');
</script>
<div id="vidalytics_embed_<unique-id>" style="width: 100%; position:relative; padding-top: 56.25%;"></div>
<script type="text/javascript">
(function (v, i, d, a, l, y, t, c, s) {
y='_'+d.toLowerCase();c=d+'L';if(!v[d]){v[d]={};}if(!v[c]){v[c]={};}if(!v[y]){v[y]={};}var vl='Loader',vli=v[y][vl],vsl=v[c][vl + 'Script'],vlf=v[c][vl + 'Loaded'],ve='Embed';
if (!vsl){vsl=function(u,cb){
if(t){cb();return;}s=i.createElement("script");s.type="text/javascript";s.async=1;s.src=u;
if(s.readyState){s.onreadystatechange=function(){if(s.readyState==="loaded"||s.readyState=="complete"){s.onreadystatechange=null;vlf=1;cb();}};}else{s.onload=function(){vlf=1;cb();};}
i.getElementsByTagName("head")[0].appendChild(s);
};}
vsl(l+'loader.min.js',function(){if(!vli){var vlc=v[c][vl];vli=new vlc();}vli.loadScript(l+'player.min.js',function(){var vec=v[d][ve];t=new vec();t.run(a);});});
var _vidalyticsPlayerPlugin = {
"vidalytics_embed_<unique-id>": {
"google-analytics": {
"id": "UA-XXXXXXXXXX-X", // Google Analytics ID
"videoTitle": "Video XYZ", // Video Başlığı
"sendWatchedPercent": "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100", // Takip edilmek istenen video izlenme oranı (%)
"sendPlay": true, // Oynatma olayı
"sendPause": true, // Durdurma olayı
"sendPausePercentage": true // Videonun durdurulduğu oran (%)
}