Understanding Posthog
Posthog is all about product analytics.
- You install a script on your website. You can grab the script off the website (though you need your own api key) or you can grab your prefilled script off your dashboard somewhere.
- It’s probably a good idea to reverse proxy posthog to improve tracking.
- By default, PostHog captures pageview events and autocaptured events. (List here)
- You can capture additional key-value data by adding the following attribute to any element. (This will be triggered on the element or any children). See below.
<button
data-ph-capture-attribute-product-id={productId}
data-ph-capture-attribute-product-name={productName}
data-ph-capture-attribute-product-price={productPrice}
data-ph-capture-attribute-product-quantity={productQuantity}
>
Add to cart
</button>
//
properties: {
"product-id": "12345678"
"product-name": "Red t-shirt"
"product-price": "30"
"product-quantity": "1"
}
- You can prevent some sensitive data from being autocaptured by adding a class
class='ph-no-capture'
- You can configure PostHog to autocapture information that is copied from the clipboard… might be useful.
- If you have a SPA you can manually send a pageview event with the current url with
posthog.capture('$pageview')
- You can identify users by a unique id (either autogenerated or an email)
- You can set up an alias if you need multiple possible ID’s
- You can’t re-identify someone
- You can add properties to a person
$set
will set the property, with override$set_once
will set the property, without override
- Groups = aggregate events
- Cohorts = set of users with something in common
- Might set a feature flag for light or dark mode
- You can receive updates in Slack