How can I disable some scripts for admin users

So I am using Google analytics, I’ve installed the code via the admin area. Is there any way that the scripts don’t get loaded up if the admin user is logged in? Will the below code do the job or I have to use any other code?

{{^if @member}}
  // google analytics code

So I have added google analytics code via insert footer menu, I want not to run these scripts for the staff users, Is there a way how can I achive it?

There’s no way inside of a Ghost theme, the Staff User system used for the admin area is completely separate to facilitate caching and improve security.

The best route is to use the internal traffic filtering options google analytics gives you.

If you can’t use those, you may be able to use some client-side scripts to query the Admin API to detect if an admin session cookie exists and only inject the script when there’s no session but it’s not optimal, it will slow down the script insertion and it’s not foolproof due to browser’s privacy mechanisms blocking cross-site request cookies. There’s some old discussion for how to do that in this topic:

1 Like