mixpanel-js icon indicating copy to clipboard operation
mixpanel-js copied to clipboard

allow /track endpoint to be renamed/localized in proxy deployments

Open ak--47 opened this issue 3 years ago • 0 comments

when self-hosting mixpanel and deploying from a proxy the SDK provides config options for changing the API host, so that they can match the proxy:

mixpanel.init("<YOUR_PROJECT_TOKEN>", {api_host: "https://<YOUR_PROXY_DOMAIN>"});

The nginx deployment we recommend also makes it possible to change the routes this proxy accepts: https://github.com/mixpanel/tracking-proxy/blob/master/nginx.conf

something like:

location /recordUserAction {
    proxy_set_header Host api.mixpanel.com;
    proxy_set_header X-Real-IP $http_x_forwarded_for;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_pass https://api.mixpanel.com/track;
}

this implementation is highly useful as some ad-blockers (like easyprivacy) will block all requests to */track regardless of the domain they are issued to.

currently, to get the above-mentioned implementation to work properly (where the SDK makes requests to /recordUserAction instead of /track), you'd need to fork the SDK and change this line:

 this.get_config('api_host') + '/track/',

to

 this.get_config('api_host') + '/recordUserAction/',

which introduces unnecessary complexity.

it would be ideal if the API routes were localizable, just like the api_host is; something like:

mixpanel.init("<YOUR_PROJECT_TOKEN>", {api_host: "https://<YOUR_PROXY_DOMAIN>", "track_route": "/recordUserAction/"})

i believe the only relevant api routes would be /track, /engage/, /decide/, /groups

ak--47 avatar Aug 13 '21 19:08 ak--47