Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/actions/setup-sqruff/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: 'Install Sqruff CLI'
description: 'Install sqruff SQL linter and formatter'
author: 'quarylabs (forked fix from fank)'

inputs:
version:
description: 'Version of Sqruff CLI to install'
required: false
default: 'latest'
github-token:
description: 'GitHub token for API requests (helps avoid rate limiting)'
required: false
default: ''

runs:
using: 'composite'
steps:
- run: |
set -e # Exit on error

# Function to make GitHub API calls with optional token
github_api_call() {
local url=$1
if [ -n "${{ inputs.github-token }}" ]; then
curl -s -H "Authorization: token ${{ inputs.github-token }}" "$url"
else
curl -s "$url"
fi
}

# Determine version to install
if [ "${{ inputs.version }}" = "latest" ]; then
echo "Fetching latest Sqruff release..."
API_RESPONSE=$(github_api_call "https://api.github.com/repos/quarylabs/sqruff/releases/latest")

# Check if API call was successful
if echo "$API_RESPONSE" | grep -q "API rate limit exceeded"; then
echo "::error::GitHub API rate limit exceeded. Please provide a github-token input."
exit 1
fi

LATEST_VERSION=$(echo "$API_RESPONSE" | grep '"tag_name"' | cut -d '"' -f 4)

if [ -z "$LATEST_VERSION" ]; then
echo "::error::Failed to fetch latest version from GitHub API"
echo "API Response: $API_RESPONSE"
exit 1
fi

echo "Latest version is $LATEST_VERSION"
VERSION=$LATEST_VERSION
else
VERSION=${{ inputs.version }}
fi

# Detect architecture
ARCH=$(uname -m)
case $ARCH in
x86_64)
BINARY_NAME="sqruff-linux-x86_64-musl"
;;
aarch64|arm64)
BINARY_NAME="sqruff-linux-aarch64-musl"
;;
*)
echo "::error::Unsupported architecture: $ARCH"
exit 1
;;
esac

# Download and install
echo "Installing Sqruff CLI version $VERSION for architecture $ARCH"
DOWNLOAD_URL="https://github.com/quarylabs/sqruff/releases/download/$VERSION/${BINARY_NAME}.tar.gz"

echo "Downloading from: $DOWNLOAD_URL"
if ! wget -q --show-progress "$DOWNLOAD_URL" -O sqruff-cli.tar.gz; then
echo "::error::Failed to download Sqruff CLI from $DOWNLOAD_URL"
exit 1
fi

echo "Extracting archive..."
if ! tar -xzf sqruff-cli.tar.gz; then
echo "::error::Failed to extract tarball"
exit 1
fi

echo "Installing binary..."
if ! sudo mv sqruff /usr/local/bin/sqruff; then
echo "::error::Failed to install sqruff binary"
exit 1
fi

# Make sure it's executable
sudo chmod +x /usr/local/bin/sqruff

# Verify installation
echo "Verifying installation..."
if sqruff --version; then
echo "✅ Sqruff CLI installed successfully!"
else
echo "::error::Failed to verify Sqruff CLI installation"
exit 1
fi
shell: bash
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
deno-version: '1.45.2'

- name: Install sqruff
uses: quarylabs/install-sqruff-cli-action@main
uses: ./.github/actions/setup-sqruff
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Atlas
uses: ariga/setup-atlas@master
Expand Down Expand Up @@ -75,7 +77,9 @@ jobs:
deno-version: '1.45.2'

- name: Install sqruff
uses: quarylabs/install-sqruff-cli-action@main
uses: ./.github/actions/setup-sqruff
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Atlas
uses: ariga/setup-atlas@master
Expand Down
52 changes: 33 additions & 19 deletions apps/demo/PLAUSIBLE_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This guide walks you through setting up Plausible Analytics with a Cloudflare Wo
## Overview

The setup consists of three parts:

1. Plausible dashboard configuration
2. Cloudflare Worker proxy deployment
3. SvelteKit app configuration
Expand Down Expand Up @@ -43,19 +44,22 @@ The setup consists of three parts:
2. Delete the default code
3. Copy the code from `cloudflare-worker-plausible-proxy.js`
4. **Update the configuration** at the top of the file:

```javascript
// Replace with your Plausible script URL from Part 1
const ProxyScript = 'https://plausible.io/js/pa-XXXXX.js';

// Customize these paths (avoid obvious names)
const ScriptName = '/metrics/script.js'; // Change to something unique
const Endpoint = '/metrics/event'; // Should match folder above
const ScriptName = '/metrics/script.js'; // Change to something unique
const Endpoint = '/metrics/event'; // Should match folder above
```

5. Click "Save and Deploy"

### Step 3: Test the Worker

1. Your worker will be available at:

```
https://your-worker-name.your-account.workers.dev
```
Expand All @@ -78,6 +82,7 @@ If your site is on Cloudflare CDN, you can run the proxy as a subdirectory:
4. Click "Save"

Now your proxy will be available at:

