milesmcc / shynet

Modern, privacy-friendly, and detailed web analytics that works without cookies or JS.
Apache License 2.0
2.94k stars 192 forks source link

Primary-Key Integration with a Single-Page Application #86

Open NeilSeligmann opened 4 years ago

NeilSeligmann commented 4 years ago

I'm currently using Shynet with a single-page Vue.js client-side app. Currently there is a callable method so that Shynet knows when a new page has been loaded Shynet.newPageLoad().

But there currently is no way (at least that I could find) to indicate an update/change to the primaryKey, maybe a new method could be used, like Shynet.setPrimaryKey('primary-key-goes-here')

Being a single-page client-side app, the whole app is first loaded in the client and then all the events of authentication happen. Therefore it's not possible to initialize the script with the user primary key.

Love the simplicity and ease of use of Shynet, if this feature was added I could use it exclusively on all my projects 😃

milesmcc commented 4 years ago

Interesting—I could imagine this being a good way to interface with the API. That said, it probably is possible to include primary key integration with your SPA without this API. Is it possible to load the <script> tag from a variable URL?

NeilSeligmann commented 4 years ago

Thanks for the quick reply! Hadn't though of that 😅, I'm currently modifying my project so that the Shynet script tag initializes via JavaScript (once the user is logged in) and see if that works.

NeilSeligmann commented 4 years ago

Testing the idea out I realized the following. Even if I can set the initial primary key, if the current user were to log out and then log in with another account the primary key would still be that of the previous account.

The only solution I can think of is to destroy the Shynet instance and create a new one with the new key.