# How Midday integrated link-sharing with analytics in a few lines of code with Dub.co

Learn how Midday was able to leverage Dub.co's link infrastructure to programmatically generate short links at scale, with features like real-time analytics, auto-expiration, and link cloaking.

- Company: [Midday](https://midday.ai)
- About: Midday provides you with greater insight into your business and automates the boring tasks, allowing you to focus on what you love to do instead.
- Industry: FinTech, SaaS
- Company size: 1-10
- Founded: 2023
- Dub plan: Pro
- Published: April 3, 2024
- Source: https://dub.co/customers/midday

[Midday](https://midday.ai) is an all-in-one financial management platform that focuses on making business operations smarter by providing insights into a business' financials and streamlining activities like time-tracking and invoice management.

## The challenge: Adding link sharing features with analytics

When Midday launched their time tracker view on X (formerly Twitter), they received a lot of great feedback from users – one of which that stood out was the ability to **share tracked hours with their customers** in real-time.

![Midday Time Tracker](https://assets.dub.co/customers/midday-tracker.png)

With this report, business owners can focus on what they do best instead of manually keeping their customers up to date with time reports.

To build this feature, Midday needed a solution that would allow them to:

- Programmatically create beautiful short links at scale
- Track click analytics in real-time
- [Automatically expire links](https://dub.co/help/article/link-expiration) after a certain period
- [Link cloaking](https://dub.co/help/article/link-cloaking) to hide the actual destination URL

After evaluating different solutions, they decided to use [Dub.co](https://dub.co/) for their link-sharing needs.

## The solution: Dub's TypeScript SDK for programmatic link creation

Dub's [TypeScript SDK](https://www.npmjs.com/package/dub) allowed Midday to programmatically create beautiful short links with just a few lines of code.

[dub on npm](https://www.npmjs.com/package/dub)

Since Midday was already using Next.js and Supabase for their tech stack, they were able to quickly implement this by adding a new `create-report-action.ts` function:

```typescript title="create-report-action.ts"
"use server";

import { action } from "@/actions/safe-action";
import { createReportSchema } from "@/actions/schema";
import { createClient } from "@midday/supabase/server";
import { Dub } from "dub";

const dub = new Dub();

export const createReportAction = action(
  createReportSchema,
  async (payload) => {
    const supabase = createClient();

    const { data } = await supabase
      .from("reports")
      .insert(payload)
      .select("\*")
      .single();

    const link = await dub.links.create({
      url: `${params.baseUrl}/report/${data.id}`,
      rewrite: true,
      expiresAt: params.expiresAt,
    });

    return link;
  },
);
```

In this code snippet, Midday uses Next.js' [Server Actions](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations) to:

1. Create a new report in their Supabase database
2. Generate a short link for that report using Dub's SDK
3. The short link is then returned to the user, who can share it with their customers

> Optionally, Midday would also set an [expiration date](https://dub.co/help/article/link-expiration) for the link to ensure
> that the report is only accessible for a certain period. This is done by
> setting the `expiresAt` parameter in the
> `dub.links.create` method.
>
> For a better brand experience, Midday also uses the `rewrite` parameter to
> [cloak the actual destination URL](https://dub.co/help/article/link-cloaking). This way, the short link will look like
> `go.midday.ai/abc123` instead of `app.midday.ai/report/project/random-uuid-123456`.
>
> You can learn more about the different parameters you can set in the
> `dub.links.create` method in the [Dub API documentation](https://dub.co/docs/api-reference/endpoint/create-a-new-link).

Because of how easy the implementation was, Midday was able to quickly roll out this feature on two more reports – Profit and Revenue reports:

[Video: https://assets.dub.co/customers/midday-demo.mp4](https://assets.dub.co/customers/midday-demo.mp4)

To find more examples of how Midday use Dub, you can check out their [GitHub repository](https://github.com/midday-ai/midday) below:

[https://github.com/midday-ai/midday](https://github.com/midday-ai/midday)

## The results: Beautiful links with real-time analytics

Midday has a lot of features where files, activity reports, and other resources can be shared.

Previously, these links were secured by JWT tokens and were not very user-friendly to share with customers given how long they were.

With Dub's link infrastructure, not only were they able to generate beautiful short links at scale, but they also got access to real-time click analytics, which their users greatly appreciate.

[Post on X](https://x.com/i/status/1754256987729092939)

Midday also uses a `go.midday.ai` short link for their [desktop app download](https://midday.ai/download) command, which allows them to track the number of downloads and the source of the traffic:

![Midday download cURL command](https://assets.dub.co/customers/midday-download.png)

> I highly recommend using Dub for all your public-facing links – whether it's
> your email signature or social profiles. Putting aside the argument of
> aesthetics, Dub gives you valuable click analytics that can help you
> understand your audience better – not to mention that you can easily update
> the destination URL for your links whenever you need.
>
> Pontus Abrahamsson, Founder, Midday.ai

## The future of Midday x Dub

Midday has experienced a shift in their approach to links after implementing Dub. They now treat links as assets and utilize Dub to generate visual charts based on financial data. These charts can be easily shared with others, thanks to Dub's link infrastructure.

For example, their upcoming Midday AI feature will allow users to share financial insights with their customers in a visual format – easily shareable via a Dub-powered short link:

![Midday AI](https://assets.dub.co/customers/midday-ai.png)

> We are super happy customers of Dub and recommend them to everyone that have
> links that they want to share. Also, the customer support is truly one of the
> best you can get.
>
> Pontus Abrahamsson, Founder, Midday.ai

## Build your own link-sharing features with the Dub.co SDK

Want to build your own link-sharing features with [Dub's TypeScript SDK](https://npmjs.com/package/dub)? We created a simple template – affectionately dubbed `dublet` – to help you get started:

[https://github.com/dubinc/dublet](https://github.com/dubinc/dublet)

Have any questions? Feel free to [send us an email](mailto:support@dub.co?subject=Questions%20about%20Dub.co%20TypeScript%20SDK) or [tweet at us](https://twitter.com/dubdotco) – we'd love to help!

See [more customer stories](https://dub.co/customers.md).
