Google Analytics on full site ONLY?

Is there any way to have Google Analytics only run on the full site, and not on the subdomain?

I know how to filter it within GA but that’s kind of a pain.

You could use some custom code instead of entering your GA details in the Webflow settings menu. This is an example created by copying the function that Webflow uses. You would just need to update the 2 variables at the top, hostname and your GA tracking number. This function will only run if the website domain matches the hostname that you define.

<script>
    const hostname = 'yourwebsite.com';
    const UA = 'yourUA'; // e.g. UA-123456789-1

    if (window.location.hostname === hostname) {
        (function (i, s, o, g, r, a, m) {
            i["GoogleAnalyticsObject"] = r;
            (i[r] =
                i[r] ||
                function () {
                    (i[r].q = i[r].q || []).push(arguments);
                }),
                (i[r].l = 1 * new Date());
            (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
            a.async = 1;
            a.src = g;
            m.parentNode.insertBefore(a, m);
        })(
            window,
            document,
            "script",
            "https://www.google-analytics.com/analytics.js",
            "ga"
        );
        ga("create", UA, "auto");
        ga("send", "pageview");
    }
</script>
1 Like

That’s slick. Thanks guy!

There really should be a toggle for this in the integrations tab, IMO.

Edit: Unfortunately, it isn’t working. Not sure if I’ve done something wrong. It shows up, but doesn’t actually trigger a visit. I’ve tried it in both the header and footer sections of the custom code tab, and with/without “https://www.”

Thoughts?

https://webtac.webflow.io
https://www.webtac.io

Tagging to make sure you see the edit: @jasondark

Any coderdudes who can take a look at this and see what I’ve done wrong?

Hey you don’t need the https://, you only need the host name.

So if your website URL is https://webtac.webflow.io, your host name is webtac.webflow.io.

If your website URL is https://www.webtac.webflow.io, your host name is www.webtac.webflow.io.

And for clarity you put this script into the footer code, not the head code.

Right now I have it in the footer, with the host name set to webtac.io. It is not triggering visits.

https://www.webtac.io

My bad, your host name is actually www.webtac.io:
image

Change it to this and give it another go.

THERE we go.

Thanks guy. You’re the man.

thank you, you are a savior
i was facing same issue for my web

you can set up “monster insights” . I think it is the same as GA