/ Middleware

Fly Middleware: Server-Side Google Analytics

tl;dr Server-Side Google Analytics is now part of our Middleware library. Click configure, put in your tracking ID, and infuse analytic intelligence into each inbound server request.

Google Analytics is a powerful, nearly ubiquitous service that websites and applications use to gain insights into their visitors. It can answer questions like: Who is visiting? What are they doing? Which pages convert? Using Fly, you can activate server-side Google Analytics in a few clicks.

Let's get into why that's better than adding it as a client-side JavaScript snippet. After that, we'll show you how to get started.

Snippet vs. Server

Ghostery and Adblock Plus are two popular methods that web-goers use to stay safe and somewhat-anonymous while browsing the Internet. While their usage is valuable, overzealous content-blockers prevent even anonymized and trusty-worthy plugins like Google Analytics from gathering data.

Ghostery, for example, will block Google Analytics while Adblock Plus will not. To avoid your users appearing in stealth-mode, let's look at what happens we attach Analytics to the client via a JavScript snippet.

This article has a Google JavaScript snippet coded into the text. Upon clicking in, you may have noticed that your content-blocker detected and removed the Google Analytics tracker:

If we were to visit Real-Time Tracking within our Google Analytics dashboard, we'd see that... no one is visiting our site! This impression is lost to our analytic history.

These content blockers are proficient at blocking the client-side script that's trying to send information back to Google. However, if you're attaching data as part of the visitors request to the server, like with Fly Middleware, there's nothing to be blocked. If you visit any of our other articles, you see this in action:

With this configuration, your Real-Time Tracking information will tell you the truth: someone is checking out your page!

Great! But the best part is that server-side tracking with Middleware is even easier to set-up than installing a code snippet. Let's dig into that.

Fly Google Analytics

First, you'll need to signup for a Fly account. Your first 2,000,000 requests and 100 GB of transfer per month are free.

After that, complete your initial site set-up by specifying your hostname and your backend type:

Next, create an ALIAS or CNAME within your domain registrar for the Fly hostname that we generate for you.

Finally, head to the Middleware tab within your site, find Google Analytics, click configure, and then enter your Google Analytics TrackingID. Once configured, you'll see Google Analytics as part of your request round-trip:

Now, you'll have a more accurate flow of analytic data headed to your Google Analytics property for analysis. Radical!

Kellen Evan Person


Kellen Evan Person

A polite, forest-dwelling Canadian who enjoys coding and writing. He's spent near two decades building web applications and strives to keep development fun and light-hearted.

North Vancouver, Canada