npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

google-analytics-embed-react

v0.0.3

Published

Bringing the Google Analytics Embed Components for your ReactJS application

Readme

google-analytics-embed-react

Bringing the Google Analytics Embed Components for your ReactJS admin panels.

Installation

npm install google-analytics-embed-react

Usage

You need to wrap your entire app with the GoogleAnalyitcsProvider component as the first step to use this library. This component will take the accessToken as the only mandatory prop. But it is also optional :smiley:. It means you do not need the accessToken in first rendering time. But you have to pass it later to display your graphs.

<GoogleAnalyticsProvider accessToken={myAccessToken}>
  {/* Your application components */}
</GoogleAnalyticsProvider>

Then render any chart component in your application.

<GoogleAnalyticsPieChart
    query={{
      ids, // <-- Replace with the ids value for your view.
      'start-date': '90daysAgo',
      'end-date': 'today',
      metrics:
        'ga:pageviews,ga:uniquePageviews,ga:timeOnPage,ga:bounces,ga:entrances,ga:exits',
      sort: '-ga:pageviews',
      dimensions: 'ga:pagePath',
      'max-results': 10
    }}
    width={500}
    style={{ float: 'left' }}
    pieHole={0.4}
  />

Component Reference

GoogleAnalyticsProvider

This component will load the Google platform script and authenticate yourself with the gapi.analytics namespace.

Props

| Name | Type | Default | Optional | Description | | ------------------------ | -------------------- | --------- | -------- | ------------------------------------------------------------------------------------- | | accessToken | string | undefined | No* | Access token to authroize the user | | onReady | callback, ()=>void | undefined | Yes | Fired once the Google platform script loaded and gapi is ready to use. | | onAuthenticated | callback, ()=>void | undefined | Yes | Fired once the Google Analytics API authenticated the access token | | scopes | array, string[] | undefined | Yes | Additional scopes to include | | overwriteDefaultScopes | boolean | false | Yes | Overwrite the scopes passed when generating the access token with the provided scopes | | children | JSX.Element | N/A | No | Child elements of the application to render inside the provider |

ViewSelector

This is the react implementation of the View Selector. Users can select their Google Analytics view from the select boxes. Then you will be notified by the onChange callback.

Props

| Name | Type | Default | Optional | Description | | ----------- | ----------------------------- | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------- | | onChange | callback, (string)=>void | undefined | Yes | Fired at the component initialization time and the user changed the view. The first argument is the view id in ga:xxxxx format. | | children | JSX.Element | undefined | Yes | An optional placeholder to show until the gapi is being ready | | style | object, React.CSSProperties | undefined | Yes | CSS styles to pass to the container element. | | className | string | undefined | Yes | Class name to pass to the container element |

DataChart

GoogleAnalyticsLineChart, GoogleAnalyticsBarChart, GoogleAnalyticsColumnChart, GoogleAnalyticsGeoChart, GoogleAnalyticsPieChart , GoogleAnalyticsTable components will help you to visualize the Google Analytics Data by using the google.visualization API. All of those components extended to the same DataChart component and the props are common for all components.

Props

| Name | Type | Default | Optional | Description | | ----------- | ------------------------------ | --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | query | object, gapi.analytics.Query | N/A | No | Refer the Google Core Reporting API for more details about the properties and filterations. | | children | JSX.Element | undefined | Yes | An optional placeholder to show until the gapi is being ready | | style | object, React.CSSProperties | undefined | Yes | CSS styles to pass to the container element. | | className | string | undefined | Yes | Class name to pass to the container element | | onSuccess | callback, (object)=>void | undefined | Yes | Fired when the chart successfully rendered and the Reporting API call success. First argument is a response object that returning from Reporting API. Check this page for more details. | | onError | callback, (object)=>void | undefined | Yes | Fired when an error occured during the rendering the chart or a error response received from the Reporting API. The first argument contains the error object. Refer this page for more details about error response object. | | . . . | object | undefined | Yes | Google Chart options depending on the chart type. Refer the Google Charts Guides to get a knowledge about options needed for different chart types. |

Data

This is the implementation for Data component. We implemented it as a helper method to fetch Reporting data manually.

fetchData(query: Query): Promise<SuccessResponse>

This method will return a Promise which resolve when the Reporting API returned a success response. And it will be rejected if the Reporting API returned an error response. This method will take a query as the only argument.