analytics icon indicating copy to clipboard operation
analytics copied to clipboard

Logging plausible event results in CORS error

Open codemonkey800 opened this issue 1 year ago • 3 comments

Past Issues Searched

  • [X] I have searched open and closed issues to make sure that the bug has not yet been reported

Issue is a Bug Report

  • [X] This is a bug report and not a feature request, nor asking for self-hosted support

Using official Plausible Cloud hosting or self-hosting?

Plausible Cloud from plausible.io

Describe the bug

For some reason a plausible event we send is throwing a CORS error on some pages. We're not entirely sure what could be the issue because the tracking event is reused in two different pages. It works on one page, but it doesn't work on the other.

The payload of the successful event looks like:

{
  "name": "View tomogram",
  "domain": "cryoetdataportal.czscience.com",
  "url": "https://cryoetdataportal.czscience.com/datasets/10002",
  "props": {
    "datasetId": 10002,
    "organism": "Homo sapiens",
    "runId": 623,
    "tomogramId": 11134,
    "type": "dataset"
  }
}

The payload of the event with the CORS error looks like:

{
  "name": "View tomogram",
  "domain": "cryoetdataportal.czscience.com",
  "url": "https://cryoetdataportal.czscience.com/runs/623",
  "props": {
    "datasetId": 10002,
    "organism": "Homo sapiens",
    "runId": 623,
    "tomogramId": 11134,
    "type": "run"
  }
}

Expected behavior

It should log the event on both pages and not throw a CORS error.

Screenshots

image image

Environment

- OS: MacOS 14.3 
- Browser: Google Chrome
- Browser Version: 121.0.6167.160

codemonkey800 avatar Feb 09 '24 01:02 codemonkey800

I have reproduced the issue and will get back to you.

aerosol avatar Feb 12 '24 08:02 aerosol

Hi @codemonkey800

I think the problem originates from this package: https://www.npmjs.com/package/axios-cache-interceptor?activeTab=readme

Please see https://github.com/arthurfiorette/axios-cache-interceptor/blob/ad69e6d6e491cfa5fe2cb542bc90fd205fc823e3/docs/src/config/request-specifics.md#cachecachetakeover

in particular this bit:

image

Please try the fallback suggested and see if the OPTIONS XHR requests are handled then.

aerosol avatar Feb 12 '24 09:02 aerosol

FWIW the problem occurs only for that button:

image

and not that one:

image

Even though both trigger a new tab link. That should help you figure out the difference

aerosol avatar Feb 12 '24 10:02 aerosol

closing this now but feel free to contact our support if you have any further questions

metmarkosaric avatar Feb 20 '24 07:02 metmarkosaric

@metmarkosaric i am struggling with the same issue. What exactly is meant with the fallback?

awacode21 avatar Apr 25 '24 18:04 awacode21

i am using Plausible with vercel. Does that look like the correct setting?

//vercel.json

{
    "headers": [
        {
            "source": "/(.*)",
            "headers": [
                {
                    "key": "Cache-Control",
                    "value": "max-age=0, s-maxage=86400, stale-while-revalidate=59"
                },
                {
                    "key": "Access-Control-Allow-Headers",
                    "value": "Cache-Control, Pragma, Expires"
                }
            ]
        }
    ]
}

awacode21 avatar Apr 25 '24 18:04 awacode21