SpeedInsights and Analytics not working

I have followed the guide as per

I am using the /pages project structure in NextJS and have made my code changes to _app.tsx . I am on these versions

  • @vercel/analytics”: “^1.5.0”
  • @vercel/speed-insights”: “^1.2.0”
  • “next”: “13.3.0”

My project is on the production version and I see the page contains a script tag for “/_vercel/insights/script.js” in my HTML as well as an HTTP request on load to /_vercel/insights/script.js. I’ve deleted and redeployed my node_modules as well as other cache invalidation techniques. This has been live for over 24 hours now.

Project information:

1 Like

Hello,

When I visit view-source:https://www.wisesheets.io/ or check network request, I don’t see Speed insights scripts being injected. Do you have a minimal reporducible steps which we can look?

What do you mean minimal reproducible steps? I’ve followed the instructions. Here is my full _app.tsx

import "@/globals.css";
import type { AppProps } from "next/app";
import { GoogleOAuthProvider } from "@react-oauth/google";
import ErrorModal from "@/components/ErrorModal";
import {
    useErrorStore,
    useLoadingStore,
    useSnackbarStore,
} from "@/state/store";
import LoadingModal from "@/components/LoadingModal";
import { useEffect } from "react";
import { hotjar } from "react-hotjar";
import Script from "next/script";
import { useRouter } from "next/router";
import SnackBar from "@/components/Snackbar";
import { SpeedInsights } from "@vercel/speed-insights/next";
import NextNProgress from "nextjs-progressbar";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import * as amplitude from "@amplitude/analytics-browser";
import { sessionReplayPlugin } from "@amplitude/plugin-session-replay-browser";
import { Analytics } from "@vercel/analytics/next";

const queryClient = new QueryClient();

