---
title: Stripe to Mixpanel Data Integration Guide
description: Learn how to integrate Stripe with Mixpanel using Google Cloud Functions or AWS Lambda for seamless event tracking.
image: https://optiblack.com/hubfs/Optiblack%20Vishal%20Rewari%20Product%20Analytics%20(12).png
---

OPTIBLACK

- [Services](https://optiblack.com/services)
- [Customers](https://optiblack.com/customers)

[Book a strategy call](https://optiblack.com/book-a-call)

- [Services](https://optiblack.com/services)
- [Customers](https://optiblack.com/customers)

[Book a strategy call](https://optiblack.com/book-a-call)

[Information](https://optiblack.com/insights/tag/information) [mixpanel](https://optiblack.com/insights/tag/mixpanel) Jul 12, 2025, 12:41:24 PM · 4 min read

# Stripe to Mixpanel Data Integration Guide

![Aswin Kumar](https://optiblack.com/hubfs/T03B5CKT6HZ-U07FHH1ESR0-561cebd6e111-512.jpeg)

Aswin Kumar

Optiblack

![move data from stripe to mixpanel](https://optiblack.com/hubfs/Optiblack%20Vishal%20Rewari%20Product%20Analytics%20(12).png)

## **Introduction**

This guide demonstrates how to stream events from Stripe webhooks to Mixpanel using a Google Cloud Function or an AWS Lambda function. The setup requires approximately 10-15 minutes and access to a GCP or AWS account with appropriate permissions.

### **Prerequisites**

- GCP account with Cloud Functions access or AWS account with Lambda access.
- Stripe account with webhook configuration capabilities.
- Mixpanel project token for importing data.

## **Approach 1: Using Google Cloud Platform (GCP)**

### **Step 1: Create a Cloud Function**

- Navigate to the GCP Console and create a new Cloud Function.
- Set the trigger type to **HTTPS**.
- Enable **Allow Unauthenticated Invocations** since Stripe will call this function.
- The function name (e.g., track-stripe) will appear in the URL (e.g., *https://us-central1-\<your-project\>.cloudfunctions.net/track-stripe*). Use the name chosen during creation.

### **Step 2: Deploy the Code**

Use the following Python code to handle Stripe webhook data and send it to Mixpanel

`import functions_framework`

`import json`

`import requests`

`import uuid  # Library to generate UUIDs`

`@functions_framework.http`

`def product(request):`

`    req = request.get_json(silent=True)`

`   `

`    # Ensure metadata exists and extract distinct_id`

`    metadata = req['data']['object'].get('metadata', {})  # Default to empty dict`

`    distinct_id = metadata.get('distinct_id', str(uuid.uuid4()))  # Fallback to UUID`

`   `

`    # Construct the properties dictionary`

`    properties = {`

`        '$insert_id': req['id'],`

`        '$device_id': distinct_id,  # Use distinct_id or fallback`

`        'time': req['created'],`

`        'utm_campaign': metadata.get('utm_campaign'),`

`        'utm_content': metadata.get('utm_content'),`

`        'utm_id': metadata.get('utm_id'),`

`        'utm_medium': metadata.get('utm_medium'),`

`        'utm_source': metadata.get('utm_source'),`

`        'utm_term': metadata.get('utm_term'),`

`        **req['data']['object']`

`    }`

`    properties = {k: v for k, v in properties.items() if v is not None}`

`    # Construct the event payload`

`    e = {`

`        'event': req['type'],`

`        'properties': properties`

`    }   `

`    # Send the request to Mixpanel`

`    resp = requests.post(`

`        "https://api.mixpanel.com/import",`

`        params={"strict": "1"},`

`        headers={`

`            "Content-Type": "application/x-ndjson",`

`            "User-Agent": "mixpanel-stripe"`

`        },`

`        auth=(request.args.get('token'), ""),`

`        data=json.dumps(e),`

`    )`

`    print("mixpanel resp", resp)   `

`    # Log the response and return it`

`    if resp.status_code != 200:`

`        print(f"Mixpanel error: {resp.status_code}, {resp.text}")`

`    else:`

`        print("Mixpanel event logged successfully")`

`   `

`    return resp.json()`

 

- Create a *requirements.txt* file with the following content:
  
  functions-framework==3.\*  
  requests

Deploy the function in the GCP Console with the code and requirements.txt.

### **Step 3: Configure Stripe Webhook**

- In the Stripe Dashboard, go to **Developers \> Webhooks**.
- Add a new webhook and paste the Cloud Function URL with the Mixpanel token (e.g., *https://us-central1-\<your-project\>.cloudfunctions.net/track-stripe?token=\<your\_token\>*).
- Select all events and save.

### **Step 4: Test the Integration**

- Open the Stripe Shell (bottom right corner of the Stripe Dashboard).
- Use the stripe trigger command to test an event (e.g., stripe trigger checkout.session.completed).
- Check the webhook status and response in the Stripe Webhooks section to confirm success.

## **Approach 2: Using Amazon Web Services (AWS)**

### **Step 1: Create a Lambda Function**

- Navigate to the AWS Management Console and create a new Lambda function.
- Choose **Python 3.11** as the runtime.
- Set up an **API Gateway** trigger with an HTTP endpoint.

### **Step 2: Deploy the Code**

Use the following Python code to handle Stripe webhook data and send it to Mixpanel.

Save this as lambda\_function.py.

`import` json

import requests

def lambda\_handler(event, context):

    # Parse the incoming event (Stripe webhook data)

    # event is the raw HTTP request body from Stripe

    req = json.loads(event\['body'\]) if isinstance(event.get('body'), str) else event

   

    # Extract the event type from the Stripe event

    event\_type = req.get('type', 'unknown\_event')

   

    # Get the customer ID or use a fallback distinct\_id (e.g., charge ID)

    customer\_id = req.get('data', {}).get('object', {}).get('customer')

    distinct\_id = customer\_id if customer\_id else req.get('data', {}).get('object', {}).get('id', 'default\_user\_' + req.get('id', 'unknown'))

   

    e = {

        'event': event\_type,

        'properties': {

            '$insert\_id': req.get('id', ''),

            'distinct\_id': distinct\_id,  # Use charge ID or default if customer is null

            '$device\_id': distinct\_id,   # Optional, for device tracking

            'time': req.get('created', ''),

            \*\*req.get('data', {}).get('object', {})

        }

    }

   

    resp = requests.post(

        "https://api.mixpanel.com/import",

        params={"strict": "1"},

        headers={

            "Content-Type": "application/x-ndjson",

            "User-Agent": "mixpanel-stripe"

        },

        auth=(event.get('queryStringParameters', {}).get('token'), ""),

        data=json.dumps(e),

    )

    return resp.json()

 

 

- Install dependencies locally using ***pip install requests -t*** . in the project folder containing *lambda\_function.py*.
- Zip the entire folder including *lambda\_function.py* and the installed requests package, then upload the ZIP to Lambda.

### **Step 3: Configure API Gateway**

- After deployment, copy the function URL from the AWS Lambda console (e.g., it will be in the format *https://\<random-string\>.lambda-url.\<region\>.on.aws* ).
- Note: The URL is unique to the deployed function; copy the specific URL provided after deployment.

### **Step 4: Configure Stripe Webhook**

- In the Stripe Dashboard, add a new webhook.
- Use the copied API Gateway URL (*https://\<random-string\>.lambda-url.\<region\>.on.aws/?token=\<your\_token\>*) with the Mixpanel token.
- Select all events and save.

### **Step 5: Test the Integration**

- Open the Stripe Shell and use stripe trigger checkout.session.completed.
- Verify the webhook status and response in the Stripe Webhooks section.

## **Viewing Data in Mixpanel Dashboard**

- Log in to the Mixpanel dashboard.
- Go to events.
- Filter by event type or distinct\_id to confirm Stripe data.

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXdfqvAZhp_zE855uYVTDlCMajrGLslX32lyLpVpLJvz6yEtNxomaZwfkWuri36QFmXpBFOyhT6zNiA6rbAQPLgmQ9lvOYp22N110bDfeI2Rm3ViQY9Gy-__V2p8m6E4CmAxP_Kluw?key=RC8aCnb6oT2m0f0aTqYlgw)

![](https://lh7-rt.googleusercontent.com/docsz/AD_4nXciIL_ZvOz5vxqJ5gx3gqn8E86d64qyeWEasPGKoJgrBm0fVcKQrzdAqdRP2Vo9GlKTnip72L4ajhIQXBPVC3bHKDwPVPKm67Z0VzYtrCVh_GFS0b5Z-EDcaSk7zFVXaMTpp45MEQ?key=RC8aCnb6oT2m0f0aTqYlgw)

## **Troubleshooting**

- Ensure the Mixpanel token matches in the webhook URL.
- Check logs in CloudWatch for Lambda or GCP Cloud Functions for errors.
- Confirm network access and API limits.

## **Conclusion**

A working Stripe to Mixpanel integration is now set up using GCP or AWS. Adjust the code for additional transformations as needed.

![Aswin Kumar](https://optiblack.com/hubfs/T03B5CKT6HZ-U07FHH1ESR0-561cebd6e111-512.jpeg)

Aswin Kumar

Tech @ Optiblack

[#Information](https://optiblack.com/insights/tag/information) [#mixpanel](https://optiblack.com/insights/tag/mixpanel)

/ Keep reading

## More from Optiblack

[![From Zero to a Multi-Region Analytics Backbone: How OptiBlack Built Scrut's Entire Data Platform](https://optiblack.com/hubfs/Optiblack%20Vishal%20Rewari%20Product%20Analytics%20(12)-3.png) Case Studies From Zero to a Multi-Region Analytics Backbone: How OptiBlack Built Scrut's Entire Data Platform](https://optiblack.com/insights/from-zero-to-a-multi-region-analytics-backbone-how-optiblack-built-scruts-entire-data-platform) [![AI in Geographic Segmentation: Key Use Cases](https://optiblack.com/hubfs/Optiblack%20Vishal%20Rewari%20Product%20Analytics%20(11)-4.png) Information AI in Geographic Segmentation: Key Use Cases](https://optiblack.com/insights/ai-geographic-segmentation-key-use-cases) [![RealBooks Selects Optiblack as Strategic Analytics Partner to Build Modern Data Stack for Real Estate Investors](https://optiblack.com/hubfs/Optiblack%20Vishal%20Rewari%20Product%20Analytics%20(11)-3.png) News RealBooks Selects Optiblack as Strategic Analytics Partner to Build Modern Data Stack for Real Estate Investors](https://optiblack.com/insights/realbooks-selects-optiblack-as-strategic-analytics-partner-to-build-modern-data-stack-for-real-estate-investors)

/ 15-minute exploration call

## Turn these insights into revenue.

We'll go through your CRM, product, and analytics data together and show you exactly where growth is leaking. No setup. No dashboards. Just signal.

[Book a strategy call →](https://optiblack.com/book-a-call)

[OPTIBLACK](https://optiblack.com/)

 US: 1309 Coffeen Ave, Suite 1200, Sheridan, WY 82801 · +1 682 297 2970 — India: 297 Designs, 74 SBK Society, Paldi, Ahmedabad 380007 · +91 9819394297

 Services

[Data services](https://optiblack.com/services) [CRM services](https://optiblack.com/services) [AI services](https://optiblack.com/services) [Book a call](https://optiblack.com/services)

 Company

[Customers](https://optiblack.com/customers) [About Us](https://optiblack.com/about-us) [Insights](https://optiblack.com/insights)

 © 2026 Optiblack · 2× Mixpanel Partner of the Year · vishal@optiblack.com

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Aswin Kumar",
    "url" : "https://optiblack.com/insights/author/aswin-kumar"
  },
  "dateModified" : "2025-10-20T11:16:27.797Z",
  "datePublished" : "2025-07-12T07:11:24.000Z",
  "headline" : "Stripe to Mixpanel Data Integration Guide",
  "image" : [ "https://optiblack.com/hubfs/Optiblack%20Vishal%20Rewari%20Product%20Analytics%20(12).png" ],
  "mainEntityOfPage" : {
    "@id" : "https://optiblack.com/insights/stripe-to-mixpanel-data-integration-guide",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://optiblack.com/hubfs/Group%201234.png"
    },
    "name" : "Optiblack"
  }
}
```