Templates
Quickstart

Quick Start Guide

Prerequisites

Ensure you have Node.js and Docker installed on your machine. You can check if they are installed by running the following command in your terminal:

terminal
docker --version && node --version

If you don't have them installed, you can download them from the following links:

Download the Template Starter Code

To create a new project, run the following command in your terminal:

Terminal
npx create-moose-app@latest moose-product-analytics --template product-analytics

You can optionally replace moose-product-analytics with your desired project name.

Project Structure

This command will create a new project directory named moose-product-analytics with the following structure:

  • The project directory contains two subdirectories:

    • moose: Hosts the Moose application code for your backend clickstream event processing service
    • next: Hosts frontend analytics dashboard code and a helper script for capturing client-side events

    The moose and next folders can run separately. Optionally, you can use a different frontend like Grafana or query the database directly to consume the captured and processed data.

    Running the Moose Application Locally

    Start Docker

    First make sure Docker is running on your machine:

    terminal
    docker info

    Start Moose Development Server

    Navigate to the moose project directory and install the necessary dependencies:

    terminal
    cd moose-product-analytics/moose && npm install

    Now, start your Moose development server by running the following command:

    terminal
    npx moose-cli dev

    You should see a message in the CLI indicating the development server is running at http://localhost:4000.

    💡

    Did you know?

    The development server contains all the backend infrastructure needed to ingest, buffer, process, store, and query event data. Learn more about the Moose development server architecture.

    Understanding the Provided Starter Code

    Open your project in your favorite IDE. Once your project is open, navigate to the /datamodels folder inside the /app directory. Open the models.ts file. You will see a pre-defined PageViewRaw data model:

    moose/app/datamodels/models.ts
    import { Key } from "@514labs/moose-lib"
     
    export interface PageViewRaw {
        eventId    Key<string>
        timestamp  DateTime
        session_id String
        user_agent String
        locale     String
        location   String
        href       String
        pathname   String
        referrer   String
    }
     
    💡

    The PageViewRaw data model is a good starting point for capturing web page views.

    Verify the Moose Infrastructure

    When you run your local development server (via moose-cli dev), Moose automatically configures the infrastructure to ingest data that fits this schema. Open a new terminal window and see for yourself! Ensure you are in the moose project directory, and run:

    terminal
    npx moose-cli ls
    💡

    The ls command lists all the APIs and tables that Moose has created for you based on the Data Models you have defined. Learn more about the ls command.

    You should now see a table showing the following:

    Moose ls

    As you can see, Moose has already set up the necessary infrastructure, including:

    • An ingest/PageViewRaw API endpoint running on a web server for posting new PageViewRaw data samples from your web application.
    • A PageViewRaw table in a Clickhouse database where Moose will store the ingested events.

    Now you are ready to start instrumenting your web app to send live clickstream data to Moose.