Skip to content

Commit

Permalink
Replace inline logging with logToConsole plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriyyakym committed Jan 9, 2025
1 parent c32181d commit 9438f61
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/analytics-nextjs/src/AnalyticsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { PropsWithChildren } from 'react';
import { createContext, useContext, useEffect, useState } from 'react';

import { isTrackingCookieAllowed } from './lib';
import { normalizePrezlyMetaPlugin, sendEventToPrezlyPlugin } from './plugins';
import { logToConsole, normalizePrezlyMetaPlugin, sendEventToPrezlyPlugin } from './plugins';
import { TrackingPolicy } from './types';
import type {
PickedGalleryProperties,
Expand Down Expand Up @@ -99,6 +99,7 @@ export function AnalyticsProvider({
...(uuid
? [sendEventToPrezlyPlugin(uuid), normalizePrezlyMetaPlugin()]
: []),
...(process.env.NODE_ENV === 'production' ? [] : [logToConsole()]),
...(plugins || []),
],
},
Expand Down
20 changes: 0 additions & 20 deletions packages/analytics-nextjs/src/hooks/useAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ export function useAnalytics() {
(userId: string, traits: object = {}, callback?: () => void) => {
const extendedTraits = injectPrezlyMeta(traits);

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.log(`analytics.identify(${stringify(userId, extendedTraits)})`);
}

if (trackingPolicy === TrackingPolicy.CONSENT_TO_IDENTIFY && !consent) {
setDeferredIdentity({ userId, traits: extendedTraits });
if (callback) {
Expand All @@ -92,11 +87,6 @@ export function useAnalytics() {

const alias = useCallback(
(userId: string, previousId: string) => {
if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.log(`analytics.alias(${stringify(userId, previousId)})`);
}

addToQueue(() => {
if (analyticsRef.current && analyticsRef.current.alias) {
analyticsRef.current.alias(userId, previousId);
Expand All @@ -110,11 +100,6 @@ export function useAnalytics() {
(category?: string, name?: string, properties: object = {}, callback?: () => void) => {
const extendedProperties = injectPrezlyMeta(properties);

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.log(`analytics.page(${stringify(category, name, extendedProperties)})`);
}

addToQueue(() => {
if (analyticsRef.current && analyticsRef.current.page) {
analyticsRef.current.page(category, name, extendedProperties, {}, callback);
Expand All @@ -128,11 +113,6 @@ export function useAnalytics() {
(event: string, properties: object = {}, callback?: () => void) => {
const extendedProperties = injectPrezlyMeta(properties);

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line no-console
console.log(`analytics.track(${stringify(event, extendedProperties)})`);
}

addToQueue(() => {
if (analyticsRef.current && analyticsRef.current.track) {
analyticsRef.current.track(event, extendedProperties, {}, callback);
Expand Down

0 comments on commit 9438f61

Please sign in to comment.