1. Add ProductLense to Shopify

The script goes in layout/theme.liquid. Replace SITE_ID with the id from Settings → Sites.

layout/theme.liquid
  <script>window.productlense=window.productlense||function(){(window.productlense.q=window.productlense.q||[]).push(arguments)}</script>
  <script defer data-site="SITE_ID" src="https://api.productlense.app/a.js"></script>
</head>

2. Identify signed-in users

layout/theme.liquid
{% if customer %}
  <script>
    window.productlense('identify', '{{ customer.id }}', { email: {{ customer.email | json }} });
  </script>
{% endif %}

3. Connect Stripe

Setup steps

  1. In Stripe, open Developers → API keys and create a restricted key with Read on Customers, Subscriptions, Charges, Refunds and Balance transactions.
  2. In ProductLense, open Settings → Billing connections → Stripe and paste the key. ProductLense makes one read call to check it.
  3. In Stripe → Developers → Webhooks, add a webhook endpoint with the URL ProductLense shows after you save the connection (pattern https://api.productlense.app/api/webhooks/{provider}/{connection_id}).
  4. Select the events listed below, save, and paste the signing secret into ProductLense.
  5. ProductLense backfills the last 12 months, then keeps up through webhooks and a nightly reconcile.

Credentials and permissions

Credentials ProductLense asks for
FieldSecretWhere to find it
Secret keyYes, encrypted at restA restricted key (rk_live_...) with read access to customers, subscriptions, charges, refunds and balance transactions. A full secret key also works; a restricted key is safer.
Webhook signing secretYes, encrypted at restThe whsec_... secret of the webhook endpoint you point at ProductLense.

Webhook

URL pattern, shown with your connection id after you save:

text
https://api.productlense.app/api/webhooks/stripe/{connection_id}

Events: charge.succeeded, charge.refunded, charge.dispute.created, customer.created, customer.updated, customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, invoice.paid

Verification: Stripe-Signature header: timestamp plus HMAC-SHA256, rejected after 5 minutes.

What ProductLense reads

Customers
Customers, including email and metadata such as pl_user_id.
Subscriptions
Subscriptions with plan, interval and status.
Payments
Charges and paid invoices.
Refunds
Refunds, plus disputes recorded as chargebacks.
Fees
The fee on each balance transaction, and the dispute fee on chargebacks.

What ProductLense never touches

  • Never creates, changes, refunds or cancels anything: read-only API calls and incoming webhooks only.
  • Never moves money, issues payouts, or reads bank account details.
  • Never sees full card numbers; providers do not expose them.
  • Never sends your customer data to the AI model: Ask and the daily insight see aggregates only.

Match payments to your users

Set metadata.pl_user_id on Stripe customers to the same id you pass to identify for the strongest match. Without it, ProductLense matches by customer email.

server: create the Stripe customer
const customer = await stripe.customers.create({
  email: user.email,
  metadata: { pl_user_id: user.id },
});

Stripe on Shopify: questions

Where does the ProductLense script go in Shopify?
In layout/theme.liquid. In Shopify admin, open Online Store → Themes → … → Edit code → layout/theme.liquid. The script is about 2.3 KB, loads with defer, sets no cookies, and records route changes in single-page apps through the history API, so no extra router code is needed.
How do I identify users in Shopify?
Call window.productlense('identify', userId) once the signed-in user is known, as in the layout/theme.liquid example on this page. Use the same id you store on Stripe as pl_user_id, so Stripe payments match by id rather than by email.
Does ProductLense work with Stripe?
Yes. ProductLense connects to Stripe with secret key, webhook signing secret, backfills 12 months of history, and stays current through signed webhooks plus a nightly reconcile. One connection is included on Starter; Growth and Scale allow every provider at once on the same site.
What data does ProductLense read from Stripe?
Customers, subscriptions, payments, refunds and fees, read-only. Payments: charges and paid invoices. Refunds: refunds, plus disputes recorded as chargebacks. Fees: the fee on each balance transaction, and the dispute fee on chargebacks.
Can ProductLense change anything in my Stripe account?
No. ProductLense only makes read calls and receives webhooks. It never creates, changes, refunds or cancels anything, never moves money, and never sees card numbers. Credentials are encrypted at rest, and the AI features only ever see aggregated numbers, never your customers’ data.

Free up to 10k events a month. No card.

Add the script, connect Stripe or any of 14 other billing providers, and see revenue by channel the same day.