### Install Dub Go SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/go.mdx Use 'go get' to install the Dub Go SDK. ```bash go get github.com/dubinc/dub-go ``` -------------------------------- ### Set Up Environment Variables Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Copy the example environment file to create a new .env file for local configuration. This file will be updated with specific values during setup. ```bash cp .env.example .env ``` -------------------------------- ### Run Development Server Source: https://github.com/dubinc/docs/blob/main/README.md Execute this command in the root of the repository to start the development server. Ensure Mintlify is installed globally first. ```bash npm run dev ``` -------------------------------- ### Start the development server Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Builds packages and starts the application servers. The web app will be accessible at localhost:8888. ```bash pnpm dev ``` -------------------------------- ### Install and Initialize Dub Go SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/quickstart/go.mdx Instructions on how to install the Dub Go SDK and initialize it with your API key. ```APIDOC ## Install Dub Go SDK To install the Dub Go SDK, run the following command: ```bash go get github.com/dubinc/dub-go ``` ## Initialize Dub Go SDK Initialize the Dub Go SDK by creating a new instance of the `Dub` struct with your API key. ```go package main import ( "log" "os" "context" dub "github.com/dubinc/dub-go" ) d := dub.New( dub.WithSecurity(os.Getenv("DUB_API_KEY")), ) ``` ``` -------------------------------- ### Install Dependencies Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Install all project dependencies using pnpm. ```bash pnpm i ``` -------------------------------- ### Install Dub Ruby SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/quickstart/ruby.mdx Install the Dub Ruby SDK using the gem command. This is the first step before initializing the SDK. ```bash gem install dub ``` -------------------------------- ### Install @dub/better-auth Plugin Source: https://github.com/dubinc/docs/blob/main/docs/conversions/leads/better-auth.mdx Install the @dub/better-auth plugin using your preferred package manager. ```bash npm install @dub/better-auth ``` ```bash yarn add @dub/better-auth ``` ```bash pnpm add @dub/better-auth ``` ```bash bun add @dub/better-auth ``` -------------------------------- ### Install Dub React Native SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/client-side-mobile/installation-guides/react-native.mdx Use this command to install the Dub React Native SDK. Ensure you have Node.js and npm/yarn installed. ```bash npm install dub-react-native # or yarn add dub-react-native ``` -------------------------------- ### Install Dub CLI with pnpm Source: https://github.com/dubinc/docs/blob/main/docs/sdks/cli.mdx Install the Dub CLI globally using pnpm. To update an existing installation, run the same command. ```bash pnpm i -g dub-cli@latest ``` -------------------------------- ### Install Dub CLI with npm Source: https://github.com/dubinc/docs/blob/main/docs/sdks/cli.mdx Install the Dub CLI globally using npm. To update an existing installation, run the same command. ```bash npm i -g dub-cli@latest ``` -------------------------------- ### Start Docker Compose Stack Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Navigate to the `apps/web` directory and run this command to start the Docker Compose stack, which includes a MySQL database and a PlanetScale simulator. ```bash docker compose up ``` -------------------------------- ### Install Mintlify Source: https://github.com/dubinc/docs/blob/main/README.md Use this command to install Mintlify globally via npm. This is a prerequisite for running the development server. ```bash npm i -g mintlify ``` -------------------------------- ### Install Dub Python SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/python.mdx Install the Dub Python SDK using pip. ```bash pip install dub ``` -------------------------------- ### Install Dub Swift SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/client-side-mobile/installation-guides/swift.mdx Use this command to install the Dub Swift SDK. Ensure you have Swift Package Manager configured. ```bash swift package add dubswift ``` -------------------------------- ### Install Dub TypeScript SDK with pnpm Source: https://github.com/dubinc/docs/blob/main/snippets/sdk-install-ts.mdx Use this command to install the Dub TypeScript SDK using pnpm. ```bash pnpm add dub ``` -------------------------------- ### Install Appwrite Node.js SDK Source: https://github.com/dubinc/docs/blob/main/docs/conversions/leads/appwrite.mdx Install the Appwrite Node.js SDK using npm. This is required for interacting with Appwrite services in your Next.js application. ```bash npm i node-appwrite ``` -------------------------------- ### Making a GET Request to /links Endpoint Source: https://github.com/dubinc/docs/blob/main/docs/api-reference/introduction.mdx Example of making a GET request to the /links endpoint using cURL, including the Authorization header for authentication. ```curl curl --request GET \ --url https://api.dub.co/links \ --header 'Authorization: Bearer dub_xxxxxx' ``` -------------------------------- ### Install Dub Analytics Script Source: https://github.com/dubinc/docs/blob/main/docs/sdks/client-side/features/conversion-tracking.mdx Install the Dub Analytics script to your website to begin tracking conversions. This script handles the initial setup for client-side tracking. ```html ``` -------------------------------- ### Create Link with Dub TypeScript SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/quickstart/remix.mdx Use this snippet to create a new short link. Ensure the Dub TypeScript SDK is installed and initialized. This basic example creates a link to Google.com. ```typescript export const loader = async () => { try { const result = await dub.links.create({ url: "https://www.google.com", }); return json(result, 200); } catch (error: any) { console.error(error); return json(error, 400); } }; ``` -------------------------------- ### Initializing Dub Client and Listing Links in PHP Source: https://github.com/dubinc/docs/blob/main/docs/api-reference/introduction.mdx Initialize the Dub client with an API key and make API calls to list links. Ensure the 'dub' package is installed. ```php use Dub\Client; $client = new Client([ 'api_key' => 'dub_xxxxxx' ]); // Make API calls $links = $client->links->list(); ``` -------------------------------- ### Initialize Dub SDK in UIKit App Source: https://github.com/dubinc/docs/blob/main/snippets/steps/initialize-ios-sdk.mdx Call `Dub.setup` with your publishable key and domain in the `application(_:didFinishLaunchingWithOptions:)` method of your AppDelegate. ```swift import UIKit import Dub @main class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? // Step 1: Obtain your Dub domain and publishable key private let dubPublishableKey = "" private let dubDomain = "" func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Step 2: Initialize the Dub SDK by calling `setup` Dub.setup(publishableKey: dubPublishableKey, domain: dubDomain) return true } } ``` -------------------------------- ### Install Dub CLI with yarn Source: https://github.com/dubinc/docs/blob/main/docs/sdks/cli.mdx Install the Dub CLI globally using yarn. To update an existing installation, run the same command. ```bash yarn global add dub-cli@latest ``` -------------------------------- ### Initializing Dub Client and Listing Links in Python Source: https://github.com/dubinc/docs/blob/main/docs/api-reference/introduction.mdx Initialize the Dub client with an API key and make API calls to list links. Ensure the 'dub' library is installed. ```python from dub import Dub client = Dub(api_key="dub_xxxxxx") # Make API calls links = client.links.list() ``` -------------------------------- ### Generate Prisma Client and Create Database Tables Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Run these commands in the `apps/web` directory to generate the Prisma client and then create the necessary database tables. ```bash pnpm run prisma:generate ``` ```bash pnpm run prisma:push ``` -------------------------------- ### Initializing Dub Client and Listing Links in Go Source: https://github.com/dubinc/docs/blob/main/docs/api-reference/introduction.mdx Initialize the Dub client with an API key and make API calls to list links. Ensure the 'dub-go' library is imported. ```go import ( "context" "github.com/dubinc/dub-go" ) client := dub.NewClient("dub_xxxxxx") // Make API calls ctx := context.Background() links, err := client.Links.List(ctx) ``` -------------------------------- ### Install Dub Analytics in React Source: https://github.com/dubinc/docs/blob/main/docs/sdks/client-side/installation-guides/react.mdx Use this snippet to install the Dub Analytics script in your React application. Ensure you have the necessary dependencies installed. ```jsx import React from 'react'; import { Analytics } from '@dub/analytics'; function App() { return (
{/* Other components */}
); } export default App; ``` -------------------------------- ### Seed the database with sample data Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Run this command in the `apps/web` directory to add sample data for testing. Existing data will not be deleted. ```bash pnpm run script dev/seed ``` -------------------------------- ### Initializing Dub Client and Listing Links in Ruby Source: https://github.com/dubinc/docs/blob/main/docs/api-reference/introduction.mdx Initialize the Dub client with an API key and make API calls to list links. Ensure the 'dub' gem is installed. ```ruby require 'dub' client = Dub::Client.new(api_key: "dub_xxxxxx") # Make API calls links = client.links.list ``` -------------------------------- ### Install Tinybird CLI Source: https://github.com/dubinc/docs/blob/main/docs/local-development.mdx Install the Tinybird CLI using pipx. Requires Python version 3.8 or higher. Ensure pipx is installed first, potentially via Homebrew. ```bash brew install pipx pipx install tinybird-cli ``` -------------------------------- ### Add Install Referrer Dependency for Android Source: https://github.com/dubinc/docs/blob/main/docs/concepts/deep-links/deferred-deep-linking.mdx Include the Google Play Install Referrer library in your Android app's build.gradle file to access install referrer information. ```kotlin // app/build.gradle { implementation 'com.android.installreferrer:installreferrer:2.2' } ``` -------------------------------- ### Configure Environment Variables Source: https://github.com/dubinc/docs/blob/main/docs/self-hosting.mdx Convert the .env.example file to .env and populate initial environment variables for domain configuration and Vercel integration. ```dotenv # The domain that your app will be hosted on NEXT_PUBLIC_APP_DOMAIN=acme.com # The short domain that your app will be using (could be the same as the above) NEXT_PUBLIC_APP_SHORT_DOMAIN=ac.me # The ID of the Vercel team that your app will be deployed to: https://vercel.com/docs/accounts/create-a-team#find-your-team-id TEAM_ID_VERCEL= # The unique access token for your Vercel account: https://vercel.com/guides/how-do-i-use-a-vercel-api-access-token AUTH_BEARER_TOKEN= ``` -------------------------------- ### Initializing Dub Client and Listing Links in Node.js Source: https://github.com/dubinc/docs/blob/main/docs/api-reference/introduction.mdx Initialize the Dub client with an API token and make API calls to list links. Ensure the 'dub' package is installed. ```javascript import { Dub } from "dub"; const dub = new Dub({ token: "dub_xxxxxx", }); // Make API calls const links = await dub.links.list(); ``` -------------------------------- ### Initialize Dub SDK in SwiftUI App Source: https://github.com/dubinc/docs/blob/main/snippets/steps/initialize-ios-sdk.mdx Call `Dub.setup` with your publishable key and domain in the `init` method of your SwiftUI App struct. Expose the `dub` instance as a SwiftUI environment value. ```swift import SwiftUI import Dub @main struct DubApp: App { // Step 1: Obtain your Dub domain and publishable key private let dubPublishableKey = "" private let dubDomain = "" init() { // Step 2: Initialize the Dub SDK by calling `setup` Dub.setup(publishableKey: dubPublishableKey, domain: dubDomain) } var body: some Scene { WindowGroup { ContentView() // Step 3: Expose the `dub` instance as a SwiftUI environment value .environment(\.dub, Dub.shared) } } } ``` -------------------------------- ### Example Invite Link Source: https://github.com/dubinc/docs/blob/main/help/article/how-to-invite-teammates.mdx This is an example of an invite link that can be shared with teammates to join a Dub workspace. ```text https://app.dub.co/invites/xxxxxx ``` -------------------------------- ### Initialize Dub Go SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/quickstart/go.mdx Initialize the Dub Go SDK by creating a new instance of the Dub struct. You must provide your DUB_API_KEY as an environment variable. ```go package main import ( "log" "os" "context" dub "github.com/dubinc/dub-go" ) d := dub.New( dub.WithSecurity(os.Getenv("DUB_API_KEY")), ) ``` -------------------------------- ### Track Install Referrer in React Native Source: https://github.com/dubinc/docs/blob/main/docs/concepts/deep-links/deferred-deep-linking.mdx Use this React Native component to track the install referrer on the first launch. It extracts deep links and tracks open events by sending data to an API. Ensure 'react-native-play-install-referrer' is installed. ```javascript // InstallReferrerTracker.js import { PlayInstallReferrer } from "react-native-play-install-referrer"; class InstallReferrerTracker { constructor() { this.isFirstLaunch = true; } trackInstallReferrer() { // Check if this is the first launch if (!this.isFirstLaunch) { return; } PlayInstallReferrer.getInstallReferrerInfo((installReferrerInfo, error) => { if (!error) { console.log( "Install referrer = " + installReferrerInfo.installReferrer, ); if (installReferrerInfo.installReferrer) { // Extract the deep link from the referrer URL const deepLink = this.extractDeepLinkFromReferrer( installReferrerInfo.installReferrer, ); if (deepLink) { // Track the deep link open with the extracted URL this.trackDeepLinkOpen(deepLink); } } } else { console.log("Failed to get install referrer info!"); console.log("Response code: " + error.responseCode); console.log("Message: " + error.message); } this.isFirstLaunch = false; }); } extractDeepLinkFromReferrer(referrerUrl) { try { // Parse the referrer URL to extract the deep link // e.g. for referrer=deepLink%3Dhttps%253A%252F%252Fdub.sh%252Fgps // the deep link is https://dub.sh/gps const referrerUrlObj = new URL(referrerUrl); const deepLinkParam = referrerUrlObj.searchParams.get("deepLink"); return decodeURIComponent(deepLinkParam); return null; } catch (error) { console.error("Error extracting deep link from referrer:", error); return null; } } async trackDeepLinkOpen(deepLink) { try { const response = await fetch("https://api.dub.co/track/open", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ deepLink, }), }); if (response.ok) { const data = await response.json(); const destinationUrl = data.link.url; // Navigate to the destination URL in your app this.navigateToDestination(destinationUrl); } } catch (error) { console.error("Error tracking deep link open:", error); } } navigateToDestination(destinationUrl) { // Implement your navigation logic here // This will depend on your navigation library (React Navigation, etc.) console.log("Navigating to:", destinationUrl); } } export default InstallReferrerTracker; ``` -------------------------------- ### Basic Go SDK Usage Source: https://github.com/dubinc/docs/blob/main/docs/sdks/go.mdx Initialize the Dub SDK with your API key, create a new link, and retrieve its click analytics in timeseries format. Ensure your DUB_API_KEY environment variable is set. ```go package main import ( "context" "fmt" "log" "os" dub "github.com/dubinc/dub-go" ) func main() { // Initialize the Dub SDK with your API key d := dub.New( dub.WithSecurity(os.Getenv("DUB_API_KEY")), // optional, defaults to DUB_API_KEY ) // Create a new link request := &operations.CreateLinkRequestBody{ URL: "https://google.com", } ctx := context.Background() res, err := d.Links.Create(ctx, request) if err != nil { log.Fatal(err) } if res.LinkSchema != nil { fmt.Println(res.LinkSchema.ShortLink) // e.g. https://dub.sh/abc123 } // Get analytics for the link analyticsRequest := operations.RetrieveAnalyticsRequest{ LinkId: res.LinkSchema.ID, GroupBy: "timeseries", Interval: "30d", } analyticsRes, err := d.Analytics.Retrieve(ctx, analyticsRequest) if err != nil { log.Fatal(err) } if analyticsRes.OneOf != nil { fmt.Println(analyticsRes.OneOf) // e.g. [{ start: "2024-01-01", clicks: 100 }] } } ``` -------------------------------- ### Install Dub TypeScript SDK with npm Source: https://github.com/dubinc/docs/blob/main/snippets/sdk-install-ts.mdx Use this command to install the Dub TypeScript SDK using npm. ```bash npm install dub ``` -------------------------------- ### Basic Usage of Dub Python SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/python.mdx Initialize the SDK with your API key, create a new short link, and retrieve its click analytics. ```python import os import dub from dub.models import operations # Initialize the Dub SDK with your API key d = dub.Dub( token=os.environ['DUB_API_KEY'], # optional, defaults to DUB_API_KEY ) # Create a new link res = d.links.create(request={ "url": "https://google.com", }) print(res.short_link) # e.g. https://dub.sh/abc123 # Get analytics for the link analytics = d.analytics.retrieve(request={ "link_id": res.id, "interval": "30d", "group_by": "timeseries", }) print(analytics) # e.g. [{ "start": "2024-01-01", "clicks": 100 }] ``` -------------------------------- ### Install Dub React Native SDK Source: https://github.com/dubinc/docs/blob/main/snippets/steps/install-react-native-sdk.mdx Use npm, yarn, or pnpm to install the Dub React Native SDK. ```sh # With npm npm install @dub/react-native ``` ```sh # With yarn yarn add @dub/react-native ``` ```sh # With pnpm pnpm add @dub/react-native ``` -------------------------------- ### Initialize React Native SDK Source: https://github.com/dubinc/docs/blob/main/docs/concepts/deep-links/attribution.mdx Initialize the Dub React Native SDK with your publishable key and short link domain. Ensure you replace 'YOUR_PUBLISHABLE_KEY' and 'your-dub-domain.com' with your actual credentials. ```javascript import { Dub } from 'dub-react-native'; Dub.initialize({ publishableKey: 'YOUR_PUBLISHABLE_KEY', domain: 'your-dub-domain.com', }); ``` -------------------------------- ### Install Dub TypeScript SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/typescript.mdx Install the Dub SDK using npm, pnpm, or yarn. Zod is a peer dependency for yarn. ```bash npm install dub ``` ```bash pnpm add dub ``` ```bash yarn add dub zod # zod is a peer dependency ``` -------------------------------- ### Create Link and Retrieve Analytics with Dub Ruby SDK Source: https://github.com/dubinc/docs/blob/main/docs/sdks/ruby.mdx Initialize the Dub SDK with your API key, create a new short link by providing a destination URL, and then retrieve click analytics for that link in a timeseries format. Ensure your DUB_API_KEY environment variable is set. ```ruby require 'dub' # Initialize the Dub SDK with your API key dub = ::OpenApiSDK::Dub.new dub.config_security( ::OpenApiSDK::Shared::Security.new( token: ENV['DUB_API_KEY'], # optional, defaults to DUB_API_KEY ) ) # Create a new link req = ::OpenApiSDK::Operations::CreateLinkRequest.new( request_body: ::OpenApiSDK::Operations::CreateLinkRequestBody.new( url: "https://google.com" ) ) res = dub.links.create(req) puts res.raw_response.body # e.g. { "shortLink": "https://dub.sh/abc123" } # Get analytics for the link analytics_req = ::OpenApiSDK::Operations::RetrieveAnalyticsRequest.new( link_id: res.raw_response.body["id"], interval: ::OpenApiSDK::Operations::Interval::THIRTYD, group_by: ::OpenApiSDK::Operations::GroupBy::TIMESERIES ) analytics_res = dub.analytics.retrieve(analytics_req) puts analytics_res.raw_response.body # e.g. [{ "start": "2024-01-01", "clicks": 100 }] ``` -------------------------------- ### Initialize iOS SDK Source: https://github.com/dubinc/docs/blob/main/docs/concepts/deep-links/attribution.mdx Initialize the Dub iOS SDK with your publishable key and short link domain. This setup is crucial for enabling deep link attribution on iOS. ```swift import Dub Dub.initialize(publishableKey: "YOUR_PUBLISHABLE_KEY", domain: "your-dub-domain.com") ```