@devboldly/react-use-google-analytics-embed-api
Advanced tools
Comparing version 0.0.31 to 0.0.32
@@ -1,2 +0,2 @@ | ||
import { GoogleAnalyticsEmbedAPILoader } from './useAnalyticsApi'; | ||
import { GoogleAnalyticsEmbedAPI } from './GoogleAnalyticsEmbedAPI'; | ||
/** | ||
@@ -29,2 +29,2 @@ * See: https://developers.google.com/analytics/devguides/reporting/embed/v1/component-reference#auth-options | ||
} | ||
export declare const useAuthorize: (gapiLoader: GoogleAnalyticsEmbedAPILoader, options: AuthorizeOptions, onSignIn?: (() => void) | undefined) => [boolean, boolean]; | ||
export declare const useAuthorize: (gapi: GoogleAnalyticsEmbedAPI | undefined, options: AuthorizeOptions, onSignIn?: (() => void) | undefined) => [boolean, boolean]; |
@@ -28,7 +28,7 @@ "use strict"; | ||
var useAnalyticsApi_1 = require("./useAnalyticsApi"); | ||
exports.useAuthorize = function (gapiLoader, options, onSignIn) { | ||
exports.useAuthorize = function (gapi, options, onSignIn) { | ||
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 () { | ||
if (!authorizedCalledLoading && !authorizedCalled) { | ||
if (!authorizedCalledLoading && !authorizedCalled && typeof gapi !== 'undefined') { | ||
var signInHandler = function () { | ||
@@ -42,9 +42,7 @@ if (!authorized) { | ||
}; | ||
if (gapiLoader.ready && gapiLoader.gapi) { | ||
gapiLoader.gapi.analytics.auth.on('signIn', signInHandler); | ||
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); | ||
} | ||
gapi.analytics.auth.on('signIn', signInHandler); | ||
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); | ||
} | ||
@@ -51,0 +49,0 @@ }); |
@@ -9,2 +9,2 @@ import { GoogleAnalyticsEmbedAPI } from './GoogleAnalyticsEmbedAPI'; | ||
*/ | ||
export declare const useDataChart: (gapi: GoogleAnalyticsEmbedAPI, query: any, chart: any) => void; | ||
export declare const useDataChart: (gapi: GoogleAnalyticsEmbedAPI | undefined, query: any, chart: any) => void; |
@@ -21,3 +21,3 @@ "use strict"; | ||
React.useEffect(function () { | ||
if (gapi) { | ||
if (typeof gapi !== 'undefined') { | ||
if (!dataChart) { | ||
@@ -24,0 +24,0 @@ if (query.ids) { |
@@ -1,2 +0,2 @@ | ||
import { GoogleAnalyticsEmbedAPILoader } from './useAnalyticsApi'; | ||
export declare const useViewSelector: (gapiLoader: GoogleAnalyticsEmbedAPILoader, viewSelectorId: string, onChange: (viewId: string) => void) => void; | ||
import { GoogleAnalyticsEmbedAPI } from './GoogleAnalyticsEmbedAPI'; | ||
export declare const useViewSelector: (gapi: GoogleAnalyticsEmbedAPI | undefined, viewSelectorId: string, onChange: (viewId: string) => void) => void; |
@@ -11,31 +11,29 @@ "use strict"; | ||
var React = __importStar(require("react")); | ||
exports.useViewSelector = function (gapiLoader, viewSelectorId, onChange) { | ||
exports.useViewSelector = function (gapi, viewSelectorId, onChange) { | ||
var _a = React.useState(), viewSelector = _a[0], setViewSelector = _a[1]; | ||
React.useEffect(function () { | ||
if (!viewSelector) { | ||
if (gapiLoader.ready && gapiLoader.gapi) { | ||
try { | ||
/** | ||
* Create a new ViewSelector instance to be rendered inside of an | ||
* element with the id provided. | ||
*/ | ||
var newViewSelector = new gapiLoader.gapi.analytics.ViewSelector({ | ||
container: viewSelectorId, | ||
}); | ||
// Render the view selector to the page. | ||
newViewSelector.execute(); | ||
/** | ||
* Render the dataChart on the page whenever a new view is selected. | ||
*/ | ||
newViewSelector.on('change', function (viewId) { | ||
onChange(viewId); | ||
}); | ||
setViewSelector(newViewSelector); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
if (!viewSelector && typeof gapi !== 'undefined') { | ||
try { | ||
/** | ||
* Create a new ViewSelector instance to be rendered inside of an | ||
* element with the id provided. | ||
*/ | ||
var newViewSelector = new gapi.analytics.ViewSelector({ | ||
container: viewSelectorId, | ||
}); | ||
// Render the view selector to the page. | ||
newViewSelector.execute(); | ||
/** | ||
* Render the dataChart on the page whenever a new view is selected. | ||
*/ | ||
newViewSelector.on('change', function (viewId) { | ||
onChange(viewId); | ||
}); | ||
setViewSelector(newViewSelector); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
} | ||
} | ||
}, [viewSelector, gapiLoader.gapi, gapiLoader.ready, viewSelectorId, onChange]); | ||
}, [viewSelector, viewSelectorId, onChange, gapi]); | ||
}; |
{ | ||
"name": "@devboldly/react-use-google-analytics-embed-api", | ||
"version": "0.0.31", | ||
"version": "0.0.32", | ||
"author": "Dev Boldly <devboldly@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "React hook for loading the Google Analytics Embed API.", |
90103
2015