Skip to main content

This document helpfully gives guidance for setting up a domain proxy in order to avoid issues with blockers: https://www.docs.developers.amplitude.com/analytics/domain-proxy/

We are following this procedure, however, I’m confused about two points in this doc. The first is where it says:

The HTTP API uses a slightly different endpoint from the SDKs, so to test, you need to temporarily set proxy_pass to https://api2.amplitude.com/2/httpapi/.

 

This implies /2/httpapi should not be final long-term value of the proxy pass, and is only temporary for testing. So what should the actual value be??

 

Second, it says later, in the SDK configuration section:

The SDK's don't point to the same API endpoint as the HTTP API V2, but rather a special endpoint for its custom payloads. Send them instead to https://api2.amplitude.com/

Which is again confusing because obviously the client SDK should not be configured to send events to amplitude’s domain, the entire purpose of the proxy is to avoid that and use our own domain. The SDK obviously should be configured to use our proxy endpoint, so can someone clarify what this is really saying?

 

I find that if I use the /2/httpapi path in the proxy pass, it seems to work. Without that path, it does not. /batch seems to work, also, but this is not mentioned anywhere. I am doubting that I’ve done it correctly given these two confusing statements. I’m just trying to proxy the network requests the @amplitude/analytics-browser npm module makes.

 

Thanks!

@jwhiting happy to help!

How are you trying to leverage the Proxy? Are you setting up the proxy with the intention on using it with an Amplitude SDK? If so, which one?

I would say that the purpose of a Proxy is to send requests to Amplitude through your own domain. This is mentioned at the beginning of the documentation.

A proxy service relays requests between a client and another service, acting as an intermediary step. Building a proxy service for your Amplitude org lets you proxy requests to the Amplitude API through your own domain.

 

My question to you is do you have your own domain that you are going to use to send data to Amplitude?


Hi @eddie.gaona thank you for helping out!

Yes, we have our own domain and are using the npm module @amplitude/analytics-browser in our React app to instrument it. We want to host the tracking endpoint at our domain under the path /amplitude. We are running a node express server on our domain and I’ve setup the express-http-proxy middleware for this purpose. Our node.js express server code for that looks like this:

import proxy from 'express-http-proxy';

app.use('/amplitude',
proxy('https://api2.amplitude.com/', {
proxyReqPathResolver: function (req) {
// rewrite the request path to /2/httpapi
return '/2/httpapi'
},
})
);

In the React App, we initialize the library with:

import * as amplitude from '@amplitude/analytics-browser';

amplitude.init(
process.env.REACT_APP_AMPLITUDE_API_KEY,
'',
{serverUrl: 'https://ourdomain.com/amplitude'}
);

Then on app events, we instrument with this code:

import { track } from '@amplitude/analytics-browser';

// ... example button click handler ...
handleButtonClick = (name) => {
track("Button Click", {name});
// ... process the actual button action
}

In development, this appears to work well. However, I don’t know if it’s configured correctly because, as I noted in my first post, the guide document says the /2/httapi endpoint should be used only temporarily for testing so I would like to understand the meaning of that statement clearly.

Thank you


Hi @eddie.gaona just checking in on this - did my reply orient you to be able to answer my question abou the correct SDK and proxy endpoint configurations? Thanks!


Hello @jwhiting apologies for the delay as it was a short week!

I asked our engineering team internally and this is the reasoning for testing with our endpoint:

if they test with http api v2 and use the SDK with http v2 api, then that means they could use the proxy directly in SDK to handle it. If it is legacy SDK with that proxy, then they need to do some transform for it, for just point to the sdk endpoint

 

Hope this helps!


Reply