Skip to content

Commit

Permalink
Prepare code to remove GA from Web and AMP (#1393)
Browse files Browse the repository at this point in the history
* Prepare code to remove ga from theguardian.com

* Remove googleAnalytics from GuardianWindowConfig

* Remove google.analytics dependency and all ga reference

* Update PeformanceEntry to use entryType === 'navigation'

* Add changeset with minor change

* Update .changeset/strange-pugs-wink.md

Co-authored-by: Simon Adcock <[email protected]>

* Update strange-pugs-wink.md

---------

Co-authored-by: Ravi <[email protected]>
Co-authored-by: Simon Adcock <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2024
1 parent 03d7e81 commit a90f1d4
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 253 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-pugs-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@guardian/commercial': minor
---

Prepare code to remove GA from Commercial
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
"@guardian/prettier": "4.0.0",
"@guardian/source-foundations": "14.1.4",
"@playwright/test": "1.40.1",
"@types/google.analytics": "^0.0.42",
"@types/googletag": "~3.1.3",
"@types/jest": "^29.4.0",
"@types/lodash-es": "^4.17.6",
Expand Down
7 changes: 0 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/core/event-timer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ describe('EventTimer', () => {
window.guardian = {
config: {
...DEFAULT_CONFIG,
googleAnalytics: {
trackers: {
editorial: 'gaTrackerTest',
},
},
},
} as typeof window.guardian;

Expand Down
114 changes: 0 additions & 114 deletions src/core/messenger/click.spec.ts

This file was deleted.

20 changes: 0 additions & 20 deletions src/core/messenger/click.ts

This file was deleted.

20 changes: 10 additions & 10 deletions src/core/targeting/build-page-targeting.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,11 +986,11 @@ describe('Build Page Targeting', () => {
).toBe('t');
});

it('should set firstvisit to true if referrer is empty and navigation type is navigate', () => {
it('should set firstvisit to true if referrer is empty and navigation type is navigation', () => {
jest.spyOn(window, 'performance', 'get').mockReturnValue({
getEntriesByType: () => [
{
type: 'navigate',
entryType: 'navigation',
},
],
mark: () => {
Expand All @@ -1011,11 +1011,11 @@ describe('Build Page Targeting', () => {
).toBe('t');
});

it('should set firstvisit to false if referrer is empty and navigation type is not navigate', () => {
it('should set firstvisit to false if referrer is empty and navigation type is not navigation', () => {
jest.spyOn(window, 'performance', 'get').mockReturnValue({
getEntriesByType: () => [
{
type: 'reload',
entryType: 'reload',
},
],
mark: () => {
Expand All @@ -1036,11 +1036,11 @@ describe('Build Page Targeting', () => {
).toBe('f');
});

it('should set firstvisit to false if referrer is the guardian and navigation type is navigate', () => {
it('should set firstvisit to false if referrer is the guardian and navigation type is navigation', () => {
jest.spyOn(window, 'performance', 'get').mockReturnValue({
getEntriesByType: () => [
{
type: 'navigate',
entryType: 'navigation',
},
],
mark: () => {
Expand All @@ -1063,11 +1063,11 @@ describe('Build Page Targeting', () => {
).toBe('f');
});

it('should set firstvisit to false if referrer is the guardian and navigation type is not navigate', () => {
it('should set firstvisit to false if referrer is the guardian and navigation type is not navigation', () => {
jest.spyOn(window, 'performance', 'get').mockReturnValue({
getEntriesByType: () => [
{
type: 'reload',
entryType: 'reload',
},
],
mark: () => {
Expand All @@ -1090,11 +1090,11 @@ describe('Build Page Targeting', () => {
).toBe('f');
});

it('should set firstvisit to true if referrer is not the guardian and navigation type is navigate', () => {
it('should set firstvisit to true if referrer is not the guardian and navigation type is navigation', () => {
jest.spyOn(window, 'performance', 'get').mockReturnValue({
getEntriesByType: () => [
{
type: 'navigate',
entryType: 'navigation',
},
],
mark: () => {
Expand Down
9 changes: 5 additions & 4 deletions src/core/targeting/build-page-targeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ const filterValues = (pageTargets: Record<string, unknown>) => {
return filtered;
};

const getLastNavigationType = (): NavigationTimingType | undefined => {
const lastPerformanceEntryIsNavigationType = (): boolean => {
if (!supportsPerformanceAPI()) {
return undefined;
return false;
}
const navigationEvents = performance.getEntriesByType('navigation');
const lastNavigationEvent = navigationEvents[navigationEvents.length - 1];
return lastNavigationEvent?.type;
// https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType#navigation
return lastNavigationEvent?.entryType === 'navigation';
};

const referrerMatchesHost = (referrer: string): boolean => {
Expand All @@ -88,7 +89,7 @@ const referrerMatchesHost = (referrer: string): boolean => {

// A consentless friendly way of determining if this is the users first visit to the page
const isFirstVisit = (referrer: string): boolean => {
if (supportsPerformanceAPI() && getLastNavigationType() !== 'navigate') {
if (supportsPerformanceAPI() && !lastPerformanceEntryIsNavigationType()) {
return false;
}

Expand Down
5 changes: 0 additions & 5 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ export type ThirdPartyTag = {

export type GetThirdPartyTag = (arg0: { shouldRun: boolean }) => ThirdPartyTag;

export type GuardianAnalyticsConfig = {
trackers: Record<string, string>;
};

export type Edition = 'UK' | 'AU' | 'US';

export type GuardianWindowConfig = {
googleAnalytics?: GuardianAnalyticsConfig;
isDotcomRendering: boolean;
ophan: {
// somewhat redundant with guardian.ophan
Expand Down
2 changes: 0 additions & 2 deletions src/init/consented/messenger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { initMessenger } from 'core';
import { init as background } from 'core/messenger/background';
import { init as sendClick } from 'core/messenger/click';
import { init as disableRefresh } from 'core/messenger/disable-refresh';
import { init as fullwidth } from 'core/messenger/full-width';
import { init as initGetPageTargeting } from 'core/messenger/get-page-targeting';
Expand Down Expand Up @@ -28,7 +27,6 @@ initMessenger(
passbackRefresh,
resize,
fullwidth,
sendClick,
background,
disableRefresh,
passback,
Expand Down
1 change: 0 additions & 1 deletion src/init/consented/prepare-googletag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ jest.mock('lib/detect/detect-breakpoint', () => ({
getCurrentBreakpoint: jest.fn(),
hasCrossedBreakpoint: jest.fn(),
}));
jest.mock('lib/analytics/google', () => () => void {});
jest.mock('display/display-lazy-ads', () => ({
displayLazyAds: jest.fn(),
}));
Expand Down
77 changes: 0 additions & 77 deletions src/lib/analytics/google.ts

This file was deleted.

Loading

0 comments on commit a90f1d4

Please sign in to comment.