@uniswap/analytics
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -21,2 +21,5 @@ "use strict"; | ||
} | ||
if ((config === null || config === void 0 ? void 0 : config.debug) && config.isProductionEnv) { | ||
throw new Error(`It looks like you're trying to initialize analytics in debug mode for production. Please disable debug mode or the production environment`); | ||
} | ||
isInitialized = true; | ||
@@ -46,2 +49,8 @@ exports.analyticsConfig = config; | ||
const origin = window.location.origin; | ||
if (exports.analyticsConfig === null || exports.analyticsConfig === void 0 ? void 0 : exports.analyticsConfig.debug) { | ||
console.log({ | ||
eventName, | ||
eventProperties: Object.assign(Object.assign({}, eventProperties), { origin }), | ||
}); | ||
} | ||
(0, analytics_browser_1.track)(eventName, Object.assign(Object.assign({}, eventProperties), { origin })); | ||
@@ -48,0 +57,0 @@ } |
import { OriginApplication } from './ApplicationTransport'; | ||
declare type AnalyticsConfig = { | ||
proxyUrl?: string; | ||
isProductionEnv?: boolean; | ||
commitHash?: string; | ||
defaultEventName?: string; | ||
isProductionEnv?: boolean; | ||
debug?: boolean; | ||
}; | ||
@@ -8,0 +9,0 @@ export declare let analyticsConfig: AnalyticsConfig | undefined; |
@@ -19,2 +19,5 @@ import { Identify, identify, init, track } from '@amplitude/analytics-browser'; | ||
} | ||
if (config?.debug && config.isProductionEnv) { | ||
throw new Error(`It looks like you're trying to initialize analytics in debug mode for production. Please disable debug mode or the production environment`); | ||
} | ||
isInitialized = true; | ||
@@ -43,2 +46,8 @@ analyticsConfig = config; | ||
const origin = window.location.origin; | ||
if (analyticsConfig?.debug) { | ||
console.log({ | ||
eventName, | ||
eventProperties: { ...eventProperties, origin }, | ||
}); | ||
} | ||
track(eventName, { ...eventProperties, origin }); | ||
@@ -45,0 +54,0 @@ } |
import { OriginApplication } from './ApplicationTransport'; | ||
declare type AnalyticsConfig = { | ||
proxyUrl?: string; | ||
isProductionEnv?: boolean; | ||
commitHash?: string; | ||
defaultEventName?: string; | ||
isProductionEnv?: boolean; | ||
debug?: boolean; | ||
}; | ||
@@ -8,0 +9,0 @@ export declare let analyticsConfig: AnalyticsConfig | undefined; |
@@ -71,3 +71,3 @@ { | ||
}, | ||
"version": "1.1.2" | ||
"version": "1.2.0" | ||
} |
@@ -54,2 +54,4 @@ # Uniswap Labs Analytics | ||
### Initializing Analytics | ||
The client should be initialized before it is used. To initialize the client, pass in the API key of the application, as well as the name of | ||
@@ -66,4 +68,16 @@ the application. If the application name is not listed under `OriginApplication`, it should be added under the enum. An additional | ||
``` | ||
Note that an `Error` is thrown if the client is initialized more than once. | ||
Note that an `Error` is thrown if the client is initialized more than once or if an invalid configuration object is provided. | ||
#### Configuration Options | ||
| Option | Type | Description | | ||
| :-------------- | :------ | :------------------------------------------------------------------------------------------- | | ||
| `proxyUrl` | string | The Amplitude URL to send events to. | | ||
| `defaultEventName` | string | When an event name is not provided, use the provided default. Defaults to `Page Viewed`. | | ||
| `commitHash` | string | The git commit hash to send with Trace events only. Does not send by default on raw events. | | ||
| `isProductionEnv` | boolean | When not set to true, user properties are not set on the Amplitude client. | | ||
| `debug` | boolean | When enabled, logs events to the console. Cannot be enabled while `isProductionEnv` is true. | | ||
### Logging Events Directly | ||
Before logging an event, make sure to add it under the `EventName` enum in the [@uniswap/analytics-events](https://www.npmjs.com/package/@uniswap/analytics-events) package. To log an analytics event: | ||
@@ -79,2 +93,4 @@ ```js | ||
### Using the Trace Component | ||
There is also a built in React component that logs an event when it is first mounted. You may use it as a wrapper: | ||
@@ -81,0 +97,0 @@ ```js |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80352
683
135