How it works

Follow these 6 simple steps to start receiving automatic alerts when coupon code abuse is detected

database icon

Record Created

This trigger regularly monitors your order database to detect new records, providing the foundation for hourly discount analysis without requiring constant manual data checks.
This trigger checks your "Shopify Orders" MESA Data table every hour for new records using the schedule. When new order data is detected, the workflow activates and begins the discount analysis process. Critical requirement: You must have a MESA Data table named "Shopify Orders" that contains order information including "Created At", "Total Price", and "Total Discount" columns. This table is typically populated by another workflow that syncs Shopify orders to MESA Data storage.
Time to complete: Auto-configured (0 minutes)

Custom SQL Query

Aggregates your order and discount data by day to calculate discount percentages, transforming raw order records into actionable metrics that reveal usage patterns and potential abuse.
This step runs a SQL query against your "Shopify Orders" table that groups orders by day and calculates the total sales, total discounts, and discount percentage for each day. The query uses TO_CHAR("Created At", 'yyyy-mm-dd') to group by date, SUM("Total Price") for daily sales totals, SUM("Total Discount") for daily discount amounts, and ROUND(SUM("Total Discount") / SUM("Total Price"), 2) to calculate the discount percentage. The results are returned as {{data_1}} and ordered chronologically by date, providing a time-series view of discount activity.
Time to complete: 1 minute

Format order total by day including discounts

Transforms the SQL query results into a clean JSON format that AI can easily analyze, ensuring accurate interpretation of discount patterns without data formatting errors.
This custom JavaScript step processes the raw SQL query results from {{data_1}} and formats them into a structured JSON object stored as {{custom.json_results}}. The script organizes the daily order totals, discount amounts, and percentages into a format optimized for AI analysis. This formatting step ensures the data is properly structured before being sent to the AI prompt, preventing parsing errors and improving analysis accuracy. Custom code: const Mesa = require('vendor/Mesa.js'); /** * A MESA Script exports a class with a script() method. */ module.exports = new (class { /** * MESA Script * * @param {object} prevResponse The response from the previous step * @param {object} context Additional context about this task */ script = (prevResponse, context) => { // Retrieve the Variables Available to this step const vars = context.steps; let newPayload = {}; newPayload.json_results = JSON.stringify(prevResponse); // Call the next step in this workflow // response will be the Variables Available from this step Mesa.output.next(newPayload); }; })();
Time to complete: 1 minute

Compare discount rates to identify coupon abuse

Uses AI to intelligently detect abnormal discount patterns by comparing current rates against your baseline average, providing smart analysis that adapts to your specific business patterns rather than rigid thresholds.
This step sends the formatted discount data from {{custom.json_results}} to AI with a prompt asking it to compare the discount rate against the usual 10% average and determine if abuse is occurring. The AI analyzes the daily discount percentages to identify unusual spikes or sustained high discount rates that indicate potential coupon code exploitation. The AI responds with a simple "Yes" or "No" stored as {{ai.response}}, making it easy to trigger alerts. Customization option: You can modify the prompt to change the baseline percentage (currently 10%) to match your typical discount rate, or add specific rules for what constitutes abuse in your business.
Time to complete: 3 minutes

Was coupon abuse detected?

Acts as a gatekeeper that only allows the workflow to continue and send alerts when AI has confirmed suspicious activity, preventing alert fatigue from false positives or normal discount activity.
This filter step checks if {{ai.response}} equals "Yes", meaning the AI detected abnormal discount rates. If the condition is true, the workflow proceeds to send a Slack alert. If the AI response is "No" (normal discount activity), the workflow stops here without sending any notification. This ensures you only receive alerts when there's actually something worth investigating.
Time to complete: 1 minute
slack logo icon

Send Slack Message

Delivers immediate notification to your team when coupon abuse is detected, enabling quick investigation and response to protect revenue before the situation escalates.
This step sends a Slack message to your specified channel when the filter determines abuse has been detected. You need to configure two fields: the channel where the alert should be sent (you must invite the MESA Slack app to your channel first by typing @MESA and clicking Invite), and the message content (default is "Coupon code abuse detected" but you can customize it to include more context). Best practice: Include actionable information in your message like instructions to review the discount report or check recent high-discount orders.
Time to complete: 1 minute

Make it your own

Customize this workflow even further:

Include detailed discount data in the alert
Modify the Slack message to include specific numbers from {{custom.json_results}}, showing which days had high discount rates and the exact percentages to provide immediate context for investigation.
Adjust the baseline discount threshold
Change the 10% baseline in the AI prompt to match your actual average discount rate, or create different thresholds for different time periods (like higher baselines during known sale events).
Add email alerts for critical spikes
Connect an email step alongside or after the Slack message to notify leadership or finance teams when discount rates exceed severely abnormal levels, ensuring critical issues reach the right people.
Store abuse incidents in Google Sheets
Add a Google Sheets step after the filter to log every detected abuse instance with timestamp, discount percentage, and AI analysis, creating a historical record for pattern analysis and reporting.

Frequently asked questions

How do I set up the "Shopify Orders" data table that this workflow requires?
The easiest way is to add the template "Store Shopify Orders in a Database". This will setup the table exactly as needed. If you want to build it from scratch, you'll need to create a separate workflow that syncs Shopify orders to a MESA Data table. Use a "Shopify Order Created" or "Order Updated" trigger and a "Data Record Create or Update" action to populate the table with fields for Created At, Total Price, and Total Discount. This provides the foundation data that the abuse detection workflow analyzes.
Can I change the 10% baseline discount rate to match my business?
Yes, edit the AI prompt in the "Compare discount rates to identify coupon abuse" step and replace "assume 10% if unspecified" with your actual typical discount rate. For example, if your average is 15%, change it to "assume 15% if unspecified" to reduce false positives.
What if I want to check more or less frequently than every hour?
Edit the trigger's poll schedule field. Adjust based on your order volume and how quickly you need to detect abuse. You may need to upgrade in order see faster frequency options.
What is a template?
Templates are pre-made workflows by our team of experts. Instead of building a workflow from scratch, these have all the steps needed to complete the task.
Can I personalize a template?
Yes! Every step can be customized to meet your exact requirements. Additionally, you can even add more steps and make it more sophisticated.
Are templates free?
Yes! Our entire library containing hundreds of templates are free to use and customize to your exact needs.

Ready to start receiving automatic alerts when coupon code abuse is detected?

Join thousands who've automated their work and saved an average of 3.5 hours every week.

Use this template — It's free
7-day free trial • 8 min setup • Cancel anytime