Subscription Revenue Optimization Engine - n8n Workflow

Automate customer retention, upselling, and re-engagement using a powerful n8n workflow connected to Postgres, Stripe, and Gmail. Leverage predictive analytics for MRR growth.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

SaaS Founders & Product Managers: Seeking to reduce churn and maximize Customer Lifetime Value (CLV).
Revenue Operations (RevOps) Specialists: Needing a scalable, custom solution for predictive segmentation.
Data Engineers: Looking for robust n8n templates that integrate database logic (Postgres) with transactional platforms (Stripe, Gmail).
Automation Experts: Who want to implement sophisticated custom logic using the n8n code node within a centralized n8n workflow.

Overview

Maintaining and growing subscription revenue requires proactive intervention, but manually segmenting customers based on dozens of health indicators is time-consuming. This sophisticated n8n workflow solves this by automating the entire revenue intelligence cycle.

The workflow uses a predictive model defined within an n8n node to analyze key metrics (usage, engagement, support tickets, payment history) stored in a Postgres database. Based on customizable thresholds set in a dedicated n8n node, it automatically determines if a customer is high-risk, a strong upsell opportunity, or needs re-engagement. This powerful n8n automation then uses Stripe to retrieve contact details and launches highly personalized campaigns via Gmail. This end-to-end n8n template ensures timely outreach, maximizing retention and revenue uplift without requiring daily manual oversight.

How it Works

This automation is initiated by the Schedule n8n trigger, Daily Revenue Analysis, running every morning at 6:00 AM.


  1. Configuration Loading: The workflow starts by defining core parameters (churn risk threshold, upsell threshold, retention discount) in the Revenue Settings n8n node.

  2. Data Retrieval: The Get Customer Analytics n8n node queries the Postgres database to retrieve active customer health scores and MRR data.

  3. Predictive Analysis: The central Analyze Revenue Opportunities n8n node executes custom JavaScript logic. It calculates weighted churn risk and upsell potential scores for each customer and assigns a recommendedaction based on the predefined thresholds (e.g., 'retentioncampaign', 'upsellcampaign', 'engagementcampaign').

  4. Segmentation: The output is immediately routed to three parallel If n8n nodes (Filter High Risk Customers, Filter Upsell Opportunities, Filter Re-engagement Needed), segmenting the customers based on the action required.

  5. Contact Enrichment: For each segment, an HTTP Request n8n node queries the Stripe API using the customer_id to fetch current, accurate contact information (like email address).

  6. Campaign Execution: Finally, a dedicated Gmail n8n node sends a customized, HTML email appropriate for the action: a discount offer for high-risk customers, a benefit-driven upgrade pitch for upsell targets, or a success-call offer for low-engagement accounts. This ensures that the entire n8n workflow delivers a relevant message at the precise moment it is most effective.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n Template: Copy the provided JSON and import it into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. Set up Credentials: This n8n workflow requires three distinct credentials:

Postgres: Set up credentials for the Get Customer Analytics n8n node. Ensure the credentials allow read access to your customeranalytics table.
Stripe: Set up Stripe API credentials for the three HTTP Request n8n nodes to fetch customer details. This typically requires a secret key.
* Gmail: Configure Gmail credentials for the three Gmail n8n nodes, granting the workflow permission to send emails on your behalf.

  1. Database Schema: Ensure your Postgres database contains a table named customeranalytics with columns referenced in the query (e.g., customerid, usagescore, mrr, support_tickets).

  2. Customize Logic: Review the Revenue Settings n8n node to adjust thresholds (e.g., churnRiskThreshold) and the Analyze Revenue Opportunities code n8n node if you need to modify the weighting of the predictive model factors.

Node Details

Daily Revenue Analysis (Schedule Trigger n8n trigger):
Function: Starts the n8n workflow daily to ensure timely analysis.
Key Configuration: Runs on a fixed CRON schedule: 0 6 (6:00 AM daily).
Revenue Settings (Set n8n node):
Function: Centralizes core business variables, making the n8n workflow easily adjustable without touching code.
Key Configuration: Defines churnRiskThreshold (0.7), upsellThreshold (0.8), and retentionDiscount (25).
Get Customer Analytics (Postgres n8n node):
Function: Fetches raw data inputs required for the predictive model.
Key Configuration: Executes a SELECT query to retrieve key customer metrics from the customeranalytics table.
Analyze Revenue Opportunities (Code n8n node):
Function: Executes the complex business logic to calculate risk/potential scores and determines the recommended
action for each customer item.
Key Configuration: Contains custom JavaScript for weighted scoring and conditional assignment based on settings provided by the previous n8n node.
Filter Nodes (If n8n node):
Function: Splits the single data stream into three parallel paths based on the calculated recommendedaction ('retentioncampaign', 'upsellcampaign', 'engagementcampaign').
Get Customer Details (HTTP Request n8n node):
Function: Uses the customer_id output by the Code n8n node to look up the corresponding customer details (like email) via the Stripe API, essential for personalization.
Send Campaign Nodes (Gmail n8n node):
* Function: Dispatches personalized HTML emails for retention, upselling, or re-engagement, integrating dynamic data like customer name, usage scores, and the retention discount percentage defined earlier in the n8n workflow.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by
Rodrigue
Rodrigue

Featured*