4lejandrito / next-plausible

Simple integration for https://nextjs.org and https://plausible.io analytics
https://next-plausible.vercel.app
MIT License
603 stars 33 forks source link

Refused to execute script from 'https://plausible.io/js/script.js' because its MIME type ('image/png') is not executable. #115

Closed paulmbw closed 11 months ago

paulmbw commented 11 months ago

Hi there,

I'm experiencing this issue that's preventing events being sent to Plausible:

Refused to execute script from 'https://plausible.io/js/script.js' because its MIME type ('image/png') is not executable.

I've correctly setup the library in my nextjs project:

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        <PlausibleProvider
          domain="launchtoday.dev"
        />
      </head>
      <body className={inter.className}>{children}</body>
    </html>
  );
}

I'm also seeing this error, though I'm not sure if it's related:

GET https://plausible.io/js/script.js net::ERR_ABORTED 499

Any idea what could be going wrong? Any help would be greatly appreciated!

I'm also using the API correctly when tracking an event, ensuring the event is setup as a goal in Plausible:

<button
          onClick={() => {
            plausible("hero-checkout-flutter-button-clicked");
          }}
...
</button>
4lejandrito commented 11 months ago

Hey!

Are you using an ad blocker?

paulmbw commented 11 months ago

Hey! Hmm, I am, but I've confirmed I can see the errors when in incognito mode

4lejandrito commented 11 months ago

What do you see if you paste https://plausible.io/js/script.js in the address bar?

paulmbw commented 11 months ago

I see the following:

!function(){"use strict";var a=window.location,r=window.document,o=r.currentScript,l=o.getAttribute("data-api")||new URL(o.src).origin+"/api/event";function s(t,e){t&&console.warn("Ignoring Event: "+t),e&&e.callback&&e.callback()}function t(t,e){if(/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(a.hostname)||"file:"===a.protocol)return s("localhost",e);if(window._phantom||window.__nightmare||window.navigator.webdriver||window.Cypress)return s(null,e);try{if("true"===window.localStorage.plausible_ignore)return s("localStorage flag",e)}catch(t){}var n={},i=(n.n=t,n.u=a.href,n.d=o.getAttribute("data-domain"),n.r=r.referrer||null,e&&e.meta&&(n.m=JSON.stringify(e.meta)),e&&e.props&&(n.p=e.props),new XMLHttpRequest);i.open("POST",l,!0),i.setRequestHeader("Content-Type","text/plain"),i.send(JSON.stringify(n)),i.onreadystatechange=function(){4===i.readyState&&e&&e.callback&&e.callback()}}var e=window.plausible&&window.plausible.q||[];window.plausible=t;for(var n,i=0;i<e.length;i++)t.apply(this,e[i]);function p(){n!==a.pathname&&(n=a.pathname,t("pageview"))}var c,w=window.history;w.pushState&&(c=w.pushState,w.pushState=function(){c.apply(this,arguments),p()},window.addEventListener("popstate",p)),"prerender"===r.visibilityState?r.addEventListener("visibilitychange",function(){n||"visible"!==r.visibilityState||p()}):p()}();
4lejandrito commented 11 months ago

That looks good. And what do you see by running curl -I https://plausible.io/js/script.js?

paulmbw commented 11 months ago

This is what I see after running that command:

HTTP/2 200
date: Wed, 13 Dec 2023 18:59:40 GMT
content-type: application/javascript
content-length: 1346
vary: Accept-Encoding
server: BunnyCDN-UK1-886
cdn-pullzone: 682664
cdn-uid: 153cb5b1-399a-48ef-b5bf-098c03770254
cdn-requestcountrycode: GB
access-control-allow-origin: *
cache-control: public, must-revalidate, max-age=86400
application: 10.0.1.2
cross-origin-resource-policy: cross-origin
permissions-policy: interest-cohort=()
x-content-type-options: nosniff
cdn-proxyver: 1.04
cdn-requestpullsuccess: True
cdn-requestpullcode: 200
cdn-cachedat: 12/13/2023 11:58:12
cdn-edgestorageid: 871
cdn-status: 200
cdn-requestid: f07526e7a9da5767bfb4ffcdfd8b3b2f
cdn-cache: HIT

hmm, surprisingly though, my events are now showing....but I've not changed anything 😭

4lejandrito commented 11 months ago

Maybe was some small outage of plausible.io 🤷 . Let's close this. Thanks!