@dapperlabs/react-analytics
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,7 +0,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AnalyticsContext = void 0; | ||
const react_1 = require("react"); | ||
import { createContext } from "react"; | ||
const noop = () => { }; | ||
exports.AnalyticsContext = (0, react_1.createContext)({ | ||
export const AnalyticsContext = createContext({ | ||
analyticsReady: false, | ||
@@ -8,0 +5,0 @@ identify: noop, |
@@ -1,21 +0,5 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./context"), exports); | ||
__exportStar(require("./provider"), exports); | ||
__exportStar(require("./withAnalytics"), exports); | ||
__exportStar(require("./useAnalytics"), exports); | ||
export * from "./context"; | ||
export * from "./provider"; | ||
export * from "./withAnalytics"; | ||
export * from "./useAnalytics"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,33 +0,7 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AnalyticsProvider = void 0; | ||
const analytics_next_1 = require("@segment/analytics-next"); | ||
const react_1 = __importStar(require("react")); | ||
const context_1 = require("./context"); | ||
const AnalyticsProvider = ({ segmentWriteToken, blockedUserAgents, children, }) => { | ||
const [isReady, setIsReady] = (0, react_1.useState)(false); | ||
const isBlockedUserAgent = (0, react_1.useMemo)(() => { | ||
import { AnalyticsBrowser } from "@segment/analytics-next"; | ||
import React, { useCallback, useEffect, useMemo, useState } from "react"; | ||
import { AnalyticsContext } from "./context"; | ||
export const AnalyticsProvider = ({ segmentWriteToken, blockedUserAgents, children, }) => { | ||
const [isReady, setIsReady] = useState(false); | ||
const isBlockedUserAgent = useMemo(() => { | ||
var _a, _b; | ||
@@ -39,8 +13,8 @@ return (!!blockedUserAgents && | ||
}, [blockedUserAgents === null || blockedUserAgents === void 0 ? void 0 : blockedUserAgents.join("")]); | ||
const analytics = (0, react_1.useMemo)(() => { | ||
const analytics = useMemo(() => { | ||
if (!segmentWriteToken) | ||
return; | ||
return analytics_next_1.AnalyticsBrowser.load({ writeKey: segmentWriteToken }); | ||
return AnalyticsBrowser.load({ writeKey: segmentWriteToken }); | ||
}, [segmentWriteToken]); | ||
(0, react_1.useEffect)(() => { | ||
useEffect(() => { | ||
if (!analytics) | ||
@@ -50,3 +24,3 @@ return; | ||
}, [analytics]); | ||
const identify = (0, react_1.useCallback)((...args) => { | ||
const identify = useCallback((...args) => { | ||
if (!analytics || isBlockedUserAgent) | ||
@@ -56,3 +30,3 @@ return; | ||
}, [analytics, isBlockedUserAgent]); | ||
const alias = (0, react_1.useCallback)((...args) => { | ||
const alias = useCallback((...args) => { | ||
if (!analytics) | ||
@@ -62,3 +36,3 @@ return; | ||
}, [analytics]); | ||
const trackPageView = (0, react_1.useCallback)((...args) => { | ||
const trackPageView = useCallback((...args) => { | ||
if (!analytics) | ||
@@ -68,3 +42,3 @@ return; | ||
}, [analytics]); | ||
const track = (0, react_1.useCallback)((...args) => { | ||
const track = useCallback((...args) => { | ||
if (!analytics || isBlockedUserAgent) | ||
@@ -74,3 +48,3 @@ return; | ||
}, [analytics, isBlockedUserAgent]); | ||
const reset = (0, react_1.useCallback)(() => { | ||
const reset = useCallback(() => { | ||
if (!analytics) | ||
@@ -80,3 +54,3 @@ return; | ||
}, [analytics]); | ||
const contextValue = (0, react_1.useMemo)(() => ({ | ||
const contextValue = useMemo(() => ({ | ||
analyticsReady: isReady, | ||
@@ -89,5 +63,4 @@ identify, | ||
}), [isReady, identify, alias, trackPageView, track, reset]); | ||
return (react_1.default.createElement(context_1.AnalyticsContext.Provider, { value: contextValue }, children)); | ||
return (React.createElement(AnalyticsContext.Provider, { value: contextValue }, children)); | ||
}; | ||
exports.AnalyticsProvider = AnalyticsProvider; | ||
//# sourceMappingURL=provider.js.map |
@@ -1,3 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
export {}; | ||
//# sourceMappingURL=types.js.map |
@@ -1,8 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useAnalytics = void 0; | ||
const react_1 = require("react"); | ||
const context_1 = require("./context"); | ||
function useAnalytics() { | ||
const result = (0, react_1.useContext)(context_1.AnalyticsContext); | ||
import { useContext } from "react"; | ||
import { AnalyticsContext } from "./context"; | ||
export function useAnalytics() { | ||
const result = useContext(AnalyticsContext); | ||
if (!result) | ||
@@ -12,3 +9,2 @@ throw new Error("Context used outside of its Provider!"); | ||
} | ||
exports.useAnalytics = useAnalytics; | ||
//# sourceMappingURL=useAnalytics.js.map |
@@ -1,41 +0,11 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.withAnalytics = void 0; | ||
const react_1 = __importStar(require("react")); | ||
const hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics")); | ||
const context_1 = require("./context"); | ||
function withAnalytics(WrappedComponent) { | ||
import React, { useContext } from "react"; | ||
import hoistNonReactStatics from "hoist-non-react-statics"; | ||
import { AnalyticsContext } from "./context"; | ||
export function withAnalytics(WrappedComponent) { | ||
const WithAnalytics = (props) => { | ||
const context = (0, react_1.useContext)(context_1.AnalyticsContext); | ||
return react_1.default.createElement(WrappedComponent, Object.assign({}, props, context)); | ||
const context = useContext(AnalyticsContext); | ||
return React.createElement(WrappedComponent, Object.assign({}, props, context)); | ||
}; | ||
return (0, hoist_non_react_statics_1.default)(WithAnalytics, WrappedComponent, {}); | ||
return hoistNonReactStatics(WithAnalytics, WrappedComponent, {}); | ||
} | ||
exports.withAnalytics = withAnalytics; | ||
//# sourceMappingURL=withAnalytics.js.map |
{ | ||
"name": "@dapperlabs/react-analytics", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A utility to connect react projects to segment", | ||
@@ -5,0 +5,0 @@ "repository": "github:dapperlabs/react-analytics", |
@@ -28,5 +28,5 @@ { | ||
/* Modules */ | ||
"module": "commonjs", /* Specify what module code is generated. */ | ||
"module": "ES2015", /* Specify what module code is generated. */ | ||
// "rootDir": "./", /* Specify the root folder within your source files. */ | ||
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ | ||
@@ -33,0 +33,0 @@ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
30467
336