Skip to content

Instantly share code, notes, and snippets.

View Kugelschieber's full-sized avatar
💭
Working on Pirsch

Marvin Blum Kugelschieber

💭
Working on Pirsch
View GitHub Profile
@Kugelschieber
Kugelschieber / copy_gcs_bucket_to_minio.go
Last active December 22, 2019 13:03
This little Go application will copy everything from one Google Cloud Storage Bucket to a MinIO Bucket. You'll need a GCS credentials file and a MinIO access key + secret.
package main
import (
"cloud.google.com/go/storage"
"context"
"github.com/minio/minio-go"
"google.golang.org/api/iterator"
"log"
"os"
)
@Kugelschieber
Kugelschieber / golang_timer_example.go
Created January 25, 2021 18:42
Example for running a timed function call in Golang without leaking the goroutine
package main
import (
"context"
"fmt"
"log"
"time"
)
func runTimed(tick time.Duration, f func()) context.CancelFunc {
@Kugelschieber
Kugelschieber / pirsch-get-domain.js
Last active February 18, 2022 12:53
List the Pirsch client domain.
var { Client } = require("pirsch-sdk");
var client = new Client({
hostname: "your-domain", // don't forget to set these!
clientID: "your-client-id",
clientSecret: "your-client-secret"
});
client.domain()
.then(d => {
(function() {
"use strict";
if(navigator.doNotTrack === "1" || localStorage.getItem("disable_pirsch")) {
return;
}
const script = document.querySelector("#pirschjs");
const endpoint = script.getAttribute("data-endpoint") || "https://api.pirsch.io/hit";
const identificationCode = script.getAttribute("data-code");
(function() {
"use strict";
window.pirsch = (name, options) => {
console.log(`Pirsch event: ${name}${options ? " "+JSON.stringify(options) : ""}`);
return Promise.resolve(null);
};
if(navigator.doNotTrack === "1" || localStorage.getItem("disable_pirsch")) {
return;
@Kugelschieber
Kugelschieber / pirsch-no-script-tag.js
Created September 17, 2022 10:40
A custom pirsch.js without the requirement for a script tag in the header section.
(function () {
"use strict";
// The identification code for your website from the settings page.
// Required.
const identificationCode = "";
// A comma-separated list of path patterns (regular expressions) to include.
// Optional.
const includePaths = "";
@Kugelschieber
Kugelschieber / Caddyfile
Last active October 5, 2022 14:12
Pirsch Go Proxy Setup
# Uncomment everything not specified here and change the domain.
proxy.yourdomain.com:443 {
reverse_proxy localhost:8080
}

Pirsch reading statistics example using the API

Step 0

Create a client ID and secret on the developer settings page and save the secret for later use.

Step 1

Get a temporary access token.

@Kugelschieber
Kugelschieber / otto-test.go
Created January 25, 2023 15:35
Otto JS Test in Go
package main
import (
"log"
"time"
"github.com/robertkrimen/otto"
)
const (
@Kugelschieber
Kugelschieber / pirsch-api.md
Last active April 12, 2024 11:58
Sending a Page View to Pirsch Using the API

Getting an Access Token

This step is only required if you use a client ID + secret. A single access key allows you to skip the step, but it cannot be used to read statistics as with the other method. For write-only clients, we recommend using an access key.

Replace the CLIENT_ID and CLIENT_SECRET in the body. The access token in the response will be valid for 15 minutes.

curl --location --request POST 'https://api.pirsch.io/api/v1/token' \
--header 'Content-Type: application/json' \
--data-raw '{