Help Needed: Execute javascript for not logged in users

Unsolved Technical Support
  • #1

    I would like to add/execute ad serving javascript (google adsense) only for users who are not logged in.

    I installed the nodebb adsense plugin, but it is not configurable to detect whether users are logged in or not. So I am thinking about just adding the code block for google adsense via custom header and wrapping it in some javascript, so it's not executed when a user is loggedin. Help is appreciated.

  • #2

    @rspk you could use a widget for this and target it to only guests ? I do something similar on my own site but instead have a welcome banner encouraging users to register - example at https://phenomlab.com

  • #3

    @phenomlab Thanks, do you use HTML widget? ! I will try that and see if Google adsense does not mind not being inside the head tag.

  • #4

    @rspk yes, sorry. Forgot that part 🤭

  • #5

    @phenomlab it seems like it kind of works, but the ads are intermittently showing and only on the front page, although I put the widget in the global header. My guess as it's something related to the google adsense code not being inside the head tag. I will keep exploring the option of using custom header and try to figure out how to detect the guest users in javascript.


Suggested Topics


| | | |