← back to Dw Signup Fulfillment
verification/tk10836/verify-shoppay-correlation.js
51 lines
#!/usr/bin/env node
// TK-10836 / TK-11366: does the Aug-18+ collapse in free-shipping selection correlate with
// Shop Pay / "Login with Shop" accelerated checkout? READ-ONLY.
const fs=require('fs'),os=require('os');
for (const line of fs.readFileSync(os.homedir()+'/Projects/secrets-manager/.env','utf8').split('\n')) {
const m=line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)$/); if(!m) continue;
let v=m[2].trim().replace(/^['"]|['"]$/g,''); if(!process.env[m[1]]) process.env[m[1]]=v;
}
const STORE=process.env.SHOPIFY_STORE_DOMAIN||'designer-laboratory-sandbox.myshopify.com';
const TOKEN=process.env.SHOPIFY_FULL_ACCESS_TOKEN, API='2024-10';
async function gql(q,v={}){const r=await fetch(`https://${STORE}/admin/api/${API}/graphql.json`,{method:'POST',
headers:{'X-Shopify-Access-Token':TOKEN,'Content-Type':'application/json'},body:JSON.stringify({query:q,variables:v})});
const j=await r.json(); if(j.errors)console.error('ERR',JSON.stringify(j.errors).slice(0,300)); return j.data;}
const Q=`query($c:String){ orders(first:40, after:$c, query:"created_at:>2026-06-01", sortKey:CREATED_AT){
pageInfo{hasNextPage endCursor}
nodes{ name createdAt totalShippingPriceSet{shopMoney{amount}} shippingLine{title}
shippingAddress{countryCodeV2}
customer{ tags }
lineItems(first:12){ nodes{ sku title discountedTotalSet{shopMoney{amount}} } } } } }`;
(async()=>{
let c=null, rows=[];
do{
const d=await gql(Q,{c}); if(!d) break;
for(const o of d.orders.nodes){
const lis=o.lineItems.nodes; if(!lis.length) continue;
if(!lis.every(li=>/(^|-)sample/i.test(li.sku||'')||/sample|memo|swatch/i.test(li.title||''))) continue;
if(o.shippingAddress?.countryCodeV2!=='US') continue;
const charged=lis.reduce((s,li)=>s+Number(li.discountedTotalSet?.shopMoney?.amount||0),0);
if(charged>0) continue; // comped only
if(lis.length>4) continue; // Kelly-shaped
const tags=(o.customer?.tags||[]);
rows.push({name:o.name,date:o.createdAt.slice(0,10),
free:Number(o.totalShippingPriceSet.shopMoney.amount)===0,
shop:tags.some(t=>/^(Login with Shop|Shop)$/i.test(t)), rate:o.shippingLine?.title||'(none)'});
}
c=d.orders.pageInfo.hasNextPage?d.orders.pageInfo.endCursor:null;
}while(c);
const tab=(rs)=>{const s=rs.filter(r=>r.shop),n=rs.filter(r=>!r.shop);
const p=a=>a.length?`${a.filter(x=>x.free).length}/${a.length} (${(100*a.filter(x=>x.free).length/a.length).toFixed(0)}% free)`:'n/a';
return ` Shop-Pay/Login-with-Shop: ${p(s)}\n NOT Shop tagged : ${p(n)}`;};
console.log('=== Comped, US, 1-4 sample lines, since 2026-06-01 ===');
console.log(`total n=${rows.length}\n`);
for(const [lab,lo,hi] of [['JUN 1 - AUG 17','2026-06-01','2026-08-17'],['AUG 18 - SEP 10','2026-08-18','2026-09-30']]){
const sub=rows.filter(r=>r.date>=lo&&r.date<=hi);
console.log(`--- ${lab} (n=${sub.length}, ${sub.filter(r=>r.free).length} free) ---`);
console.log(tab(sub));
console.log(` Shop-tagged share of cohort: ${sub.length?(100*sub.filter(r=>r.shop).length/sub.length).toFixed(0):0}%\n`);
}
fs.writeFileSync('verification/tk10836/shoppay-correlation.json',JSON.stringify({generated:new Date().toISOString(),rows},null,2));
})();