Skip to content

Commit

Permalink
Merge pull request #1739 from laws-africa/matomo
Browse files Browse the repository at this point in the history
track pageviews for search; matomo site language
  • Loading branch information
longhotsummer authored Feb 23, 2024
2 parents b224f57 + 56ebb64 commit 470903b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions peachjam/js/components/FindDocuments/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ import AdvancedSearch from './AdvancedSearch.vue';
import HelpBtn from '../HelpBtn.vue';
import { scrollToElement } from '../../utils/function';
import FacetBadges from './FacetBadges.vue';
import analytics from '../analytics';
function resetAdvancedFields (fields) {
const advanced = ['all', 'title', 'judges', 'case_summary', 'flynote', 'content'];
Expand Down Expand Up @@ -636,6 +637,7 @@ export default {
'',
document.location.pathname + '?' + this.serialiseState()
);
analytics.trackPageView();
}
const response = await fetch(url);
Expand Down
27 changes: 27 additions & 0 deletions peachjam/js/components/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Helper class to do common analytics tracking across both GA and Matomo.
*/
export class Analytics {
isGAEnabled: boolean;
isMatomoEnabled: boolean;
gtag: any;
paq: any[];

constructor () {
this.isGAEnabled = 'gtag' in window;
this.isMatomoEnabled = '_paq' in window;

// @ts-ignore
this.gtag = this.isGAEnabled ? window.gtag : () => {};
// @ts-ignore
this.paq = this.isMatomoEnabled ? window._paq : [];
}

trackPageView () {
this.paq.push(['trackPageView']);
this.gtag('event', 'page_view');
}
}

const analytics = new Analytics();
export default analytics;
2 changes: 1 addition & 1 deletion peachjam/static/js/app-prod.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions peachjam/templates/peachjam/layouts/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
var _paq = window._paq = window._paq || [];
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['setCustomDimension', 1, '{{ CURRENT_LANGUAGE }}']);
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
Expand Down

0 comments on commit 470903b

Please sign in to comment.