```
https://yourdomain.com/analytics/metrics/script.js
https://yourdomain.com/analytics/metrics/event
Expand All @@ -91,24 +96,25 @@ Open `apps/demo/src/routes/+layout.svelte` and update the TODO section:

```typescript
onMount(() => {
initPlausible({
domain: 'demo.pgflow.dev', // Your actual domain
apiHost: 'https://your-worker.workers.dev/metrics', // Your proxy URL
trackLocalhost: false // Set to true for testing locally
});
initPlausible({
domain: 'demo.pgflow.dev', // Your actual domain
apiHost: 'https://your-worker.workers.dev/metrics', // Your proxy URL
trackLocalhost: false // Set to true for testing locally
});
});
```

**Configuration options:**

- **Without custom route** (worker URL):

```typescript
apiHost: 'https://your-worker-name.your-account.workers.dev/metrics'
apiHost: 'https://your-worker-name.your-account.workers.dev/metrics';
```

- **With custom route** (subdirectory):
```typescript
apiHost: '/analytics/metrics' // Relative path works!
apiHost: '/analytics/metrics'; // Relative path works!
```

## Part 4: Track Custom Events
Expand All @@ -123,19 +129,23 @@ track('button_clicked');

// Event with properties
track('signup', {
tier: 'pro',
plan: 'monthly',
source: 'landing_page'
tier: 'pro',
plan: 'monthly',
source: 'landing_page'
});

// Event with revenue tracking
track('purchase', {
product: 'pro-plan',
quantity: 1
}, {
amount: 29.99,
currency: 'USD'
});
track(
'purchase',
{
product: 'pro-plan',
quantity: 1
},
{
amount: 29.99,
currency: 'USD'
}
);
```

### Common Event Examples
Expand All @@ -158,11 +168,13 @@ track('documentation_download', { doc_type: 'api_reference' });
## Part 5: Verify Installation

1. **Start your dev server**:

```bash
pnpm nx dev demo
```

2. **Open your browser console** and look for:

```
[Plausible] Initialized successfully
```
Expand All @@ -173,10 +185,12 @@ track('documentation_download', { doc_type: 'api_reference' });
- Note: It may take a few seconds for events to appear

4. **Test custom events**:

```typescript
// In browser console or your code
track('test_event', { test: true });
```

- Check Plausible dashboard > Custom Events to see it

## Troubleshooting
Expand Down
42 changes: 21 additions & 21 deletions apps/demo/cloudflare-worker-plausible-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// CONFIGURATION - UPDATE THIS VALUE!
// Get this from your Plausible dashboard (Site Settings > Site Installation)
// It will look like: https://plausible.io/js/script.js (or pa-XXXXX.js for custom domains)
const ProxyScript = 'https://plausible.io/js/script.js'; // ← UPDATE THIS!
const ProxyScript = 'https://plausible.io/js/script.js'; // ← UPDATE THIS!

// Customize these paths to avoid ad-blocker detection
const ScriptName = '/stats/script.js';
Expand All @@ -18,34 +18,34 @@ const Endpoint = '/stats/event';
const ScriptWithoutExtension = ScriptName.replace('.js', '');

addEventListener('fetch', (event) => {
event.passThroughOnException();
event.respondWith(handleRequest(event));
event.passThroughOnException();
event.respondWith(handleRequest(event));
});

async function handleRequest(event) {
const pathname = new URL(event.request.url).pathname;
const [baseUri, ...extensions] = pathname.split('.');
const pathname = new URL(event.request.url).pathname;
const [baseUri] = pathname.split('.');

if (baseUri.endsWith(ScriptWithoutExtension)) {
return getScript(event, extensions);
} else if (pathname.endsWith(Endpoint)) {
return postData(event);
}
if (baseUri.endsWith(ScriptWithoutExtension)) {
return getScript(event);
} else if (pathname.endsWith(Endpoint)) {
return postData(event);
}

return new Response(null, { status: 404 });
return new Response(null, { status: 404 });
}

async function getScript(event, extensions) {
let response = await caches.default.match(event.request);
if (!response) {
response = await fetch(ProxyScript);
event.waitUntil(caches.default.put(event.request, response.clone()));
}
return response;
async function getScript(event) {
let response = await caches.default.match(event.request);
if (!response) {
response = await fetch(ProxyScript);
event.waitUntil(caches.default.put(event.request, response.clone()));
}
return response;
}

async function postData(event) {
const request = new Request(event.request);
request.headers.delete('cookie');
return await fetch('https://plausible.io/api/event', request);
const request = new Request(event.request);
request.headers.delete('cookie');
return await fetch('https://plausible.io/api/event', request);
}
1 change: 0 additions & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"dependencies": {
"@pgflow/client": "workspace:*",
"@pgflow/dsl": "workspace:*",
"@plausible-analytics/tracker": "^0.4.4",
"@supabase/supabase-js": "^2.78.0",
"@xyflow/svelte": "^1.4.1",
"shiki": "^3.14.0"
Expand Down
Loading
Loading