Streaming live at 10am (PST)

Google Analytics on full site ONLY?


#1

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.


#2

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>

#3

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


#4

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


#5

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.


#6

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


#7

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


#8

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

Change it to this and give it another go.


#9

THERE we go.

Thanks guy. You’re the man.