Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
@devboldly/react-use-google-analytics-embed-api
Advanced tools
React hook for loading the Google Analytics Embed API.
Read the official documentation.
The useAnalyticsApi
hook can be used to load and ready the Google Analytics Embed API in React.
What is the Google Analytics Embed API? It's is a JavaScript library that allows you to easily create and embed Google Analytics charts on a third-party website in a matter of minutes.
This library also provides a few helper hooks for common operations via the API:
Looking for components? A full React component library that wraps these hooks is now available! Check out React Analytics Charts.
window
dependence
window
, but this hook pulls the API into a singleton to limit window
dependence.npm i @devboldly/react-use-analytics-api
To load the Google Analytics Embed API, use the useAnalyticsApi
hook:
import { useAnalyticsApi } from '@devboldly/react-use-analytics-api';
Then in your function component:
const { ready, gapi, authorized, error } = useAnalyticsApi();
When ready
is true
, the gapi
object will be set to the loaded and ready-to-use Google Analytics Embed API. The gapi
object will be undefined
until it is ready to use.
The authorized
property will be true
when the user is authorized, false
otherwise.
From here, you can authorize the user, render a view selector, and render charts... or do anything else you want with the API!
🏁 For a live example demonstrating all features of this library including full auth flow, see the useDataChart example. This is a great starting point for building your own charts dashboard.
Type definitions have been included for TypeScript support.
Open source software is awesome and so are you. 😎
Feel free to submit a pull request for bugs or additions, and make sure to update tests as appropriate. Even the smallest changes help.
For major changes, open an issue first to discuss what you'd like to change.
More stars means more development love. So if you found this project helpful, star it! 👉⭐
FAQs
React hook for loading the Google Analytics Embed API.
We found that @devboldly/react-use-google-analytics-embed-api 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
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.