export default function App({ Component, pageProps }: AppProps) {
    const router = useRouter();

    const { loading } = useLoadingStore((state) => state);
    const { error, setError } = useErrorStore((state) => state);
    const { snackbar } = useSnackbarStore((state) => state);

    useEffect(() => {
        hotjar.initialize("obfuscated", 6);
    }, []);

    useEffect(() => {
        if (router.isReady && process.env.NODE_ENV === "production") {
            const sessionReplayTracking = sessionReplayPlugin({
                forceSessionTracking: true,
                sampleRate: 0.01,
            });
            amplitude.add(sessionReplayTracking);
            amplitude.init("obfuscated", {
                autocapture: true,
            });
        }
    }, [router.isReady]);

    useEffect(() => {
        if (typeof window !== "undefined") {
            const rdt = window.rdt;
            rdt("init", "t2_9plptppx");
            rdt("track", "PageVisit");
            router.events.on("routeChangeComplete", () => {
                window.fbq("track", "PageView");
                rdt("track", "PageVisit");
                window.comet("custom_event_1");
            });
        }
    }, [router.events]);

    return (
        <>
            <GoogleOAuthProvider clientId="obfuscated">
                {error.hasError ? (
                    <ErrorModal
                        message={error.errorMessage}
                        onClick={() =>
                            setError({ hasError: false, errorMessage: "" })
                        }
                    />
                ) : null}
                {loading.isLoading ? (
                    <LoadingModal message={loading.message} />
                ) : null}
                {/* COMETLY SCRIPT START */}
                <Script
                    id="cometly-script"
                    strategy="afterInteractive"
                    src="https://t.cometlytrack.com/e?uid=3a0c69-3377699767000054-5dd014-s"
                ></Script>
                {/* COMETLY SCRIPT END */}
                {/* HEAP SCRIPT START*/}
                <Script id="heap-analytics" strategy="afterInteractive">
                    {`(window.heap = window.heap || []),
                    (heap.load = function (e, t) {
                      (window.heap.appid = e), (window.heap.config = t = t || {});
                      var r = document.createElement("script");
                      (r.type = "text/javascript"),
                        (r.async = !0),
                        (r.src = "https://cdn.heapanalytics.com/js/heap-" + e + ".js");
                      var a = document.getElementsByTagName("script")[0];
                      a.parentNode.insertBefore(r, a);
                      for (
                        var n = function (e) {
                            return function () {
                              heap.push(
                                [e].concat(Array.prototype.slice.call(arguments, 0))
                              );
                            };
                          },
                          p = [
                            "addEventProperties",
                            "addUserProperties",
                            "clearEventProperties",
                            "identify",
                            "resetIdentity",
                            "removeEventProperty",
                            "setEventProperties",
                            "track",
                            "unsetEventProperty",
                          ],
                          o = 0;
                        o < p.length;
                        o++
                      )
                        heap[p[o]] = n(p[o]);
                    });
                  heap.load("1493772514");`}
                </Script>
                {/* HEAP SCRIPT END*/}
                {/* REWARDFUL SCRIPT START */}
                <Script id="rewardful-script" strategy="afterInteractive">
                    {`(function (w, r) {
                    w._rwq = r;
                    w[r] =  w[r] || function () {
                        (w[r].q = w[r].q || []).push(arguments);
                    };
                })(window, "rewardful");`}
                </Script>
                <Script
                    strategy="afterInteractive"
                    src="https://affiliates.wisesheets.io/rw.js"
                    data-rewardful="8c6171"
                ></Script>
                {/* REWARDFUL SCRIPT END */}
                {/* REDDIT PIXEL SCRIPT START */}
                <Script id="reddit-pixel" strategy="afterInteractive">
                    {`!(function (w, d) {
                    if (!w.rdt) {
                      var p = (w.rdt = function () {
                        p.sendEvent
                          ? p.sendEvent.apply(p, arguments)
                          : p.callQueue.push(arguments);
                      });
                      p.callQueue = [];
                      var t = d.createElement("script");
                      (t.src = "https://www.redditstatic.com/ads/pixel.js"), (t.async = !0);
                      var s = d.getElementsByTagName("script")[0];
                      s.parentNode.insertBefore(t, s);
                    }
                  })(window, document);`}
                </Script>
                {/* REDDIT PIXEL SCRIPT END */}
                {/* GOOGLE ANALYTICS SCRIPT START */}
                <Script
                    strategy="afterInteractive"
                    src="https://www.googletagmanager.com/gtag/js?id=G-GMSNQQZN74"
                ></Script>
                <Script id="ga4" strategy="afterInteractive">
                    {`window.dataLayer = window.dataLayer || [];

                function gtag() {
                dataLayer.push(arguments);
                }

                gtag("js", new Date());

                gtag("config", "G-GMSNQQZN74");`}
                </Script>
                {/* GOOGLE ANALYTICS SCRIPT END */}
                {/* GOOGLE ADS SCRIPT START */}
                <Script
                    strategy="afterInteractive"
                    src="https://www.googletagmanager.com/gtag/js?id=AW-10798975584"
                ></Script>
                <Script id="gads" strategy="afterInteractive">
                    {`window.dataLayer = window.dataLayer || [];
                    function gtag() {
                        dataLayer.push(arguments);
                    }
                    gtag("js", new Date());
                    gtag("config", "AW-10798975584");`}
                </Script>
                {/* GOOGLE ADS SCRIPT END */}
                {/* GOOGLE OPTIMIZE SCRIPT START */}
                <Script
                    strategy="afterInteractive"
                    src="https://www.googleoptimize.com/optimize.js?id=OPT-N68QXW4"
                ></Script>
                {/* GOOGLE OPTIMIZE SCRIPT END */}
                {/* GOOGLE TAG MANAGE SCRIPT START*/}
                <Script id="gtm" strategy="afterInteractive">
                    {`(function (w, d, s, l, i) {
                    w[l] = w[l] || [];
                    w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
                    var f = d.getElementsByTagName(s)[0],
                    j = d.createElement(s),
                    dl = l != "dataLayer" ? "&l=" + l : "";
                    j.async = true;
                    j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
                    f.parentNode.insertBefore(j, f);
                })(window, document, "script", "dataLayer", "GTM-N6VSC5V");`}
                </Script>
                {/* GOOGLE TAG MANAGE SCRIPT END*/}
                {/* <!-- Facebook Pixel Code --> */}
                <Script id="meta-pixel" strategy="afterInteractive">
                    {`!function(f,b,e,v,n,t,s)
                    {if(f.fbq)return;n=f.fbq=function(){n.callMethod?
                    n.callMethod.apply(n,arguments):n.queue.push(arguments)};
                    if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
                    n.queue=[];t=b.createElement(e);t.async=!0;
                    t.src=v;s=b.getElementsByTagName(e)[0];
                    s.parentNode.insertBefore(t,s)}(window, document,'script',
                    'https://connect.facebook.net/en_US/fbevents.js');
                    fbq('init', '435895237583366');
                    fbq('track', 'PageView');`}
                </Script>
                {/* <!-- End Facebook Pixel Code --> */}
                <NextNProgress color={"var(--wisesheets-green)"} />
                <QueryClientProvider client={queryClient}>
                    <Component {...pageProps} />
                </QueryClientProvider>
                {snackbar.isShowing ? <SnackBar /> : null}
            </GoogleOAuthProvider>
            <Analytics />
            <SpeedInsights />
        </>
    );
}

Also here is a screenshot of the script in the inspection pane

Screenshot 2025-04-26 at 10.35.54 AM

Hey Jake,

I’m working on the Web Analytics and Speed Insights team :waving_hand:

Please make sure you’re importing the packages from @vercel/speed-insights/react and @vercel/analytics/react given your Next version.

You can also verify locally by looking at your browser console after doing a refresh, you should see the following:

[Vercel Speed Insights] Debug mode is enabled by default in development. No requests will be sent to the server.
[Vercel Web Analytics] Debug mode is enabled by default in development. No requests will be sent to the server.

Hope this helps!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.