Skip to content

Commit

Permalink
Merge pull request #16 from EyeSeeTea/feature/add-ga4
Browse files Browse the repository at this point in the history
Add Google Analytics 4 and remove feedback
  • Loading branch information
adrianq authored Feb 12, 2024
2 parents 32858f0 + 8bd82f6 commit 57df58e
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 81 deletions.
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
BROWSER=false
PORT=8081
BROWSER=false
SKIP_PREFLIGHT_CHECK=true

REACT_APP_DHIS2_BASE_URL=http://localhost:8080
REACT_APP_GOOGLE_ANALYTICS_4='Your GA4 code'
REACT_APP_DHIS2_AUTH=admin:district

CYPRESS_DHIS2_AUTH='admin:district'
CYPRESS_EXTERNAL_API="https://dev.eyeseetea.com/play"
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# home-page-app-dev
Home Page app is a DHIS2 app that allows to create dynamic landing pages in DHIS2

### Google analytics

In order to send home page views to Google Analytics, the GA4 code must be provided in the ```.env``` file under ```REACT_APP_GOOGLE_ANALYTICS_4='Your GA4 code'```.
1 change: 0 additions & 1 deletion public/feedback-tool/feedback-dhis2.min.js

This file was deleted.

1 change: 0 additions & 1 deletion public/feedback-tool/feedback-github.min.js

This file was deleted.

1 change: 0 additions & 1 deletion public/feedback-tool/feedback.min.css

This file was deleted.

6 changes: 0 additions & 6 deletions public/feedback-tool/feedback.min.js

This file was deleted.

31 changes: 0 additions & 31 deletions public/feedback-tool/i18n/en.properties

This file was deleted.

31 changes: 0 additions & 31 deletions public/feedback-tool/i18n/es.properties

This file was deleted.

Binary file removed public/feedback-tool/icons.png
Binary file not shown.
Binary file removed public/feedback-tool/spinner.gif
Binary file not shown.
15 changes: 8 additions & 7 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<script async src="https://www.googletagmanager.com/gtag/js?id=%REACT_APP_GOOGLE_ANALYTICS_4%"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', '%REACT_APP_GOOGLE_ANALYTICS_4%');
</script>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/icon-sm.png" sizes="192x192" />
<link rel="icon" href="%PUBLIC_URL%/icon-small.png" sizes="192x192" />
Expand All @@ -21,13 +29,6 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Homepage App</title>

<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script src="%PUBLIC_URL%/feedback-tool/feedback.min.js"></script>
<script src="%PUBLIC_URL%/feedback-tool/feedback-github.min.js"></script>
<script src="%PUBLIC_URL%/feedback-tool/feedback-dhis2.min.js"></script>

<link rel="stylesheet" href="%PUBLIC_URL%/feedback-tool/feedback.min.css" />
</head>
<body>
<noscript> You need to enable JavaScript to run this app. </noscript>
Expand Down
3 changes: 3 additions & 0 deletions src/data/repositories/InstanceDhisRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export class InstanceDhisRepository implements InstanceRepository {

@cache()
public async isAppInstalledByUrl(launchUrl: string): Promise<boolean> {
const isUrlRelative = launchUrl.startsWith("/");
if (!isUrlRelative) return false;

try {
await this.api.baseConnection.request({ method: "get", url: launchUrl }).getData();
} catch (error: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import "./webapp/utils/wdyr";

declare global {
interface Window {
$: { feedbackDhis2(d2: object, appKey: string, feedbackOptions: object): void };
api: D2Api;
gtag: (...args: any[]) => void;
dataLayer: any[];
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/webapp/utils/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function sendAnalytics(name: string, data?: object) {
if (!window.gtag) throw new Error("gtag() function has not been declared.");
window.gtag(
"event",
name,
data
// Relevant params to track. Only add if the client allows it
// data && {
// ...data,
// location_hash: window.location.hash,
// location_pathname: window.location.pathname,
// location_href: window.location.href,
// }
);
}

0 comments on commit 57df58e

Please sign in to comment.