Skip to content
Snippets Groups Projects
Commit 77a95649 authored by Emmanuel Raviart's avatar Emmanuel Raviart
Browse files

Don't fail when window._paq is undefined

parent 2c51f6b0
Branches
Tags
No related merge requests found
Pipeline #10997 passed
...@@ -3,6 +3,8 @@ import type { ParametricReform } from "$lib/reforms" ...@@ -3,6 +3,8 @@ import type { ParametricReform } from "$lib/reforms"
function trackEvent(category: string, action: string, name: string) { function trackEvent(category: string, action: string, name: string) {
if (browser) { if (browser) {
// @ts-expect-error: global variable needed by Matomo.
window._paq ??= []
// @ts-expect-error: global variable needed by Matomo. // @ts-expect-error: global variable needed by Matomo.
const _paq = window._paq const _paq = window._paq
_paq.push(["trackEvent", category, action, name]) _paq.push(["trackEvent", category, action, name])
...@@ -27,6 +29,8 @@ function trackEvent(category: string, action: string, name: string) { ...@@ -27,6 +29,8 @@ function trackEvent(category: string, action: string, name: string) {
function trackSearch(query: string, category: string, resultCount: number) { function trackSearch(query: string, category: string, resultCount: number) {
if (browser) { if (browser) {
// @ts-expect-error: global variable needed by Matomo.
window._paq ??= []
// @ts-expect-error: global variable needed by Matomo. // @ts-expect-error: global variable needed by Matomo.
const _paq = window._paq const _paq = window._paq
_paq.push([ _paq.push([
...@@ -42,6 +46,8 @@ function trackSearch(query: string, category: string, resultCount: number) { ...@@ -42,6 +46,8 @@ function trackSearch(query: string, category: string, resultCount: number) {
// function trackSearchResult(category: string, resultValue: string) { // function trackSearchResult(category: string, resultValue: string) {
// if (browser) { // if (browser) {
// // @ts-expect-error: global variable needed by Matomo. // // @ts-expect-error: global variable needed by Matomo.
// window._paq ??= []
// // @ts-expect-error: global variable needed by Matomo.
// const _paq = window._paq // const _paq = window._paq
// _paq.push([ // _paq.push([
// "setCustomUrl", // "setCustomUrl",
...@@ -85,6 +91,8 @@ export function trackSearchVariable( ...@@ -85,6 +91,8 @@ export function trackSearchVariable(
export function trackPageView(url: URL, prependDomain: boolean | undefined) { export function trackPageView(url: URL, prependDomain: boolean | undefined) {
if (browser) { if (browser) {
// @ts-expect-error: global variable needed by Matomo.
window._paq ??= []
// @ts-expect-error: global variable needed by Matomo. // @ts-expect-error: global variable needed by Matomo.
const _paq = window._paq const _paq = window._paq
_paq.push(["setCustomUrl", url.pathname + url.search]) _paq.push(["setCustomUrl", url.pathname + url.search])
...@@ -101,6 +109,8 @@ export function trackParametricReform( ...@@ -101,6 +109,8 @@ export function trackParametricReform(
prependDomain: boolean | undefined, prependDomain: boolean | undefined,
) { ) {
if (browser) { if (browser) {
// @ts-expect-error: global variable needed by Matomo.
window._paq ??= []
// @ts-expect-error: global variable needed by Matomo. // @ts-expect-error: global variable needed by Matomo.
const _paq = window._paq const _paq = window._paq
_paq.push([ _paq.push([
......
...@@ -687,7 +687,7 @@ ...@@ -687,7 +687,7 @@
url: string url: string
}) { }) {
// @ts-expect-error: global variable needed by Matomo. // @ts-expect-error: global variable needed by Matomo.
window._paq = window._paq ?? [] window._paq ??= []
// @ts-expect-error: global variable needed by Matomo. // @ts-expect-error: global variable needed by Matomo.
const _paq = window._paq const _paq = window._paq
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment