Skip to content

Commit 74b9fe5

Browse files
Add 'install' event that is fired once on first run (#11)
1 parent fed2f75 commit 74b9fe5

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

.env

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
NEXT_PUBLIC_POSTHOG_KEY=phc_VFn4CkEGHRdlVyOOw8mfkoj1DKVoG6y1007EClvzAnS
21
NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
32
NEXT_PUBLIC_POSTHOG_ASSET_HOST=https://us-assets.i.posthog.com
4-
NEXT_PUBLIC_POSTHOG_UI_HOST=https://us.posthog.com
3+
NEXT_PUBLIC_POSTHOG_UI_HOST=https://us.posthog.com
4+
5+
# @note: This is also set in the Dockerfile.
6+
NEXT_PUBLIC_POSTHOG_KEY=phc_VFn4CkEGHRdlVyOOw8mfkoj1DKVoG6y1007EClvzAnS

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ ENV DATA_DIR=/data
3535
ENV CONFIG_PATH=$DATA_DIR/config.json
3636
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
3737

38+
# @note: This is also set in .env
39+
ENV NEXT_PUBLIC_POSTHOG_KEY=phc_VFn4CkEGHRdlVyOOw8mfkoj1DKVoG6y1007EClvzAnS
40+
3841
# Sourcebot collects anonymous usage data using [PostHog](https://posthog.com/). Uncomment this line to disable.
3942
# ENV SOURCEBOT_TELEMETRY_DISABLED=1
4043

4144
# Configure dependencies
42-
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor
45+
RUN apk add --no-cache git ca-certificates bind-tools tini jansson wget supervisor uuidgen curl
4346

4447
# Configure zoekt
4548
COPY vendor/zoekt/install-ctags-alpine.sh .

entrypoint.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,33 @@
11
#!/bin/sh
22
set -e
33

4+
# Issue a info message about telemetry
5+
if [ ! -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then
6+
echo -e "\e[34m[Info] Disabling telemetry since SOURCEBOT_TELEMETRY_DISABLED was set.\e[0m"
7+
fi
8+
9+
# Check if DATA_CACHE_DIR exists, if not create it
10+
if [ ! -d "$DATA_CACHE_DIR" ]; then
11+
mkdir -p "$DATA_CACHE_DIR"
12+
fi
13+
14+
# In order to detect if this is the first run, we create a `.installed` file in
15+
# the cache directory.
16+
FIRST_RUN_FILE="$DATA_CACHE_DIR/.installed"
17+
if [ ! -f "$FIRST_RUN_FILE" ]; then
18+
touch "$FIRST_RUN_FILE"
19+
20+
# If this is our first run, send a `install` event to PostHog
21+
# (if telemetry is enabled)
22+
if [ -z "$SOURCEBOT_TELEMETRY_DISABLED" ]; then
23+
curl -L -s --header "Content-Type: application/json" -d '{
24+
"api_key": "'"$NEXT_PUBLIC_POSTHOG_KEY"'",
25+
"event": "install",
26+
"distinct_id": "'"$(uuidgen)"'"
27+
}' https://us.i.posthog.com/capture/ > /dev/null
28+
fi
29+
fi
30+
431
# Fallback to sample config if a config does not exist
532
if [ ! -f "$CONFIG_PATH" ]; then
633
echo -e "\e[33m[Warning] Config file at CONFIG_PATH not found. Falling back on sample config.\e[0m"

0 commit comments

Comments
 (0)