Skip to content
🦋

Limit user tracking in a Laravel Spark application

Heads up: this post is a bit old. Caveat emptor.

Laravel Spark comes with a really handy feature: user impersonation. The “kiosk” allows you to search for users of your application, and click a button to sign in as that user. This is great for things like white-glove onboarding, recording screencasts for a user to show them a feature, etc.

It’s quite common to use something like Intercom, FullStory, etc. to track users in your application. You might want to keep tabs on how often they log in, what actions they take, and so on. But, if you use that impersonation feature, you’ll trigger that tracking for a user’s account when they aren’t actually using the app! And, you probably don’t care about using something like FullStory to track your own usage of the app.

I wanted a way to avoid this problem, and after some digging, I discovered that Spark sets a spark:impersonator session key when using the impersonation feature. As a result, we can check for that in our app’s app.blade.php layout file, and conditionally set a javascript variable:

We can then check for that variable in our javascript, and skip user tracking if it’s present.

Revisions