Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@devboldly/react-use-google-analytics-embed-api

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devboldly/react-use-google-analytics-embed-api - npm Package Compare versions

Comparing version 0.0.28 to 0.0.29

5

dist/hooks/useAuthorize.d.ts
import { GoogleAnalyticsEmbedAPILoader } from './useAnalyticsApi';
/**
* See: https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth-options
*/
export interface AuthorizeOptions {

@@ -26,2 +29,2 @@ /** The client ID of your project in the [developers console](https://console.developers.google.com/project). */

}
export declare const useAuthorize: (gapiLoader: GoogleAnalyticsEmbedAPILoader, options: AuthorizeOptions, onSignIn?: (() => void) | undefined) => boolean;
export declare const useAuthorize: (gapiLoader: GoogleAnalyticsEmbedAPILoader, options: AuthorizeOptions, onSignIn?: (() => void) | undefined) => [boolean, boolean];

53

dist/hooks/useAuthorize.js
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -18,34 +29,26 @@ if (mod && mod.__esModule) return mod;

exports.useAuthorize = function (gapiLoader, options, onSignIn) {
var refreshedRequiredKeyName = 'refreshRequired';
// This hook will pull the global value from the previous render only.
// This is important because we can only call Google's authorize()
// function once. After that, it refuses to populate the container it's given. :(
// So on the second render and after, we want to indicate that a refresh is required.
var _a = react_use_window_global_1.useWindowGlobal(global_namespace_1.default, refreshedRequiredKeyName, false), refreshRequired = _a[1];
var _a = react_use_window_global_1.useWindowGlobal(global_namespace_1.default, 'authorizeCalled', false), authorizedCalledLoading = _a[0], authorizedCalled = _a[1], setAuthorizeCalled = _a[2];
var _b = react_use_window_global_1.useWindowGlobal(global_namespace_1.default, useAnalyticsApi_1.authorizedKeyName, false), authorized = _b[1], setAuthorized = _b[2];
React.useEffect(function () {
var signInHandler = function () {
if (!authorized) {
setAuthorized(true);
}
if (typeof onSignIn !== 'undefined') {
onSignIn();
}
};
var win = window;
// If a refresh isn't required (since authorize can only be called once)
if (!win[global_namespace_1.default][refreshedRequiredKeyName]) {
if (!authorizedCalledLoading && !authorizedCalled) {
var signInHandler = function () {
if (!authorized) {
setAuthorized(true);
}
if (typeof onSignIn !== 'undefined') {
onSignIn();
}
};
if (gapiLoader.ready && gapiLoader.gapi) {
gapiLoader.gapi.analytics.auth.on('signIn', signInHandler);
gapiLoader.gapi.analytics.auth.authorize({
container: options.container,
clientid: options.clientId,
});
// Set this directly to prevent a rerender.
// Authorize can only be called once so we need to track whether a refresh is required.
win[global_namespace_1.default][refreshedRequiredKeyName] = true;
gapiLoader.gapi.analytics.auth.authorize(__assign({
// There seems to be a typo in the official spec docs (clientId vs clientid)
clientid: options.clientId }, options));
setAuthorizeCalled(true);
}
}
});
return !!refreshRequired;
var loading = authorizedCalledLoading;
var called = !!authorizedCalled;
return [loading, called];
};
{
"name": "@devboldly/react-use-google-analytics-embed-api",
"version": "0.0.28",
"version": "0.0.29",
"author": "Dev Boldly <devboldly@gmail.com>",

@@ -5,0 +5,0 @@ "description": "React hook to async load the Google Analytics Embed API.",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc