Integrating Stripe S2S (Server-to-Server) events with Amplitude allows you to track user purchases and other significant events that happen with purchases (renewals, cancels, refunds, etc). This guide will walk you through the necessary steps to connect Amplitude with Stripe and configure the webhooks needed.
There are 3 main steps
Step 1: Connect Amplitude Script
Open Project in Onboarding Online Service and click on the Project Overview tab.
Add Amplitude Analytics
Find the Web Analytics menu option.
Click on +Add Analytics.
Select Amplitude from the 'Add new web analytic' screen.
3. Get Your Amplitude API Key
Log in to your Amplitude account.
Go to Settings β Organization Settings.
On the left tab, click on Projects and select your project.
Click on Show in the API Key section and copy it.
4. Insert Amplitude API Key into Script
Replace
'YOUR_API_KEY_HERE'
in the script with your Amplitude API key.
<script type="text/javascript">
!function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:{}};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{var r=function(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}},s=function(e,t,n){return function(r){e._q.push({name:t,args:Array.prototype.slice.call(n,0),resolve:r})}},o=function(e,t,n){e[t]=function(){if(n)return{promise:new Promise(s(e,t,Array.prototype.slice.call(arguments)))}}},i=function(e){for(var t=0;t<m.length;t++)o(e,m[t],!1);for(var n=0;n<g.length;n++)o(e,g[n],!0)};n.invoked=!0;var u=t.createElement("script");u.type="text/javascript",u.integrity="sha384-x0ik2D45ZDEEEpYpEuDpmj05fY91P7EOZkgdKmq4dKL/ZAVcufJ+nULFtGn0HIZE",u.crossOrigin="anonymous",u.async=!0,u.src="https://cdn.amplitude.com/libs/analytics-browser-2.0.0-min.js.gz",u.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var a=t.getElementsByTagName("script")[0];a.parentNode.insertBefore(u,a);for(var c=function(){return this._q=[],this},p=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],l=0;l<p.length;l++)r(c,p[l]);n.Identify=c;for(var d=function(){return this._q=[],this},f=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],v=0;v<f.length;v++)r(d,f[v]);n.Revenue=d;var m=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset","extendSession"],g=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];i(n),n.createInstance=function(e){return n._iq[e]={_q:[]},i(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
amplitude.init('YOUR_API_KEY_HERE');
</script>
5. Insert Script with Amplitude API Key
Insert the modified script into the 'Add new web analytic' in the 'head' field and click on Create.
Step 2: Connect Amplitude API Key
Navigate to your project and click on the Project Overview tab.
Find the Amplitude menu option and click +Create.
β
2. Add Amplitude API Key
Paste the API Key into the provided field.
You can use the same API key for both Production and Sandbox environments. Note that using the same key will send events from both test and live purchases to the same analytics project. Using separate keys will segregate test and live purchases.
Click on Create to complete the setup.
Step 3: Set Up the Server URL in the Stripe Account
1.Open Project in Onboarding Online Service, Navigate to your project and click on the Project Overview tab.
2. Find the Stripe section. If you have not added Stripe keys, click on Create and follow the guide. If you have already set up the Stripe keys, click on Edit.
3.Copy Server URLs
Here, you will find the server URLs for Production and Sandbox environments.
Production Server URL: Used for sending events for live purchases.
Sandbox Server URL: Used for sending events for test purchases.
4. Configure Webhooks in Stripe
Go to Stripe Dashboard Webhooks.
4.1 For Test Events
Copy the Sandbox Server URL.
Enable the Test mode toggle and click on Add endpoint.
Insert the Endpoint URL.
Click on Select Events.
Finish setup by clicking on Add Endpoint.
For Live Events
Copy the Production Server URL.
Disable the Test mode toggle and click on Add endpoint.
Insert the Endpoint URL.
Click on Select Events.
Finish setup by clicking on Add Endpoint.
Conclusion By following these steps, you can effectively set up Stripe S2S events to be sent to Amplitude, enabling you to track user purchases and other important events seamlessly. This integration helps in maintaining real-time analytics and ensuring a smooth operational workflow.