stayallive / wp-sentry

A (unofficial) WordPress plugin reporting PHP and JavaScript errors to Sentry.
https://wordpress.org/plugins/wp-sentry-integration/
MIT License
300 stars 48 forks source link

Sentry object is not available on pages #151

Closed vvvhung closed 1 year ago

vvvhung commented 1 year ago

After all settings, I can find the Sentry object (via the browser's console) on the WordPress dashboard page. But I can not find Sentry on my homepage. It shows: ReferenceError: Can't find variable: Sentry. Is there anything missing that can cause that issue?

stayallive commented 1 year ago

It's possible that the theme is incorrectly rendering the scripts or they are being blocked and or grouped by optimizer plugins, you should see something like the following on your page source:

<script src='https://YOUR_DOMAIN/wp-content/plugins/wp-sentry/public/wp-sentry-browser.min.js?ver=6.8.0' id='wp-sentry-browser-js'></script>

Do you have any optimization plugins like WP Rocket, W3 cache or others active?

vvvhung commented 1 year ago

No, I don't have optimization plugins. As I mention, I can find the script on the WP dashboard when I login, but I can not find it on the homepage: https://elsaspeak.com/en/.

stayallive commented 1 year ago

I am seeing no scripts or stylesheets loaded from any WordPress plugin or theme in the section of that page at all, so that is probably the issue that the theme is probably missing some code to render the styles/scripts in the section.

vvvhung commented 1 year ago

@stayallive yeah, it may be the cause. But I wonder what is the auto-mechanism that WP-Sentry rely on to be render to the theme page? Or do I need to add the script file manually?

Sorry if I bother you with my own theme issues.

stayallive commented 1 year ago

We use wp_enqueue_script: https://github.com/stayallive/wp-sentry/blob/ba2cf8f106e0b139e646d2a9be490b54f7c80bbb/src/class-wp-sentry-js-tracker.php#L184-L189.

This is a core part of WordPress that allows plugins and themes to add scripts and styles to the header or footer of a site. See the developer documentation on this: https://developer.wordpress.org/themes/basics/including-css-javascript/.

Depending on if you are building a classic or block theme there are ways for you to render these enqueued scripts and styles.

vvvhung commented 1 year ago

@stayallive Yeah, thanks. You are correct, my theme does not call wp_head() so wp_enqueue_scripts() was not called. I will close this issue.