How To Event Stream Data From Your Eleventy Site To Google Analytics Using RudderStack
Tags: eleventy, googleanalytics, dataanalytics, javascript
Published: 2021-12-30 05:56:41

[RudderStack](https://rudderstack.com/) is an open-source Customer Data Pipeline that helps you track your customer events from your web, mobile, and server-side sources and sends them to your entire customer data stack in real-time. We have also open-sourced our primary GitHub repository - [rudder-server](https://github.com/rudderlabs/rudder-server).

This article will guide you through the integration process of your Eleventy site with RudderStack using our [JavaScript SDK](https://github.com/rudderlabs/rudder-sdk-js). It'll also help you get started with tracking real-time user events and sending them to your preferred destinations.

Instrument event streams on your Eleventy site by following three simple steps:

1\. Integrate Eleventy 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 Eleventy site and verify the event stream

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

Before getting started, you need to ensure your Eleventy site is installed and set up. If you haven't done it yet, visit the [official Eleventy installation doc](https://www.11ty.dev/) to get started.

Step 1: Integrating Eleventy Site With RudderStack JavaScript SDK
-----------------------------------------------------------------

### Creating A Source In RudderStack

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

1\. Log into your [RudderStack dashboard](https://app.rudderstack.com/). If you're new to RudderStack, [sign up here](https://app.rudderlabs.com/signup?type=freetrial).

2\. Once you are logged in, you will see the following dashboard:

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

3\. Note the Data Plane URL. You will need this URL to integrate your Eleventy site with RudderStack.

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

4\. Create a Source by clicking on the Add Source option. You can also click on the Directory option in the left nav bar and select Event Streams under Sources, as shown. Next, select JavaScript.

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

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

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

6\. Your JavaScript source is now configured and ready to track events. Note the Write Key associated with this source. You will need it to set up the RudderStack integration with your Eleventy site.

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

### Integrating Your Eleventy Site With RudderStack

Integrate RudderStack JavaScript code with your Eleventy Site and set up the tracking code following steps given below:

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

```
<script> rudderanalytics=window.rudderanalytics=[];for(var methods=["load","page","track","identify","alias","group","ready","reset","getAnonymousId","setAnonymousId"],i=0;i<methods.length;i++){var method=methods[i];rudderanalytics[method]=function(a){return function(){rudderanalytics.push([a].concat(Array.prototype.slice.call(arguments)))}}(method)}rudderanalytics.load("1pBSDA8DDqVgLRzxN5JWyKJQoNN","https://hosted.rudderlabs.com"),rudderanalytics.page();rudderanalytics.track(  "Test Event in 11ty",  {    revenue:  30,    currency:  'INR' ,    user_actual_id:  12345  },   () => {console.log("Track call");});</script><script src="https://cdn.rudderlabs.com/rudder-analytics.min.js"></script>

```

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

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

RudderStack supports over [80 third-party tools](https://rudderstack.com/integration/) and platforms to which you can securely send your tracked events. In this section, we will route the Eleventy Site events to [Google Analytics](https://docs.rudderstack.com/destinations/google-analytics-ga). In order to add Google Analytics as a destination in RudderStack, follow the steps given below:

1\. In your RudderStack dashboard's left navigation bar, click on Destinations 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\. Next, 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 Next, as shown:

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

4\. Now, connect the JavaScript source that we have already configured previously in Step 1.

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

5\. 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\. You can also transform your events before sending them to Google Analytics. For more information on this feature, check out our [documentation](https://docs.rudderstack.com/adding-a-new-user-transformation-in-rudderstack) on User Transformations.

7\. Well done! Your Google Analytics is now configured as a destination. You should see the following source-destination connection in your dashboard:

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

(Alternate) Step 2: Create A Warehouse Destination For Your Eleventy Site Events
--------------------------------------------------------------------------------

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.

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

Once you have set up the project and assigned the required user permissions, follow the instructions given below:

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

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

2\. Assign a name to your Destination and click Next.

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

3\. Connect to the JavaScript source from which you will track your Eleventy Site events. Then, click Next.

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

4\. Specify Connection Credentials. Add BigQuery Project ID and the Staging Bucket Name. You can refer to these [instructions to get this information.](https://docs.rudderstack.com/data-warehouse-integrations/google-bigquery#setting-up-google-bigquery)

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

5\. Finally, copy the contents of the private JSON file. You can refer to our [documentation](https://docs.rudderstack.com/data-warehouse-integrations/google-bigquery#setting-up-the-service-account-for-rudderstack) for more information on how to do this.

That's all! You have now successfully set up BigQuery as a warehouse destination in RudderStack.

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

Now that you have successfully configured your event source and destination, next you need to verify that the event stream is working properly. To do so, deploy your Eleventy Site application and test if the events are being tracked by the JavaScript source and are being delivered to your Google Analytics destination.

Follow the steps below:

1\. In your Terminal or cmd, navigate to the folder containing your Eleventy Site.

2\. To deploy the app, execute `npx` `@11ty/eleventy --serve` command, as shown:

![](https://cdn.sanity.io/images/mwovquhr/production/9e8601f2e4a81706b582ccec6fc0747e1aba91c9-662x438.png)

3\. Open your Eleventy site by visiting the server address mentioned in the cmd or [http://localhost:8080](http://192.168.0.122:8080/) on your browser.

![](https://cdn.sanity.io/images/mwovquhr/production/6ca1c61ceb845be147edc3670e71cb56bcc6eef2-546x287.png)

4\. Next, verify if `rudder-analytics.js` (RudderStack's JavaScript SDK) has loaded correctly. To do this, go to 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/b091afae18bff8e2912fa595dc48a0d74420acf2-602x624.png)

5\. 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 events start sending 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\. Brilliant! RudderStack has successfully tracked and captured the events:

![](https://cdn.sanity.io/images/mwovquhr/production/5f2426ee6e0dafe55fb74f75fb7d1c93b13b9df0-1876x959.png)

7\. Next, check if the events are sent to your Google Analytics destination. Go to your Google Analytics dashboard and navigate to the Realtime - **Events **option.

![](https://cdn.sanity.io/images/mwovquhr/production/b8d1fcb5fdfc2ff5a20561575e3f63f0580e9a0e-1372x732.png)

As you can see, there is one active user on the Eleventy site, and the track event is visible as well. This means the event was tracked and delivered successfully. Similarly, you will also receive the event in your Google BigQuery warehouse.

Summary
-------

Web analytics is the process of collecting and analyzing the user behavior data on a website. It helps companies understand how users interact with their websites in order to optimize performance and create better end-user experiences. RudderStack enables companies to perform web analytics securely.

To conclude, in this article we covered how you can use Rudderstack to capture real-time event data from your Eleventy site by instrumenting the site with the RudderStack JS SDK and setting up the tracking code. We also detailed how to integrate Google Analytics as a destination in RudderStack in order to route real-time event data from your Eleventy 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.rudderstack.com/signup?type=freetrial)