0.0.44 โ€ข Published 5 years ago

@devboldly/react-use-google-analytics-embed-api v0.0.44

Weekly downloads
44
License
MIT
Repository
github
Last release
5 years ago

Documentation

Read the official documentation.

๐Ÿ‘๏ธ Live Demo

Overview

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.

Features include:

  • ๐Ÿš€ Easily load the Google Analytics Embed API
    • Loading and readying the API is handled for you so you can just focus on the good stuff, like embedding charts.
  • ๐Ÿ“ˆ Drop in charts quickly and easily
    • Embed Google Analytics charts on your site in minutes.
  • ๐Ÿ’ From auth to charts, it's handled for you
    • Side-effects are handled for common API operations. Need to handle the auth flow, render a view selector, or render charts? Got ya covered!
  • ๐Ÿงผ Minimized window dependence
    • Google loads the API to window, but this hook pulls the API into a singleton to limit window dependence.
  • ๐Ÿค Hooks stay synchronized
    • When calling the API hook in multiple places, changes to readiness and auth will propate to all hooks, keeping them in sync.
  • โœจ Live examples and rich documentation
    • Develop easier with plenty of live examples, starting points, and rich docs.
  • And more!

Installation

npm i @devboldly/react-use-analytics-api

Quick Start

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.

TypeScript

Type definitions have been included for TypeScript support.

Contributing

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.

โญ Found It Helpful? Star It!

More stars means more development love. So if you found this project helpful, star it! ๐Ÿ‘‰โญ

0.0.44

5 years ago

0.0.43

5 years ago

0.0.42

5 years ago

0.0.41

5 years ago

0.0.40

5 years ago

0.0.39

5 years ago

0.0.37

5 years ago

0.0.38

5 years ago

0.0.36

5 years ago

0.0.35

5 years ago

0.0.34

5 years ago

0.0.33

5 years ago

0.0.32

5 years ago

0.0.30

5 years ago

0.0.31

5 years ago

0.0.26

5 years ago

0.0.27

5 years ago

0.0.28

5 years ago

0.0.29

5 years ago

0.0.25

5 years ago

0.0.24

5 years ago

0.0.23

5 years ago

0.0.22

5 years ago

0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.15

5 years ago

0.0.16

5 years ago

0.0.14

5 years ago

0.0.11

5 years ago

0.0.12

5 years ago

0.0.13

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago