
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
react-metrics-service
Advanced tools
React adapter for metrics services like Google Analytics, Tealium or Comcast.
React adapter for metrics services like Google Analytics, Tealium or Comcast.
First create your metrics-service module (eg. using google analytics) in the file my-metrics.js
:
// my-metrics.js
import { createClient, googleAnalytics } from 'react-metrics-service'
const client = createClient()
client.addDispatcher(googleAnalytics({ trackingID: 'UA-000000-01' }))
export default client
You can create your own metrics-service module, check some examples in src/dispatchers
Use the service directly like:
import myClient from 'my-metrics'
export default () => {
// ...
myClient.callDispatchers('gaSend', 'event', 'Video', 'play')
// ...
}
With Proxy support you can also write:
import myClient from 'my-metrics'
export default () => {
// ...
myClient.gaSend('event', 'Video', 'play')
// ...
}
Add metricsServiceContext
high order component to your app root component:
import { metricsServiceContext } from 'react-metrics-service'
import myClient from 'my-metrics'
const App = (
// ... your app here
)
export default metricsServiceContext({ client: myClient })(App)
Then you can use the withMetricsServiceClient
HOC:
import { withMetricsServiceClient } from 'react-metrics-service'
const Component = ({
metricsServiceClient
}) => {
// ...
metricsServiceClient.gaSend('event', 'Video', 'play')
// ...
}
export default withMetricsServiceClient()(Component)
Or the metricsServiceClick
HOC:
import { metricsServiceClick } from 'react-metrics-service'
import MyComponent from 'my-component.js'
export default metricsServiceClick('gaSend', 'event', 'Video', 'play')(MyComponent)
import {
createClient,
googleAnalytics,
googleAnalyticsLegacy,
googleTagManager,
tealium,
debugLog
} from 'react-metrics-service'
const client = createClient()
client.addDispatcher(googleAnalytics({ trackingID: 'UA-000000-01' }))
client.addDispatcher(googleAnalyticsLegacy({ trackingID: 'UA-000000-01' }))
client.addDispatcher(googleTagManager({ containerID: 'GTM-0000', dataLayer: {} }))
client.addDispatcher(tealium({ account: 'acc', profile: 'pro', env: 'dev', utag_data: {} }))
client.addDispatcher(debugLog)
First of all, thank you for wanting to help!
git checkout -b more_magic
npm test
git commit -am "Added more magic"
git push origin more_magic
FAQs
React adapter for metrics services like Google Analytics, Tealium or Comcast.
The npm package react-metrics-service receives a total of 0 weekly downloads. As such, react-metrics-service popularity was classified as not popular.
We found that react-metrics-service demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.