Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove unused Google Analytics code (#905)
sarayourfriend5a2de7749d17
diff --git a/nuxt.config.js b/nuxt.config.jsindex 438fce678..d0863483f 100644--- a/nuxt.config.js+++ b/nuxt.config.js@@ -116,7 +116,6 @@ export default {dirs: [{ path: '~/components', extensions: ['vue'], pathPrefix: false }],},plugins: [- { src: '~/plugins/ga.js', mode: 'client' },{ src: '~/plugins/url-change.js' },{ src: '~/plugins/migration-notice.js' },{ src: '~/plugins/ua-parse.js' },diff --git a/src/analytics/events.js b/src/analytics/events.jsdeleted file mode 100644index 9fa5470aa..000000000--- a/src/analytics/events.js+++ /dev/null@@ -1,13 +0,0 @@-import { Event } from './google-analytics'--export function CopyAttribution(type, text) {- return new Event('Attribution Copy', type, text)-}--export function DonateLinkClick(location) {- return new Event('Donation', 'Click', location)-}--export function DonateBannerClose() {- return new Event('Donation', 'Close')-}diff --git a/src/analytics/google-analytics.js b/src/analytics/google-analytics.jsdeleted file mode 100644index 6de7c1eea..000000000--- a/src/analytics/google-analytics.js+++ /dev/null@@ -1,63 +0,0 @@-function doNotTrackEnabled() {- // Standard IE 9/10 IE11/MS Edge- return navigator.doNotTrack || navigator.msDoNotTrack || window.doNotTrack-}--function isTrackingEnabled() {- if (typeof window === 'undefined' || typeof navigator === 'undefined') {- return false- }-- const gaAvailable = window.ga !== null && window.ga !== undefined-- if (!gaAvailable) {- console.warn('Google Analytics is unavailable. Unable to send any events.')- }-- return gaAvailable && !doNotTrackEnabled()-}--function sendEvent(event) {- window.ga('send', event)-}--function sendPageView() {- sendEvent('pageview')-}--function set(field, params) {- window.ga('set', field, params)-}--function setCurrentPage(to) {- set('page', to.fullPath)-}--const GoogleAnalytics = () => {- const enabled = isTrackingEnabled()- return {- sendPageView(to) {- if (enabled) {- setCurrentPage(to)- sendPageView()- }- },- sendEvent(event) {- if (enabled) {- sendEvent(event)- }- },- }-}--export default GoogleAnalytics--export function Event(category, action, label = '', value = 0) {- return {- hitType: 'event',- eventCategory: category,- eventAction: action,- eventLabel: label,- eventValue: value,- }-}diff --git a/src/components/VMediaInfo/VCopyLicense.vue b/src/components/VMediaInfo/VCopyLicense.vueindex 41183b62f..4b196debf 100644--- a/src/components/VMediaInfo/VCopyLicense.vue+++ b/src/components/VMediaInfo/VCopyLicense.vue@@ -157,8 +157,7 @@ import {useContext,} from '@nuxtjs/composition-api'import CopyButton from '~/components/CopyButton.vue'-import { COPY_ATTRIBUTION } from '~/constants/action-types'-import { ATTRIBUTION, USAGE_DATA } from '~/constants/store-modules'+import { USAGE_DATA } from '~/constants/store-modules'import {SEND_DETAIL_PAGE_EVENT,DETAIL_PAGE_EVENTS,@@ -211,11 +210,7 @@ const VCopyLicense = defineComponent({const onSourceLinkClicked = () =>sendDetailPageEvent(DETAIL_PAGE_EVENTS.SOURCE_CLICKED)- const onCopyAttribution = (type, event) => {- store.dispatch(`${ATTRIBUTION}/${COPY_ATTRIBUTION}`, {- type,- content: event.content,- })+ const onCopyAttribution = () => {sendDetailPageEvent(DETAIL_PAGE_EVENTS.ATTRIBUTION_CLICKED)}diff --git a/src/constants/action-types.js b/src/constants/action-types.jsindex 66879e9fc..0f0782ea5 100644--- a/src/constants/action-types.js+++ b/src/constants/action-types.js@@ -3,7 +3,6 @@ export const FETCH_MEDIA_PROVIDERS = 'FETCH_MEDIA_PROVIDERS'export const FETCH_MEDIA_ITEM = 'FETCH_MEDIA_ITEM'export const FETCH_MEDIA = 'FETCH_MEDIA'export const FETCH_SINGLE_MEDIA_TYPE = 'FETCH_SINGLE_MEDIA_TYPE'-export const COPY_ATTRIBUTION = 'COPY_ATTRIBUTION'export const HANDLE_MEDIA_ERROR = 'HANDLE_MEDIA_ERROR'export const TOGGLE_FILTER = 'TOGGLE_FILTER'export const UPDATE_SEARCH_TYPE = 'UPDATE_SEARCH_TYPE'diff --git a/src/constants/store-modules.js b/src/constants/store-modules.jsindex 7125aee15..5b3d05fc6 100644--- a/src/constants/store-modules.js+++ b/src/constants/store-modules.js@@ -1,6 +1,5 @@export const RELATED = 'related'export const ACTIVE = 'active'-export const ATTRIBUTION = 'attribution'export const PROVIDER = 'provider'export const NAV = 'nav'export const NOTIFICATION = 'notification'diff --git a/src/plugins/ga.js b/src/plugins/ga.jsdeleted file mode 100644index 8592cd750..000000000--- a/src/plugins/ga.js+++ /dev/null@@ -1,47 +0,0 @@-import stringToBoolean from '~/utils/string-to-boolean'-import GoogleAnalytics from '~/analytics/google-analytics'--/* eslint-disable */-export default ({ app }) => {- // Exit early if analytics is diasabled- if (!stringToBoolean(process.env.enableGoogleAnalytics)) {- return- }-- /*- ** Include Google Analytics Script- */- ;(function (i, s, o, g, r, a, m) {- i['GoogleAnalyticsObject'] = r- ;(i[r] =- i[r] ||- function () {- ;(i[r].q = i[r].q || []).push(arguments)- }),- (i[r].l = 1 * new Date())- ;(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0])- a.async = 1- a.src = g- m.parentNode.insertBefore(a, m)- })(- window,- document,- 'script',- 'https://www.google-analytics.com/analytics.js',- 'ga'- )- /*- ** Set the current page- */- ga('create', process.env.googleAnalyticsUA, 'auto')-- // Initialize helper- const analytics = GoogleAnalytics()-- /*- ** Every time the route changes (fired on initialization too)- */- app.router.afterEach((to, _) => {- analytics.sendPageView(to)- })-}diff --git a/src/store/attribution.js b/src/store/attribution.jsdeleted file mode 100644index 0180aa70c..000000000--- a/src/store/attribution.js+++ /dev/null@@ -1,12 +0,0 @@-import GoogleAnalytics from '~/analytics/google-analytics'-import { CopyAttribution } from '~/analytics/events'-import { COPY_ATTRIBUTION } from '~/constants/action-types'--export const createActions = (googleAnalytics) => ({- [COPY_ATTRIBUTION](_, params) {- const event = CopyAttribution(params.type, params.content)- googleAnalytics().sendEvent(event)- },-})--export const actions = createActions(GoogleAnalytics)diff --git a/src/utils/env.js b/src/utils/env.jsindex ae5c11a4e..304ac8111 100644--- a/src/utils/env.js+++ b/src/utils/env.js@@ -7,8 +7,6 @@ import stringToBoolean from './string-to-boolean'*/export const env = {apiUrl: process.env.API_URL ?? 'https://api.openverse.engineering/v1/',- enableGoogleAnalytics: stringToBoolean(process.env.ENABLE_GOOGLE_ANALYTICS),- googleAnalyticsUA: process.env.GOOGLE_ANALYTICS_UA ?? 'UA-2010376-36',filterStorageKey: 'openverse-filter-visibility',notificationStorageKey: 'openverse-show-notification',enableInternalAnalytics: stringToBoolean(diff --git a/test/unit/specs/components/ImageDetails/v-copy-license.spec.js b/test/unit/specs/components/ImageDetails/v-copy-license.spec.jsindex 0c103c3bb..f1f5952fd 100644--- a/test/unit/specs/components/ImageDetails/v-copy-license.spec.js+++ b/test/unit/specs/components/ImageDetails/v-copy-license.spec.js@@ -1,12 +1,11 @@import VCopyLicense from '~/components/VMediaInfo/VCopyLicense.vue'-import { COPY_ATTRIBUTION } from '~/constants/action-types'import {DETAIL_PAGE_EVENTS,SEND_DETAIL_PAGE_EVENT,} from '~/constants/usage-data-analytics-types'import render from '../../../test-utils/render'-import { ATTRIBUTION, USAGE_DATA } from '~/constants/store-modules'+import { USAGE_DATA } from '~/constants/store-modules'describe('VCopyLicense', () => {let options = null@@ -57,18 +56,6 @@ describe('VCopyLicense', () => {expect(wrapper.find('.copy-license')).toBeDefined()})- it('should dispatch COPY_ATTRIBUTION', () => {- const wrapper = render(VCopyLicense, options)- wrapper.vm.onCopyAttribution(copyData.type, copyData.event)- expect(dispatchMock).toHaveBeenCalledWith(- `${ATTRIBUTION}/${COPY_ATTRIBUTION}`,- {- type: copyData.type,- content: copyData.event.content,- }- )- })-it('should dispatch SEND_DETAIL_PAGE_EVENT on copy attribution', () => {const wrapper = render(VCopyLicense, options)wrapper.vm.onCopyAttribution(copyData.type, copyData.event)diff --git a/test/unit/specs/store/attribution.spec.js b/test/unit/specs/store/attribution.spec.jsdeleted file mode 100644index 4837e3d7f..000000000--- a/test/unit/specs/store/attribution.spec.js+++ /dev/null@@ -1,29 +0,0 @@-import { createActions } from '~/store/attribution'-import { CopyAttribution } from '~/analytics/events'-import { COPY_ATTRIBUTION } from '~/constants/action-types'--describe('Attribution Store', () => {- describe('actions', () => {- let gaInstance = null- let googleAnalyticsMock = null- let actions = null-- beforeEach(() => {- gaInstance = { sendEvent: jest.fn() }- googleAnalyticsMock = jest.fn(() => gaInstance)- actions = createActions(googleAnalyticsMock)- })-- it('COPY_ATTRIBUTION sends copy event', () => {- const data = {- type: 'HTML Whatever',- content: '<div>foo</div>',- }- actions[COPY_ATTRIBUTION]({}, data)-- expect(googleAnalyticsMock().sendEvent).toHaveBeenCalledWith(- new CopyAttribution(data.type, data.content)- )- })- })-})