Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
@analytics/perfumejs
Advanced tools
Send browser performance metrics to third-party analytics providers
analytics
Send performance metrics to any analytics provider using perfume.js.
Perfume is a tiny, web performance monitoring library that reports field data back to your favorite analytics tool.
Using perfume.js with analytics
makes wiring up your performances metrics to any third-party analytics tool nice & easy.
npm install analytics
npm install @analytics/perfumejs
npm install perfume.js
The @analytics/perfumejs
package works in the browser to collect and send performance data to any third party analytics tool.
To use, install the package, include in your project and initialize the plugin with analytics.
By default, the perfume.js plugin will send performance metrics to all analytics plugins attached to analytics
. You can customize this & disable specific providers with the optional destinations
config setting.
Below is an example of how to use the browser plugin.
import Analytics from 'analytics'
import customerIOPlugin from '@analytics/customerio'
import googleAnalytics from '@analytics/google-analytics'
import hubSpotPlugin from '@analytics/hubspot'
// Include perfume.js analytics plugin
import perfumePlugin from '@analytics/perfumejs'
// Include perfume.js library
import Perfume from 'perfume.js'
const analytics = Analytics({
app: 'my-app',
plugins: [
// Attach Google analytics
googleAnalytics({
trackingId: 'UA-12341131-6',
instanceName: 'two'
})
// Attach Hubspot analytics
hubSpotPlugin({
portalId: '234576'
}),
// Attach Customer.io analytics
customerIOPlugin({
siteId: '123-xyz'
})
/* Include perfume.js plugin */
perfumePlugin({
// Perfume.js class. If empty, window.Perfume will be used.
perfume: Perfume,
// Analytics providers to send performance data.
destinations: {
// perf data will sent to Google Analytics
'google-analytics': true,
// perf data will sent to Customer.io
'customerio': true,
// perf will NOT be sent to HubSpot
'hubspot': false
},
}),
]
})
/* Perfume.js will now automatically sent performance data
to Google Analytics and Customer.io 🎉 */
See additional implementation examples for more details on using in your project.
Option | description |
---|---|
perfume optional - object | perfume.js class. If not provided, a global window reference to Perfume will be used |
destinations optional - object | Where perfume.js will send performance data |
category optional - string | Name of event category. Default 'perfume.js' |
perfumeOptions optional - object | Options to pass to perfume.js instance. See https://github.com/Zizzamia/perfume.js#perfume-custom-options |
For more in how destinations
option works, see sending provider-specific events docs
.
perfumePlugin({
perfume: Perfume,
destinations: { all: true } // <-- default value to send to all plugins
})
Disable all and only send to specific plugins
perfumePlugin({
perfume: Perfume,
destinations: {
all: false,
'hubspot': true, // <--- these are the plugin 'name' properties
'google-analytics': true // <--- these are the plugin 'name' properties
}
})
Below are additional implementation examples.
Below is an example of importing via the unpkg CDN. Please note this will pull in the latest version of the package.
<!DOCTYPE html>
<html>
<head>
<title>Using @analytics/perfumejs in HTML</title>
<script src="https://unpkg.com/analytics/dist/analytics.min.js"></script>
<script src="https://unpkg.com/perfume.js"></script>
<script src="https://unpkg.com/@analytics/perfumejs/dist/@analytics/perfumejs.min.js"></script>
<script type="text/javascript">
/* Initialize analytics */
var Analytics = _analytics.init({
app: 'my-app-name',
plugins: [
analyticsPerfumeJs({
perfume: Perfume,
category: 'perfMetrics'
})
]
})
</script>
</head>
<body>
....
</body>
</html>
Using @analytics/perfumejs
in ESM modules.
<!DOCTYPE html>
<html>
<head>
<title>Using @analytics/perfumejs in HTML via ESModules</title>
<script>
// Polyfill process.
// **Note**: Because `import`s are hoisted, we need a separate, prior <script> block.
window.process = window.process || { env: { NODE_ENV: 'production' } }
</script>
<script type="module">
import analytics from 'https://unpkg.com/analytics/lib/analytics.browser.es.js?module'
import Perfume from 'https://unpkg.com/perfume.js?module'
import analyticsPerfumeJs from 'https://unpkg.com/@analytics/perfumejs/lib/analytics-plugin-perfumejs.browser.es.js?module'
/* Initialize analytics */
const Analytics = analytics({
app: 'analytics-html-demo',
debug: true,
plugins: [
analyticsPerfumeJs({
perfume: Perfume,
category: 'perfMetrics'
})
// ... add any other third party analytics plugins
]
})
</script>
</head>
<body>
....
</body>
</html>
For ease of use, there is a "zero-config" option where you only need to pass in the Perfume
class to the analytics plugin. This will automatically send all performance metrics to all attached analytic plugins.
import Analytics from 'analytics'
import googleAnalytics from '@analytics/google-analytics'
import hubSpotPlugin from '@analytics/hubspot'
import perfumePlugin from '@analytics/perfumejs'
import Perfume from 'perfume.js'
const analytics = Analytics({
app: 'my-app',
plugins: [
// Attach Google analytics
googleAnalytics({
trackingId: 'UA-12341131-6',
instanceName: 'two'
})
// Attach Hubspot analytics
hubSpotPlugin({
portalId: '234576'
}),
// Include perfume.js plugin with no options set.
// This will send data to all analytics providers by default
perfumePlugin(Perfume),
]
})
FAQs
Send browser performance metrics to third-party analytics providers
The npm package @analytics/perfumejs receives a total of 677 weekly downloads. As such, @analytics/perfumejs popularity was classified as not popular.
We found that @analytics/perfumejs 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
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.