How To Event Stream Data From Your Hugo Site To Google Analytics Using RudderStack
Tags: hugo, javascript, googleanalytics, eventstream
Published: 2022-01-20 05:55:17

[RudderStack](https://rudderstack.com/) is an open-source customer data platform that empowers you to track your customer events from your web, mobile, and server-side sources in real-time. We have also open-sourced our primary repository - [rudder-server](https://github.com/rudderlabs/rudder-server) - on GitHub. This article will walk you through the process of integrating your [Hugo site](https://gohugo.io/) with RudderStack using our [JavaScript SDK](https://github.com/rudderlabs/rudder-sdk-js). It will also help you track the real-time user events and send them to the destinations of your choice.

You can easily implement event streams on your Hugo site by following three steps:

1\. Integrate your Hugo site with RudderStack JavaScript SDK and set up the tracking code

2\. Set up a tool or warehouse destination in RudderStack to route all the event data in real-time

3\. Deploy your Hugo site and verify the event stream

Pre-Requisites
--------------

Before getting started, we are assuming that you have already installed the Hugo site on your system. In case you haven't, visit the official [Hugo](https://gohugo.io/getting-started/quick-start/) installation doc to get started.

Step 1: Integrating Your Hugo Site With The RudderStack JavaScript SDK
----------------------------------------------------------------------

### Creating A Source In RudderStack

First and foremost, open your RudderStack Dashboard and set up a JavaScript source to track the events from your Hugo site. Follow the instructions listed below to set up the source:

1\. Log into your [RudderStack dashboard](https://app.rudderstack.com/). If you don't have an account at RudderStack, [sign up here](https://app.rudderlabs.com/signup?type=freetrial).

2\. Once done, you will see the following dashboard:

![](https://cdn.sanity.io/images/mwovquhr/production/d103d2c6452dcee6f44c27ee8087e864cdbb84a2-630x319.png)

3\. Note the Data Plane URL as you will need this URL to integrate your Hugo site with RudderStack.

![](https://cdn.sanity.io/images/mwovquhr/production/654cffa6fa2c334832f4281927f69d3d6ce49fd7-518x194.png)

4\. Next, create a Source by clicking on the Add Source option. If already added, you can also click on the Directory option in the left navigation bar, and select Event Streams under Sources, as shown. Next, select JavaScript as a source.

![](https://cdn.sanity.io/images/mwovquhr/production/e906f26d6b0132d870057e3700cff46b4f9a107c-630x327.png)

5\. Add a name for your JavaScript source and click on Next.

![](https://cdn.sanity.io/images/mwovquhr/production/d0e2ef39955da5294c0984f3bba7f429c52dd18c-630x195.png)

6\. Now the JavaScript source is configured and all set to track events. Take note of the WRITE KEY associated with this source. You will need this key to set up the RudderStack integration with your Hugo site.

![](https://cdn.sanity.io/images/mwovquhr/production/00105d7adc808d9f3f0323050edbcb516d7703ae-630x149.png)

### Integrating Your Hugo Site With RudderStack

Integrate RudderStack JavaScript code with your Hugo Site and set up the tracking code using the following steps:

1.  Open your index.html file and insert the following code within the `<head></head>` tag:

```JavaScript
<script>
      rudderanalytics = window.rudderanalytics = [];
        var methods = [
          "load",
          "page",
          "track",
          "identify",
          "alias",
          "group",
          "ready",
          "reset",
          // "requireIntegration",
          "setAnonymousId",
          "getAnonymousId",
        ];
        for (var i = 0; i < methods.length; i++) {
          var method = methods[i];
          rudderanalytics[method] = (function (methodName) {
            return function () {
              rudderanalytics.push(
                [methodName].concat(Array.prototype.slice.call(arguments))
              );
            };
          })(method);
        }
        rudderanalytics.load("1skegHQpcGKIfhSHCHTVbsv9oui","https://hosted.rudderlabs.com");
        rudderanalytics.track("Simple track call");
    </script>
    <script src="https://cdn.rudderlabs.com/v1/rudder-analytics.min.js"></script>
```

>
> Important: *You can refer to our sample Hugo site present in [RudderStack Hugo site repository](https://github.com/rudderlabs/rudder-analytics-hugo) for more information on modifying these files.*

Step 2: Creating A Destination Tool In RudderStack For Routing Your Hugo Site Events
------------------------------------------------------------------------------------

RudderStack supports more than [80 third-party tools](https://rudderstack.com/integration/) as well as platforms where you can send your tracked events securely. In this section, you will route the Hugo site events to [Google Analytics](https://docs.rudderstack.com/destinations/google-analytics-ga) using RudderStack integration. To do this, follow the below steps:

1\. Click on Destinations in your RudderStack dashboard's left navigation bar, and then select Add Destination as shown:

> Note: *You can use the Connect Destinations option if you have already configured a destination in RudderStack and want to send your event data to that platform.*

![](https://cdn.sanity.io/images/mwovquhr/production/bb027d1e3ad7665d7f7bdf68bd3df7da833daae8-630x316.png)

2\. Choose Google Analytics as your destination.

![](https://cdn.sanity.io/images/mwovquhr/production/dee0813b1679e76a5fb623df69bfd21dafd7e804-630x316.png)

3\. Add a name to your destination and click on Next, as shown:

![](https://cdn.sanity.io/images/mwovquhr/production/638e3e2ef556357ec424b5ec30d3943504fb9827-630x317.png)

4\. Once the destination is named, connect it to the JavaScript source that you have already configured in Step 1 - Integrating your Hugo site with the RudderStack JavaScript SDK.

![](https://cdn.sanity.io/images/mwovquhr/production/22da8027cb80f55cc4c81cc56e8e49aa30996b89-630x317.png)

5\. Next, on the Connection Settings page, configure your Google Analytics destination with your Google Analytics Tracking ID and other optional settings, as shown below. Then, click Next.

![](https://cdn.sanity.io/images/mwovquhr/production/53654b0aee376a392973f2b0f7c55b66a2749272-630x334.png)

6\. Before sending your events to Google Analytics, Rudderstack also provides you the option of transforming them. To learn more about this feature, check out our [User Transformations documentation.
](https://docs.rudderstack.com/adding-a-new-user-transformation-in-rudderstack)

7\. Congratulations! Google Analytics is now configured as a destination. Now, you will be able to see the following source-destination connection in your dashboard:

![](https://cdn.sanity.io/images/mwovquhr/production/6cd115d36f1604e2a795e207d55fd4c9f2f96f3b-630x244.png)

(Alternate) Step 3: Create A Warehouse Destination For Your Hugo Site Event
---------------------------------------------------------------------------

> Important: *Before you configure a data warehouse as a destination in RudderStack, you will need to set up a new project in your data warehouse. Also, you need to create a new RudderStack user role with the relevant permissions. Follow our [documentation](https://docs.rudderstack.com/data-warehouse-integrations) to get step-by-step instructions on how to do this for your preferred data warehouse.*

In this tutorial, you will configure a [Google BigQuery warehouse destination](https://rudderstack.com/integration/bigquery/on) to route all the events from your Hugo Site. You can also follow [our documentation](https://docs.rudderstack.com/data-warehouse-integrations/google-bigquery) to set up a BigQuery project with the required permissions for the service account.

Once the project is all set and the required user permissions are assigned, follow the instructions given below:

1\. From the Destinations Directory, select Google BigQuery:

![](https://cdn.sanity.io/images/mwovquhr/production/d901af95b4b3a046ea62b4e7354473f7a4932deb-630x328.png)

2\. Name your Destination and click Next.

![](https://cdn.sanity.io/images/mwovquhr/production/fdf892d0f37e4c6c9ec4c31bd48253b26a6da774-630x290.png)

3\. Now, connect to the JavaScript source from which you will track your Hugo Site events. Then, click Next.

![](https://cdn.sanity.io/images/mwovquhr/production/ae4a58bd7965bf9088d15e2b85233639fd7fbc67-630x290.png)

4\. Specify Connection Credentials. Add BigQuery Project ID and Staging GCS Storage Bucket Name by following these [instructions](https://docs.rudderstack.com/data-warehouse-integrations/google-bigquery#setting-up-google-bigquery):

![](https://cdn.sanity.io/images/mwovquhr/production/e92473af23c60ee47bdaef090e8131796594864c-357x834.png)

5\. Once done, copy the contents of the private JSON file.

Voila! You have now successfully set up BigQuery as a warehouse destination in RudderStack.

Step 3: Deploying Your Hugo Site And Verifying The Event Stream
---------------------------------------------------------------

Now that your event source and destination are configured, verify that the event stream is working. For this, deploy your Hugo Site application and test whether the events are being tracked by the JavaScript source and delivered to your Google Analytics destination.

Follow the steps below:

1\. In your Terminal or Command Prompt, navigate to the folder containing your Hugo Site.

2\. To deploy the app, execute the hugo server -D command, as shown:

![](https://cdn.sanity.io/images/mwovquhr/production/4c639617edc3a6a694710e82625a2bda26536ef0-986x538.png)

3\. Navigate to your Hugo site by visiting the server address mentioned in the cmd or <http://localhost:1313/> on your browser.

![](https://cdn.sanity.io/images/mwovquhr/production/8e7b852ae3517c14be8794d62f8e83a73757524d-1347x663.png)

4\. Next, verify if `rudder-analytics.js` (RudderStack's JavaScript SDK) has loaded correctly. For this, open your browser's Developer tools and navigate to the Network tab. The following screenshot highlights this option for Google Chrome:

![](https://cdn.sanity.io/images/mwovquhr/production/b06a49900e421d8ebea7b881fb9b3fb266371048-523x660.png)

5\. Now check if RudderStack can track the different page views and clicks by clicking on the Live Events tab of your JavaScript source on the RudderStack dashboard page:

> Note: *After deploying your app, there can sometimes be a lag before the Hugo site starts sending the events and are visible in your dashboard and destination. Don't worry. All events are captured and sent; just be aware that they can take a few minutes to show up.*

![](https://cdn.sanity.io/images/mwovquhr/production/1859e5a94847c323bd450e19b15fcb46b8973bee-630x272.jpg)

6\. Great! RudderStack has successfully tracked and captured the event:

![](https://cdn.sanity.io/images/mwovquhr/production/28096c44c934d0f847bf046f9780af01fcafacac-1508x923.png)

7\. Next, check if the events are being sent to your Google Analytics destination. For that, go to your Google Analytics dashboard and navigate to the Realtime > Events option.

![](https://cdn.sanity.io/images/mwovquhr/production/aeb67bdaa587fe2b25e80a928e348b78d52ecdef-1298x532.png)

As you can see there is one active user on the Hugo site, and the event call is visible. This indicates that the event was tracked and delivered successfully. You will also receive the event in your Google BigQuery warehouse.

Summary
-------

Web analytics facilitates collecting and analyzing user behavior data on a website. It helps companies understand their user behavior in order to optimize performance and create better end-user experiences. RudderStack enables companies to perform web analytics securely.

In this article, you learned how Rudderstack can be used to capture real-time event data from your Hugo site by integrating the site with the RudderStack JS SDK and setting up the tracking code. You also explored how to integrate Google Analytics as a destination in RudderStack to route real-time event data from your Hugo site to the Google Analytics platform.

### Sign Up For Free And Start Sending Data

Test out our event stream, ELT, and reverse-ETL pipelines. Use our HTTP source to send data in less than 5 minutes, or install one of our 12 SDKs in your website or app. [Get started](https://app.rudderlabs.com/signup?type=freetrial)