posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

feat(toolbar): posthog.loadToolbar({ temporaryToken: 'key' })

Open mariusandra opened this issue 3 years ago • 1 comments

Changes

Implements

window.posthog.loadToolbar({ temporaryToken: 'key' })

With the aim to

  1. provide an alternative to the #__posthog={state} url hash method to load the toolbar
  2. provide users a way to capture the hash themselves in their single page app, and pass it on to posthog

Other params to temporaryToken, if provided, are passed on to the toolbar as well. Ideally they are not needed.

This PR also renames some old Editor identifiers into Toolbar, to better reflect our product. In a backwards compatible way 🤞.

There will be a follow up PR to the main repo with the some other improvements.

Checklist

mariusandra avatar Oct 20 '22 10:10 mariusandra

I added one more feature, a source param that gets passed to posthog's toolbar. This will either be "url", "localstorage" or undefined, depending if the toolbar was loaded from the URL, from localstorage, or from any random loadToolbar call that didn't specify this further.

This way, when trying to make posthog.loadToolbar() work, I can avoid showing a big "token expired" warning to users whose tokens genuinely expire when they visit their own website 2 days later. No need to show a cryptic warning then.

EDIT: after 3 extra commits, ready for a look.

mariusandra avatar Oct 20 '22 11:10 mariusandra