Created
April 19, 2021 23:25
-
-
Save bryanp/12f04f7ba096b4ee7551fc61352cf006 to your computer and use it in GitHub Desktop.
Proc Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pw.define("analytics", { | |
authorization: null, | |
constructor() { | |
window.fetch(this.config.authorization + `?authenticity=${this.config.authenticity}`).then(async (response) => { | |
if (response.status === 200) { | |
let payload = await response.json(); | |
this.authorization = payload.authorization; | |
const Proc = await import("https://cdn.skypack.dev/pin/@proc.dev/[email protected]/mode=imports,min/optimized/@proc.dev/client.js"); | |
this.client = Proc.connect(this.authorization); | |
this.client.self.analytics.track.call({}, { | |
environment: this.config.environment, | |
identifier: this.config.identifier, | |
payload: { | |
id: this.config.identifier, | |
path: window.location.pathname, | |
query: window.location.search | |
} | |
}); | |
} else { | |
// error | |
} | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "proc" | |
client = Proc.connect("...") | |
date = client["time.now"] >> client["time.format"].with( | |
string: "%Y-%m-%d:%H" | |
) | |
bucket = client["type.array.append"].with( | |
["analytics"], value: :environment | |
) >> client["type.array.join"].with( | |
separator: ":" | |
) | |
key = client["type.array.append"].with( | |
[], value: date | |
) >> client["type.array.append"].with( | |
value: :identifier | |
) >> client["type.array.join"].with( | |
separator: ":" | |
) | |
payload = client["type.hash.set"].with( | |
:payload, key: "time", value: client["time.now"] | |
) | |
track = client["keyv.transform"].with(bucket: bucket, key: key, set: []) { | |
client["type.array.append"].with(value: payload) | |
} | |
client["proc.update"].call(name: "analytics.track", proc: track.with(:payload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment