diff --git a/packages/google-analytics-gtag/package.json b/packages/google-analytics-gtag/package.json index 49ae9f4..4b8816a 100644 --- a/packages/google-analytics-gtag/package.json +++ b/packages/google-analytics-gtag/package.json @@ -1,6 +1,6 @@ { "name": "@redux-beacon/google-analytics-gtag", - "version": "1.0.0", + "version": "1.0.1", "description": "Google Analytics (gtag.js) integration for Redux", "main": "dist/index.js", "typings": "dist/index.d.ts", diff --git a/packages/google-analytics-gtag/src/__tests__/google-analytics-gtag.test.ts b/packages/google-analytics-gtag/src/__tests__/google-analytics-gtag.test.ts index b124447..11d2eee 100644 --- a/packages/google-analytics-gtag/src/__tests__/google-analytics-gtag.test.ts +++ b/packages/google-analytics-gtag/src/__tests__/google-analytics-gtag.test.ts @@ -74,6 +74,24 @@ describe('Page Tracking', () => { expect(window.gtag).toHaveBeenCalledWith('config', 'GA_TRACKING_ID_1', {}); expect(window.gtag).toHaveBeenCalledWith('config', 'GA_TRACKING_ID_2', {}); }); + + test('given { type: "page", trackingId: [] } (empty trackPageView)', () => { + const events = [ + { + type: 'page', + trackingId: [], + page_path: '/topics', + }, + ]; + + const target = GoogleAnalyticsGtag('GA_TRACKING_ID'); + + target(events); + + expect(window.gtag).toHaveBeenCalledWith('config', 'GA_TRACKING_ID', { + page_path: '/topics', + }); + }); }); describe('Event Tracking', () => { diff --git a/packages/google-analytics-gtag/src/google-analytics-gtag.ts b/packages/google-analytics-gtag/src/google-analytics-gtag.ts index a0b4d82..e46f89a 100644 --- a/packages/google-analytics-gtag/src/google-analytics-gtag.ts +++ b/packages/google-analytics-gtag/src/google-analytics-gtag.ts @@ -2,7 +2,7 @@ import { Target } from 'redux-beacon'; declare let gtag: any; -function GoogleAnalyticsGtag(gaTrackingId: string): Target { +function GoogleAnalyticsGtag(defaultTrackingId: string): Target { if (typeof window === 'undefined') { return () => {}; } @@ -13,7 +13,7 @@ function GoogleAnalyticsGtag(gaTrackingId: string): Target { ); } - gtag('config', gaTrackingId, { send_page_view: false }); + gtag('config', defaultTrackingId, { send_page_view: false }); return function target(events) { const pageTracking = events.filter(event => event.type === 'page'); @@ -22,13 +22,13 @@ function GoogleAnalyticsGtag(gaTrackingId: string): Target { pageTracking.forEach(event => { const { type, trackingId, ...params } = event; - let trackingIds = [gaTrackingId]; + let trackingIds = [defaultTrackingId]; if (typeof trackingId === 'string') { trackingIds = [trackingId]; } - if (Array.isArray(trackingId)) { + if (Array.isArray(trackingId) && trackingId.length > 0) { trackingIds = trackingId; }