Skip to content

Lightweight Go server that redirects users to platform-specific URLs (e.g., App Store, Play Store)

License

Notifications You must be signed in to change notification settings

ftp27/go-universal-redirect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

header

🚀 Universal Redirect

GitHub pull requests GitHub last commit GitHub issues License Go Version Go Report Card

Universal Redirect is a lightweight and efficient server designed to redirect incoming requests to platform-specific URLs. Perfect for directing users to the App Store or Play Store based on their device platform. Additionally, you can append custom metadata to the link and retrieve it in your app.

📚 Table of Contents

  1. 🚀 Usage
  2. ⚙️ How It Works
  3. 🛠️ Installation
    1. 📋 Requirements
    2. 📂 Clone the Repository
    3. 🐳 Docker
    4. 🌐 Dokku
  4. ⚙️ Configuration
  5. 📈 Analytics
  1. Deploy the server on your hosting platform.
  2. Create a link using the following format: https://your-host.com?meta=your-meta.
  3. Redirect users to this link.
  4. Retrieve the metadata in your app using a GET request to https://your-host.com/meta.
  1. The user clicks the link.
  2. The server reads the user agent to determine the user's platform and caches the client's IP.
  3. The server redirects the user to the appropriate platform-specific URL.
  4. Metadata is saved to the Redis cache.
  5. The app retrieves the metadata from the Redis cache.
  • Redis server
  • Default redirect URL
git clone https://github.com/ftp27/go-universal-redirect.git
cd go-universal-redirect

Build the Container

docker build -t universal-redirect .

Run the Container

docker compose up -d

Create the App

dokku apps:create universal-redirect

Create the Redis Service

dokku redis:create universal-redirect
dokku redis:link universal-redirect universal-redirect

Set Configuration

Required:

dokku config:set universal-redirect LINK_DEFAULT=https://example.com

Optional (InfluxDB):

dokku config:set universal-redirect INFLUX_TOKEN=... INFLUX_HOST=... INFLUX_DATABASE=...

Optional (Platform-Specific Links):

dokku config:set universal-redirect LINK_APPSTORE=https://apps.apple.com LINK_GOOGLEPLAY=https://play.google.com

Configure Ports

dokku proxy:ports-add universal-redirect http:80:8080 https:443:8080

Set Domain (Optional)

dokku domains:set universal-redirect example.com

Deploy the App

git remote add dokku ... # Add the Dokku remote
git push dokku main

Customize the server by setting the following environment variables:

  • REDIS_URL - URL of the Redis server (required)
  • LINK_DEFAULT - Default redirect URL (required)
  • LINK_APPSTORE - App Store redirect URL (optional)
  • LINK_GOOGLEPLAY - Play Store redirect URL (optional)
  • PORT - Server port (default: 8080)

For InfluxDB analytics, configure the following variables:

  • INFLUX_TOKEN - InfluxDB token (optional)
  • INFLUX_HOST - InfluxDB host (optional)
  • INFLUX_DATABASE - InfluxDB database (optional)

Universal Redirect supports InfluxDB for analytics. It sends each click and install event to the link measurement, along with platform and type information (click or install). Here are some example queries:

  • Total Clicks By Day:
SELECT 
  DATE_BIN(INTERVAL '1 day', time, '1970-01-01T00:00:00Z'::TIMESTAMP) AS day, 
  SUM(value) as value 
FROM "link" 
WHERE time >= now() - INTERVAL '30 day' AND type = 'click' 
GROUP BY day
from(bucket: "<bucket_name>")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "link")
  |> filter(fn: (r) => r["type"] == "click")
  |> group(columns: [])
  |> aggregateWindow(every: 1d, fn: sum, createEmpty: false)
  |> yield(name: "sum")
  • Total Clicks by Platform:
SELECT 
  SUM("value") AS "total_value", 
  platform 
FROM "link" 
WHERE time >= now() - INTERVAL '30 day' AND type = 'click' 
GROUP BY platform
from(bucket: "<bucket_name>")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "link")
  |> filter(fn: (r) => r["_field"] == "value")
  |> group(columns: ["platform"])
  |> aggregateWindow(every: 1d, fn: sum, createEmpty: false)
  |> yield(name: "sum")

About

Lightweight Go server that redirects users to platform-specific URLs (e.g., App Store, Play Store)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published