From 96113eca998af5b978209963ae6bc4039a9048e6 Mon Sep 17 00:00:00 2001 From: lfarrell Date: Thu, 12 Oct 2023 13:27:02 -0400 Subject: [PATCH 1/2] Remove Google Analytics --- .../src/test/resources/access-app.properties | 1 - static/js/vue-cdr-access/package-lock.json | 50 +++---- static/js/vue-cdr-access/package.json | 3 +- static/js/vue-cdr-access/src/main.js | 10 +- .../src/mixins/analyticsUtils.js | 17 --- .../tests/fixtures/testHelpers.js | 4 - .../tests/unit/aboutRepository.spec.js | 2 - .../tests/unit/advancedSearch.spec.js | 2 - .../tests/unit/analyticsUtils.spec.js | 4 +- .../tests/unit/displayWrapper.spec.js | 2 - .../tests/unit/frontPage.spec.js | 2 - .../tests/unit/matomoUtils.spec.js | 2 - .../tests/unit/searchWrapper.spec.js | 2 - static/service-unavailable.html | 2 - .../main/webapp/WEB-INF/service-context.xml | 4 - .../common/utils/AnalyticsTrackerUtil.java | 130 ------------------ .../utils/AnalyticsTrackerUtilTest.java | 64 +-------- .../main/webapp/WEB-INF/service-context.xml | 6 - 18 files changed, 23 insertions(+), 284 deletions(-) delete mode 100644 static/js/vue-cdr-access/tests/fixtures/testHelpers.js diff --git a/integration/src/test/resources/access-app.properties b/integration/src/test/resources/access-app.properties index 46f9dd2780..470bfdcbaa 100644 --- a/integration/src/test/resources/access-app.properties +++ b/integration/src/test/resources/access-app.properties @@ -17,7 +17,6 @@ services.api.url=http://localhost:48080/services/api/ fuseki.baseUri=http://localhost:48080 -google.trackingId= matomo.authToken= matomo.api.url= matomo.site.id=5 diff --git a/static/js/vue-cdr-access/package-lock.json b/static/js/vue-cdr-access/package-lock.json index 5c1b36baa0..de8ff45ff6 100644 --- a/static/js/vue-cdr-access/package-lock.json +++ b/static/js/vue-cdr-access/package-lock.json @@ -25,7 +25,6 @@ "lodash.sortby": "^4.7.0", "nouislider": "^15.6.1", "vue": "^3.2.47", - "vue-gtag": "^2.0.1", "vue-i18n": "^9.2.2", "vue-router": "^4.1.6", "vuex": "^4.1.0" @@ -41,7 +40,7 @@ "@vue/test-utils": "2.3.2", "@vue/vue3-jest": "^29.2.3", "babel-jest": "^29.5.0", - "caniuse-lite": "^1.0.30001474", + "caniuse-lite": "^1.0.30001547", "jest-environment-jsdom": "^29.5.0", "jest-localstorage-mock": "^2.4.26", "moxios": "^0.4.0", @@ -51,9 +50,9 @@ } }, "node_modules/@adobe/css-tools": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.0.1.tgz", - "integrity": "sha512-+u76oB43nOHrF4DDWRLWDCtci7f3QJoEBigemIdIeTi1ODqjx6Tad9NCVnPRwewWlKkVab5PlK8DCtPTyX7S8g==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.1.tgz", + "integrity": "sha512-/62yikz7NLScCGAAST5SHdnjaDJQBDq0M2muyRTpf2VQhw6StBg2ALiu73zSJQ4fMVLA+0uBhBHAle7Wg+2kSg==", "dev": true }, "node_modules/@antfu/utils": { @@ -3878,9 +3877,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001474", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001474.tgz", - "integrity": "sha512-iaIZ8gVrWfemh5DG3T9/YqarVZoYf0r188IjaGwx68j4Pf0SGY6CQkmJUIE+NZHkkecQGohzXmBGEwWDr9aM3Q==", + "version": "1.0.30001547", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001547.tgz", + "integrity": "sha512-W7CrtIModMAxobGhz8iXmDfuJiiKg1WADMO/9x7/CLNin5cpSbuBjooyoIUVB5eyCc36QuTVlkVa1iB2S5+/eA==", "dev": true, "funding": [ { @@ -4286,9 +4285,10 @@ } }, "node_modules/debug": { - "version": "4.2.0", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, - "license": "MIT", "dependencies": { "ms": "2.1.2" }, @@ -9887,14 +9887,6 @@ "@vue/shared": "3.2.47" } }, - "node_modules/vue-gtag": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/vue-gtag/-/vue-gtag-2.0.1.tgz", - "integrity": "sha512-aM4A58FVL0wV2ptYi+xzAjeg+pQVRyUcfBc5UkXAwQrR4t3WBhor50Izp2I+3Oo7+l+vWJ7u78DGcNzReb8S/A==", - "peerDependencies": { - "vue": "^3.0.0" - } - }, "node_modules/vue-i18n": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.2.2.tgz", @@ -10259,9 +10251,9 @@ }, "dependencies": { "@adobe/css-tools": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.0.1.tgz", - "integrity": "sha512-+u76oB43nOHrF4DDWRLWDCtci7f3QJoEBigemIdIeTi1ODqjx6Tad9NCVnPRwewWlKkVab5PlK8DCtPTyX7S8g==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.3.1.tgz", + "integrity": "sha512-/62yikz7NLScCGAAST5SHdnjaDJQBDq0M2muyRTpf2VQhw6StBg2ALiu73zSJQ4fMVLA+0uBhBHAle7Wg+2kSg==", "dev": true }, "@antfu/utils": { @@ -13083,9 +13075,9 @@ "dev": true }, "caniuse-lite": { - "version": "1.0.30001474", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001474.tgz", - "integrity": "sha512-iaIZ8gVrWfemh5DG3T9/YqarVZoYf0r188IjaGwx68j4Pf0SGY6CQkmJUIE+NZHkkecQGohzXmBGEwWDr9aM3Q==", + "version": "1.0.30001547", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001547.tgz", + "integrity": "sha512-W7CrtIModMAxobGhz8iXmDfuJiiKg1WADMO/9x7/CLNin5cpSbuBjooyoIUVB5eyCc36QuTVlkVa1iB2S5+/eA==", "dev": true }, "canvas": { @@ -13396,7 +13388,9 @@ "requires": {} }, "debug": { - "version": "4.2.0", + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, "requires": { "ms": "2.1.2" @@ -17473,12 +17467,6 @@ "@vue/shared": "3.2.47" } }, - "vue-gtag": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/vue-gtag/-/vue-gtag-2.0.1.tgz", - "integrity": "sha512-aM4A58FVL0wV2ptYi+xzAjeg+pQVRyUcfBc5UkXAwQrR4t3WBhor50Izp2I+3Oo7+l+vWJ7u78DGcNzReb8S/A==", - "requires": {} - }, "vue-i18n": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/vue-i18n/-/vue-i18n-9.2.2.tgz", diff --git a/static/js/vue-cdr-access/package.json b/static/js/vue-cdr-access/package.json index eef2ddce19..ff85d34b6f 100644 --- a/static/js/vue-cdr-access/package.json +++ b/static/js/vue-cdr-access/package.json @@ -27,7 +27,6 @@ "lodash.sortby": "^4.7.0", "nouislider": "^15.6.1", "vue": "^3.2.47", - "vue-gtag": "^2.0.1", "vue-i18n": "^9.2.2", "vue-router": "^4.1.6", "vuex": "^4.1.0" @@ -43,7 +42,7 @@ "@vue/test-utils": "2.3.2", "@vue/vue3-jest": "^29.2.3", "babel-jest": "^29.5.0", - "caniuse-lite": "^1.0.30001474", + "caniuse-lite": "^1.0.30001547", "jest-environment-jsdom": "^29.5.0", "jest-localstorage-mock": "^2.4.26", "moxios": "^0.4.0", diff --git a/static/js/vue-cdr-access/src/main.js b/static/js/vue-cdr-access/src/main.js index e0c38f570a..3aa89c8fc9 100644 --- a/static/js/vue-cdr-access/src/main.js +++ b/static/js/vue-cdr-access/src/main.js @@ -1,7 +1,6 @@ import { createApp, h } from 'vue' import { createI18n } from 'vue-i18n' import { createHead, VueHeadMixin } from "@vueuse/head" -import VueGtag from 'vue-gtag'; import App from './App.vue' import router from './router' import store from './store' @@ -24,8 +23,6 @@ if (document.getElementById('app') !== null && window.dcr_browse_records === und } }); - const gaCode = import.meta.env.VITE_GA_CODE || ''; - // Set this here as it gives a build error otherwise window.matomoSiteSrcUrl = import.meta.env.VITE_MATOMO_SITE_SRC_URL || ''; @@ -37,10 +34,5 @@ if (document.getElementById('app') !== null && window.dcr_browse_records === und .use(head) .use(store) .use(router) - .use(i18n) - .use(VueGtag, { - config: { - id: gaCode - } - }).mount('#app'); + .use(i18n).mount('#app'); } \ No newline at end of file diff --git a/static/js/vue-cdr-access/src/mixins/analyticsUtils.js b/static/js/vue-cdr-access/src/mixins/analyticsUtils.js index b2987fd94d..9d61c3e9fb 100644 --- a/static/js/vue-cdr-access/src/mixins/analyticsUtils.js +++ b/static/js/vue-cdr-access/src/mixins/analyticsUtils.js @@ -1,14 +1,6 @@ export default { methods: { pageEvent(recordData) { - this.$gtag.event('record', { - 'event_category': recordData.briefObject.parentCollectionId, - 'event_label': `${recordData.briefObject.title}|${recordData.briefObject.id}` - }); - this.matomoPageEvent(recordData); - }, - - matomoPageEvent(recordData) { let collection = recordData.briefObject.parentCollectionName || ''; if (collection === '' && recordData.briefObject.type === 'Collection') { collection = recordData.briefObject.title; @@ -29,15 +21,6 @@ export default { }, pageView(title) { - this.$gtag.pageview({ - page_title: `Digital Collections Repository - ${title}`, - page_path: this.$route.path, - page_location: window.location.href - }); - this.matomoPageView(title) - }, - - matomoPageView(title) { window._mtm = window._mtm || []; window._mtm.push({ event: 'pageViewEvent', diff --git a/static/js/vue-cdr-access/tests/fixtures/testHelpers.js b/static/js/vue-cdr-access/tests/fixtures/testHelpers.js deleted file mode 100644 index a73cc60ce9..0000000000 --- a/static/js/vue-cdr-access/tests/fixtures/testHelpers.js +++ /dev/null @@ -1,4 +0,0 @@ -export const $gtag = { - event: jest.fn(), - pageview: jest.fn() -}; \ No newline at end of file diff --git a/static/js/vue-cdr-access/tests/unit/aboutRepository.spec.js b/static/js/vue-cdr-access/tests/unit/aboutRepository.spec.js index 843c965a09..53904b2ca2 100644 --- a/static/js/vue-cdr-access/tests/unit/aboutRepository.spec.js +++ b/static/js/vue-cdr-access/tests/unit/aboutRepository.spec.js @@ -6,7 +6,6 @@ import {createI18n} from "vue-i18n"; import translations from "@/translations"; import store from '@/store'; import moxios from "moxios"; -import { $gtag } from '../fixtures/testHelpers'; let wrapper, router; @@ -38,7 +37,6 @@ describe('aboutRepository.vue', () => { wrapper = shallowMount(aboutRepository, { global: { plugins: [i18n, router, store], - mocks: { $gtag }, stubs: { RouterLink: RouterLinkStub } diff --git a/static/js/vue-cdr-access/tests/unit/advancedSearch.spec.js b/static/js/vue-cdr-access/tests/unit/advancedSearch.spec.js index f2ea4612f5..d68f8e45c1 100644 --- a/static/js/vue-cdr-access/tests/unit/advancedSearch.spec.js +++ b/static/js/vue-cdr-access/tests/unit/advancedSearch.spec.js @@ -6,7 +6,6 @@ import {createI18n} from "vue-i18n"; import translations from "@/translations"; import store from '@/store'; import moxios from "moxios"; -import { $gtag } from '../fixtures/testHelpers'; let wrapper, router; @@ -38,7 +37,6 @@ describe('advancedSearch.vue', () => { wrapper = shallowMount(advancedSearch, { global: { plugins: [i18n, router, store], - mocks: { $gtag }, stubs: { RouterLink: RouterLinkStub } diff --git a/static/js/vue-cdr-access/tests/unit/analyticsUtils.spec.js b/static/js/vue-cdr-access/tests/unit/analyticsUtils.spec.js index 07f3c1d176..0cdb651b27 100644 --- a/static/js/vue-cdr-access/tests/unit/analyticsUtils.spec.js +++ b/static/js/vue-cdr-access/tests/unit/analyticsUtils.spec.js @@ -6,7 +6,6 @@ import analyticsUtils from "../../src/mixins/analyticsUtils"; import store from '@/store'; import { createI18n } from "vue-i18n"; import translations from "@/translations"; -import { $gtag } from '../fixtures/testHelpers'; import moxios from "moxios"; let wrapper; @@ -44,7 +43,6 @@ describe('analyticsUtils', () => { wrapper = mount(advancedSearch, { global: { plugins: [router, store, i18n], - mocks: { $gtag }, stubs: { RouterLink: RouterLinkStub } @@ -145,7 +143,7 @@ describe('analyticsUtils', () => { wrapper = mount(displayWrapper, { global: { plugins: [store, i18n], - mocks: { $gtag, $route }, + mocks: { $route }, stubs: { RouterLink: RouterLinkStub } diff --git a/static/js/vue-cdr-access/tests/unit/displayWrapper.spec.js b/static/js/vue-cdr-access/tests/unit/displayWrapper.spec.js index 5a29d667c6..0a8d82ff0a 100644 --- a/static/js/vue-cdr-access/tests/unit/displayWrapper.spec.js +++ b/static/js/vue-cdr-access/tests/unit/displayWrapper.spec.js @@ -6,7 +6,6 @@ import moxios from "moxios"; import {createI18n} from "vue-i18n"; import translations from "@/translations"; import { response, briefObjectData } from "../fixtures/displayWrapperFixtures"; -import { $gtag } from '../fixtures/testHelpers'; let wrapper, router; @@ -45,7 +44,6 @@ describe('displayWrapper.vue', () => { wrapper = mount(displayWrapper, { global: { plugins: [router, store, i18n], - mocks: { $gtag }, stubs: { RouterLink: RouterLinkStub } diff --git a/static/js/vue-cdr-access/tests/unit/frontPage.spec.js b/static/js/vue-cdr-access/tests/unit/frontPage.spec.js index d1ef906e78..b3e9d8fc61 100644 --- a/static/js/vue-cdr-access/tests/unit/frontPage.spec.js +++ b/static/js/vue-cdr-access/tests/unit/frontPage.spec.js @@ -6,7 +6,6 @@ import {createI18n} from "vue-i18n"; import translations from "@/translations"; import store from '@/store'; import moxios from "moxios"; -import { $gtag } from '../fixtures/testHelpers'; let wrapper, router; @@ -38,7 +37,6 @@ describe('frontPage.vue', () => { wrapper = shallowMount(frontPage, { global: { plugins: [i18n, router, store], - mocks: { $gtag }, stubs: { RouterLink: RouterLinkStub } diff --git a/static/js/vue-cdr-access/tests/unit/matomoUtils.spec.js b/static/js/vue-cdr-access/tests/unit/matomoUtils.spec.js index 43b08d782f..db7d42fab0 100644 --- a/static/js/vue-cdr-access/tests/unit/matomoUtils.spec.js +++ b/static/js/vue-cdr-access/tests/unit/matomoUtils.spec.js @@ -6,7 +6,6 @@ import displayWrapper from '@/components/displayWrapper.vue'; import store from '@/store'; import { createI18n } from "vue-i18n"; import translations from "@/translations"; -import { $gtag } from '../fixtures/testHelpers'; let wrapper; @@ -44,7 +43,6 @@ describe('matomoUtils', () => { attachTo: '#root', global: { plugins: [router, store, i18n], - mocks: { $gtag }, stubs: { RouterLink: RouterLinkStub } diff --git a/static/js/vue-cdr-access/tests/unit/searchWrapper.spec.js b/static/js/vue-cdr-access/tests/unit/searchWrapper.spec.js index ed59d6b139..113da177aa 100644 --- a/static/js/vue-cdr-access/tests/unit/searchWrapper.spec.js +++ b/static/js/vue-cdr-access/tests/unit/searchWrapper.spec.js @@ -5,7 +5,6 @@ import moxios from "moxios"; import displayWrapper from "@/components/displayWrapper.vue"; import {createI18n} from "vue-i18n"; import translations from "@/translations"; -import { $gtag } from '../fixtures/testHelpers'; const response = { "container": { @@ -141,7 +140,6 @@ describe('searchWrapper.vue', () => { wrapper = shallowMount(searchWrapper, { global: { plugins: [router, i18n], - mocks: { $gtag } } }); diff --git a/static/service-unavailable.html b/static/service-unavailable.html index b423fc1ffe..ae3d228017 100644 --- a/static/service-unavailable.html +++ b/static/service-unavailable.html @@ -45,8 +45,6 @@ - - Digital Collections Repository - Page Unavailable diff --git a/web-access-app/src/main/webapp/WEB-INF/service-context.xml b/web-access-app/src/main/webapp/WEB-INF/service-context.xml index 922573be8f..fdb3a2e605 100644 --- a/web-access-app/src/main/webapp/WEB-INF/service-context.xml +++ b/web-access-app/src/main/webapp/WEB-INF/service-context.xml @@ -41,10 +41,6 @@ - - - - diff --git a/web-common/src/main/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtil.java b/web-common/src/main/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtil.java index 9056839bc0..f4caf1fc38 100644 --- a/web-common/src/main/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtil.java +++ b/web-common/src/main/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtil.java @@ -1,23 +1,10 @@ package edu.unc.lib.boxc.web.common.utils; import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; -import org.apache.http.NameValuePair; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.conn.HttpClientConnectionManager; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; import org.matomo.java.tracking.MatomoTracker; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,42 +28,13 @@ public class AnalyticsTrackerUtil { // Made up CID to use if the request does not include one, such as from a API request protected static final String DEFAULT_CID = "35009a79-1a05-49d7-b876-2b884d0f825b"; - // Google analytics measurement API url - private static final String GA_URL = "https://www.google-analytics.com/collect"; public static final String MATOMO_ACTION = "Downloaded Original"; - // Google analytics tracking id - private String gaTrackingID; - - private HttpClientConnectionManager httpClientConnectionManager; - private CloseableHttpClient httpClient; - private String repositoryHost; private String matomoAuthToken; private String matomoApiURL; private int matomoSiteID; private SolrSearchService solrSearchService; - public void setHttpClientConnectionManager(HttpClientConnectionManager manager) { - this.httpClientConnectionManager = manager; - - RequestConfig requestConfig = RequestConfig.custom() - .setConnectTimeout(2000) - .build(); - - this.httpClient = HttpClients.custom() - .setConnectionManager(httpClientConnectionManager) - .setDefaultRequestConfig(requestConfig) - .build(); - } - - public void setHttpClient(CloseableHttpClient httpClient) { - this.httpClient = httpClient; - } - - public void setGaTrackingID(String trackingID) { - this.gaTrackingID = trackingID; - } - /** * Track an event with the specified action for object pid for the active user on the request. * @@ -94,7 +52,6 @@ public void trackEvent(HttpServletRequest request, String action, PID pid, Acces "(no collection)" : briefObject.getParentCollectionName(); String viewedObjectLabel = briefObject.getTitle() + "|" + pid; - trackEvent(userData, parentCollection, action, viewedObjectLabel); // track in matomo var matomoRequest = buildMatomoRequest(getFullURL(request), userData, parentCollection, viewedObjectLabel); sendMatomoRequest(matomoRequest); @@ -104,16 +61,6 @@ public void trackEvent(HttpServletRequest request, String action, PID pid, Acces } } - private void trackEvent(AnalyticsUserData userData, String category, String action, String label) { - if (userData == null) { - return; - } - - // Perform the analytics tracking event asynchronously - Thread trackerThread = new Thread(new EventTrackerRunnable(userData, category, action, label)); - trackerThread.start(); - } - private MatomoRequest buildMatomoRequest(String url, AnalyticsUserData userData, String parentCollection, String label) throws UnsupportedEncodingException { return MatomoRequest.builder() .siteId(matomoSiteID) @@ -156,10 +103,6 @@ private String getFullURL(HttpServletRequest request) { public void setSolrSearchService(SolrSearchService solrSearchService) { this.solrSearchService = solrSearchService; } - - public void setRepositoryHost(String repositoryHost) { - this.repositoryHost = repositoryHost; - } public void setMatomoAuthToken(String matomoAuthToken) { this.matomoAuthToken = matomoAuthToken; } @@ -232,77 +175,4 @@ public AnalyticsUserData(HttpServletRequest request) { } } } - - protected class EventTrackerRunnable implements Runnable { - - private final AnalyticsUserData userData; - private final String category; - private final String action; - private final String label; - - public EventTrackerRunnable(AnalyticsUserData userData, String category, String action, String label) { - this.category = category; - this.action = action; - this.label = label; - this.userData = userData; - } - - @Override - public void run() { - log.debug("Tracking user {} with event {} in category {} with label {}", - userData.cid, action, category, label); - - URIBuilder builder; - try { - builder = new URIBuilder(GA_URL); - } catch (URISyntaxException e) { - log.warn("Failed to build URI for tracker", e); - return; - } - - // See https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters - List params = new ArrayList<>(); - params.add(new BasicNameValuePair("v", "1")); - params.add(new BasicNameValuePair("tid", gaTrackingID)); - params.add(new BasicNameValuePair("cid", userData.cid)); - params.add(new BasicNameValuePair("t", "event")); - params.add(new BasicNameValuePair("uip", userData.uip)); - params.add(new BasicNameValuePair("ua", userData.userAgent)); - params.add(new BasicNameValuePair("dh", repositoryHost)); - params.add(new BasicNameValuePair("an", "cdr")); - params.add(new BasicNameValuePair("de", "UTF-8")); - params.add(new BasicNameValuePair("ul", "en-us")); - log.debug("Tracking user {} with event {} in category {} with label {}", - userData.cid, action, category, label); - log.debug("Tracking:{} {} {} {}", new Object[] { GA_URL, gaTrackingID, userData.cid, userData.uip}); - - if (category != null) { - params.add(new BasicNameValuePair("ec", category)); - } - if (action != null) { - params.add(new BasicNameValuePair("ea", action)); - } - if (label != null) { - params.add(new BasicNameValuePair("el", label)); - } - - builder.addParameters(params); - - HttpGet method; - try { - URI url = builder.build(); - method = new HttpGet(url); - method.addHeader("Accept", "*/*"); - } catch (URISyntaxException e) { - log.warn("Failed to build tracking url", e); - return; - } - - try (CloseableHttpResponse resp = httpClient.execute(method)) { - } catch (Exception e) { - log.warn("Failed to issue tracking event for cid {}", e, userData.cid); - } - } - - } } diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtilTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtilTest.java index bad83022bb..fdfbe0da63 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtilTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/AnalyticsTrackerUtilTest.java @@ -9,13 +9,10 @@ import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.solr.services.SolrSearchService; -import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.impl.client.CloseableHttpClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import com.github.tomakehurst.wiremock.junit5.WireMockTest; @@ -25,7 +22,6 @@ import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; -import java.net.URI; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.HashMap; @@ -37,11 +33,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; /** @@ -51,22 +44,14 @@ public class AnalyticsTrackerUtilTest { private final static String PID_UUID = "03114533-0017-4c83-b9d9-567b08fb2429"; @Mock - private HttpClientConnectionManager httpClientConnectionManager; - @Mock - private CloseableHttpClient httpClient; - @Mock private SolrSearchService solrSearchService; @Mock private HttpServletRequest request; @Mock private ContentObjectRecord contentObjectRecord; - @Captor - private ArgumentCaptor httpRequestCaptor; private AccessGroupSet principals; private AnalyticsTrackerUtil analyticsTrackerUtil; - private String repositoryHost = "boxy.example.com"; - private String trackingId = "trackme"; private String authToken = "secret123456789qwertyasdfghzxcvb"; private String apiURL = "http://localhost:46887"; private String userId = "5e462bae5cada463"; @@ -78,10 +63,7 @@ public class AnalyticsTrackerUtilTest { public void setup() { MockitoAnnotations.openMocks(this); analyticsTrackerUtil = new AnalyticsTrackerUtil(); - analyticsTrackerUtil.setRepositoryHost(repositoryHost); - analyticsTrackerUtil.setGaTrackingID(trackingId); analyticsTrackerUtil.setSolrSearchService(solrSearchService); - analyticsTrackerUtil.setHttpClient(httpClient); analyticsTrackerUtil.setMatomoApiURL(apiURL); analyticsTrackerUtil.setMatomoAuthToken(authToken); analyticsTrackerUtil.setMatomoSiteID(siteID); @@ -91,13 +73,10 @@ public void setup() { @Test public void testTrackEventInCollection() throws Exception { when(request.getHeader("Proxy-Client-IP")).thenReturn("0.0.0.0"); - var cidCookie = mock(Cookie.class); - when(cidCookie.getName()).thenReturn("_ga"); - when(cidCookie.getValue()).thenReturn("ga.1.123456789.1234567890"); var uidCookie = mock(Cookie.class); when(uidCookie.getName()).thenReturn("_pk_id"); when(uidCookie.getValue()).thenReturn(userId +".1234567890"); - when(request.getCookies()).thenReturn(new Cookie[]{ cidCookie, uidCookie }); + when(request.getCookies()).thenReturn(new Cookie[]{ uidCookie }); when(request.getHeader("User-Agent")).thenReturn("boxy-client"); when(request.getRequestURL()).thenReturn(urlBuffer); var pid = PIDs.get(PID_UUID); @@ -114,11 +93,6 @@ public void testTrackEventInCollection() throws Exception { analyticsTrackerUtil.trackEvent(request, "testAction", pid, principals); - verify(httpClient, timeout(1000).times(1)).execute(httpRequestCaptor.capture()); - var gaRequest = httpRequestCaptor.getValue(); - var gaUri = gaRequest.getURI(); - assertGaQueryIsCorrect(gaUri, true); - assertMatomoQueryIsCorrect(expectedParams); } @@ -144,12 +118,6 @@ public void testTrackEventNotInCollection() throws Exception { analyticsTrackerUtil.trackEvent(request, "testAction", pid, principals); - verify(httpClient, timeout(1000).times(1)).execute(httpRequestCaptor.capture()); - - var gaRequest = httpRequestCaptor.getValue(); - var gaUri = gaRequest.getURI(); - assertGaQueryIsCorrect(gaUri, false); - assertMatomoQueryIsCorrect(expectedParams); } @@ -181,36 +149,6 @@ public void testAnalyticsUserDataRemoteAddr() throws Exception { assertEquals("1.1.1.1", userData.uip); } - @Test - public void testSetHttpClientConnectionManager() throws Exception { - // Just verifying the setter doesn't error - analyticsTrackerUtil.setHttpClientConnectionManager(httpClientConnectionManager); - } - - private void assertGaQueryIsCorrect(URI gaUri, boolean withCollection) { - assertEquals("www.google-analytics.com", gaUri.getHost()); - assertEquals("/collect", gaUri.getPath()); - var gaQuery = gaUri.getQuery(); - assertTrue(gaQuery.contains("&t=event")); - assertTrue(gaQuery.contains("&ua=boxy-client")); - assertTrue(gaQuery.contains("&dh=boxy.example.com")); - assertTrue(gaQuery.contains("&an=cdr")); - assertTrue(gaQuery.contains("&de=UTF-8")); - assertTrue(gaQuery.contains("&ea=testAction")); - - if (withCollection) { - assertTrue(gaQuery.contains("&cid=123456789.1234567890")); - assertTrue(gaQuery.contains("&ec=Parent+Collection")); - assertTrue(gaQuery.contains("&uip=0.0.0.0")); - assertTrue(gaQuery.contains("&el=Test+Work|" + url)); - } else { - assertTrue(gaQuery.contains("&cid=" + AnalyticsTrackerUtil.DEFAULT_CID)); - assertTrue(gaQuery.contains("&ec=(no+collection)")); - assertTrue(gaQuery.contains("&uip=1.1.1.1")); - assertTrue(gaQuery.contains("&el=Test+Work2|" + url)); - } - } - private void assertMatomoQueryIsCorrect(Map params) { for (int i=0 ; i<100 ; i++) { try { diff --git a/web-services-app/src/main/webapp/WEB-INF/service-context.xml b/web-services-app/src/main/webapp/WEB-INF/service-context.xml index 1c4bfa967c..114121056c 100644 --- a/web-services-app/src/main/webapp/WEB-INF/service-context.xml +++ b/web-services-app/src/main/webapp/WEB-INF/service-context.xml @@ -172,17 +172,11 @@ - - - - - From 2779a3c5773420241ecb7604d01e4039d5494def Mon Sep 17 00:00:00 2001 From: lfarrell Date: Tue, 2 Jan 2024 15:50:32 -0500 Subject: [PATCH 2/2] More GA cleanup --- .../src/main/webapp/WEB-INF/access-fedora-context.xml | 3 --- web-services-app/src/main/webapp/WEB-INF/service-context.xml | 2 -- 2 files changed, 5 deletions(-) diff --git a/web-access-app/src/main/webapp/WEB-INF/access-fedora-context.xml b/web-access-app/src/main/webapp/WEB-INF/access-fedora-context.xml index e481b1586c..cc44218bd2 100644 --- a/web-access-app/src/main/webapp/WEB-INF/access-fedora-context.xml +++ b/web-access-app/src/main/webapp/WEB-INF/access-fedora-context.xml @@ -22,10 +22,7 @@ - - - diff --git a/web-services-app/src/main/webapp/WEB-INF/service-context.xml b/web-services-app/src/main/webapp/WEB-INF/service-context.xml index 114121056c..8a0adb7398 100644 --- a/web-services-app/src/main/webapp/WEB-INF/service-context.xml +++ b/web-services-app/src/main/webapp/WEB-INF/service-context.xml @@ -178,8 +178,6 @@ - -