Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Adding option to add Reverse Proxy. #563

Open
cyfyifanchen opened this issue Mar 29, 2024 · 9 comments
Open

[Feature Request] Adding option to add Reverse Proxy. #563

cyfyifanchen opened this issue Mar 29, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@cyfyifanchen
Copy link

Adding option to add Reverse Proxy.

@kkopp001
Copy link

yesssss pleeaaase...... Half of our traffic doesnt get recorded which is super frustrating...

@AbdelrhmanMagdy AbdelrhmanMagdy added the enhancement New feature or request label Apr 3, 2024
@onyoo
Copy link

onyoo commented Apr 26, 2024

I took a stab at this in our codebase.. I can re-route the /collect calls with something like this, but I can't seem to intercept the https://www.clarity.ms/tag call which is required to start the /collect calls. Abandoning for now. Just mentioning it to show interest in this ticket.

(function() {
    var proxiedXhr = window.XMLHttpRequest;

    window.XMLHttpRequest = function() {
        var xhr = new proxiedXhr();

        xhr.addEventListener("load", function(p) {
            const originalUrl = p.target.responseURL;
            console.log("Intercepted XMLHttpRequest call", originalUrl);
            if (originalUrl.startsWith("https://r.clarity.ms/collect")
             xhr.open('GET', "other-url/clarity-collect");
        });

        return xhr;
    };
})();

@z0nekill
Copy link

z0nekill commented May 6, 2024

An alternative way is to use the npm package clarity-js. By setting the upload parameter of the clarity configuration to a reverse proxy URL you can funnel your traffic through your domain.

Conversely, if you were to do a custom inline tag of https://www.clarity.ms/tag/<project_id> and modify the upload parameter before loading it into a script tag that could also be a viable option, at least until it's officially supported by Clarity.

NPM Configuration Approach:
#408 (comment)

@cyfyifanchen
Copy link
Author

I thought the npm package clarity-js isn't recommended and the script tag is. But the workaround is nice, have you tested it?

@z0nekill
Copy link

z0nekill commented May 7, 2024

I'm using the npm package approach myself and have hardcoded the necessary values (works for now), I did take a look at using Regex to extract the configuration JSON from https://www.clarity.ms/tag/<project_id> to use with the NPM module but it was hacky - and prone to breaking.

However, your use case of modifying the upload parameter would be less hacky ;) as you would just be replacing

upload: "https://z.clarity.ms/collect" => "https://<mydomain>/collect"

But I wouldn't recommend it - because the script coming back from that service is bound to change, and so could the parameters and version of clarity-js returned as well.

@cyfyifanchen
Copy link
Author

Good to know, thanks for the detailed info. Let me try it out and see what I can share here.

@TurkerTunali
Copy link

It seems Mautic and Piwik are our only options because most of the visitors have adblockers.

@TonsiTT
Copy link

TonsiTT commented Jun 6, 2024

I tried proxying and it worked but it seems the collect endpoint takes the IP address of the proxy as the 'location' for the user session instead

@z0nekill
Copy link

z0nekill commented Jun 6, 2024

Have you tried setting X-Forwarded-For headers in your proxy setup?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants