Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
analytics-plugin-tab-events
Advanced tools
Expose tab visibility events plugin for 'analytics' module
This analytics plugin fire events on tab visibility changes. When visitors switch between browser tabs callbacks are fired.
Tab visibility changes can be useful for session information, pausing videos/carousels, and displaying calls to action when a visitor returns to a tab.
The plugin exposes tab events (tabHidden
and tabVisible
) that listeners & other plugins can react to.
This package comes with a standalone onTabChange
function for usage anywhere in your app.
Install from npm.
npm install analytics
npm install analytics-plugin-tab-events
Then initialize analytics with the plugin.
import Analytics from 'analytics'
import tabEventsPlugin from 'analytics-plugin-tab-events'
const analytics = Analytics({
app: 'my-app',
plugins: [
/* Include tab events plugin */
tabEventsPlugin,
// ...other plugins
]
})
// expose analytics instance for your app to use
export default analytics
You can listen to the tabHidden
& tabVisible
events with .on
& .once
listeners directly in your app code.
/* import analytic instance in your app code */
import analytics from '/src/analytics'
// Somewhere in your app
/* Or fire .on listeners */
analytics.on('tabHidden', () => {
// do stuff when tab hidden
})
analytics.on('tabVisible', () => {
// do stuff when tab visible
})
/* Or fire listeners just once */
analytics.once('tabHidden', () => {
// do stuff ONCE when tab hidden
})
analytics.once('tabVisible', () => {
// do stuff ONCE when tab visible
})
/* Clean up events */
const remove = analytics.on('tabHidden', () => {/* logic */})
// Call remove() to detach listener
remove()
Instead of listening inline with .on
or .once
, you can create plugins to also react to tabHidden
and tabVisible
events.
This keeps your app code nice an clean & centralizes functionality where your analytics instance is initialized.
Here is an example:
import Analytics from 'analytics'
import tabEventsPlugin from 'analytics-plugin-tab-events'
let tabInterval
/* Example plugin that listener to tab events */
const customPluginExample = {
NAMESPACE: 'custom-plugin-with-tab-listeners',
tabHidden: () => {
console.log('Tab is now hidden')
let tabHiddenCount = 0
tabInterval = setInterval(() => {
console.log(`tab counter ${tabHiddenCount++}`)
}, 500)
},
tabVisible: () => {
console.log('Tab now visible again')
clearInterval(tabInterval)
},
}
const analytics = Analytics({
app: 'my-app',
plugins: [
/* Include tab events plugin */
tabEventsPlugin,
/* Example plugin that listener to tab events */
customPluginExample,
]
})
onTabChange
This standalone onTabChange
function can imported and used by itself, without the plugin being attached to analytics
, anywhere in your application logic.
import { onTabChange } from 'analytics-plugin-tab-events'
const myListener = onTabChange((isHidden) => {
if (isHidden) {
console.log('Tab is not visible')
} else {
console.log('Welcome back tab is visible')
}
})
// Optionally remove the listener
myListener()
FAQs
Expose tab visibility events plugin for 'analytics' module
The npm package analytics-plugin-tab-events receives a total of 2,195 weekly downloads. As such, analytics-plugin-tab-events popularity was classified as popular.
We found that analytics-plugin-tab-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.