Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Matomo tracking #633

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
| sed s/{CODA_TOKEN}/${{ secrets.CODA_TOKEN }}/ \
| sed s/{CODA_INCOMING_TOKEN}/${{ secrets.CODA_INCOMING_TOKEN }}/ \
| sed s/{CODA_WRITES_TOKEN}/${{ secrets.CODA_WRITES_TOKEN }}/ \
| sed s/{GOOGLE_ANALYTICS_ID}/${{ secrets.GOOGLE_ANALYTICS_ID }}/ \
| sed s/{MATOMO_DOMAIN}/${{ secrets.MATOMO_DOMAIN }}/ \
> wrangler.toml
npm ci
npm run deploy
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
| sed s/{CODA_TOKEN}/${{ secrets.CODA_TOKEN }}/ \
| sed s/{CODA_INCOMING_TOKEN}/${{ secrets.CODA_INCOMING_TOKEN }}/ \
| sed s/{CODA_WRITES_TOKEN}/${{ secrets.CODA_WRITES_TOKEN }}/ \
| sed s/{GOOGLE_ANALYTICS_ID}/${{ secrets.GOOGLE_ANALYTICS_ID }}/ \
| sed s/{MATOMO_DOMAIN}/${{ secrets.MATOMO_DOMAIN }}/ \
> wrangler.toml
npm ci
npm run deploy
Expand Down
46 changes: 23 additions & 23 deletions app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,31 @@ export const loader = async ({request}: Parameters<LoaderFunction>[0]) => {
url: request.url,
embed,
showSearch,
gaTrackingId: GOOGLE_ANALYTICS_ID,
matomoDomain: MATOMO_DOMAIN,
}
}

const GoogleAnalytics = ({gaTrackingId}: {gaTrackingId?: string}) => {
if (!gaTrackingId) return null
const AnaliticsTag = ({matomoDomain}: {matomoDomain?: string}) => {
if (!matomoDomain) return null
return (
<>
<script async src={`https://www.googletagmanager.com/gtag/js?id=${gaTrackingId}`} />
<script
async
id="gtag-init"
dangerouslySetInnerHTML={{
__html: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '${gaTrackingId}', {
page_path: window.location.pathname,
});
`,
}}
/>
</>
<script
async
dangerouslySetInnerHTML={{
__html: `
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://${matomoDomain}.matomo.cloud/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '3']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src='https://cdn.matomo.cloud/${matomoDomain}.matomo.cloud/matomo.js'; s.parentNode.insertBefore(g,s);
})();`,
}}
/>
)
}

Expand Down Expand Up @@ -182,7 +182,7 @@ type Loader = Awaited<ReturnType<typeof loader>>
export type Context = Pick<Loader, 'embed' | 'showSearch'>

export default function App() {
const {embed, showSearch, gaTrackingId} = useLoaderData<Loader>()
const {embed, showSearch, matomoDomain} = useLoaderData<Loader>()
const {savedTheme} = useTheme()
const context: Context = {embed, showSearch}

Expand All @@ -208,7 +208,7 @@ export default function App() {

return (
<BasePage embed={embed} savedTheme={savedTheme}>
<GoogleAnalytics gaTrackingId={gaTrackingId} />
<AnaliticsTag matomoDomain={matomoDomain} />
<Outlet context={context} />
<ScrollRestoration />
<Scripts />
Expand Down
2 changes: 1 addition & 1 deletion remix.env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ declare const CODA_INCOMING_TOKEN: string
declare const CODA_WRITES_TOKEN: string
declare const NLP_SEARCH_ENDPOINT: string
declare const ALLOW_ORIGINS: string
declare const GOOGLE_ANALYTICS_ID: string
declare const MATOMO_DOMAIN: string
2 changes: 1 addition & 1 deletion wrangler.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ CODA_INCOMING_TOKEN = "{CODA_INCOMING_TOKEN}"
CODA_WRITES_TOKEN = "{CODA_WRITES_TOKEN}"
NLP_SEARCH_ENDPOINT = "https://stampy-nlp-t6p37v2uia-uw.a.run.app/"
ALLOW_ORIGINS = "https://chat.aisafety.info"
GOOGLE_ANALYTICS_ID = "{GOOGLE_ANALYTICS_ID}"
MATOMO_DOMAIN = "{MATOMO_DOMAIN}"
Loading