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

Matomo tracking #109

Merged
merged 19 commits into from
Nov 20, 2020
Merged

Matomo tracking #109

merged 19 commits into from
Nov 20, 2020

Conversation

donni106
Copy link
Member

@donni106 donni106 commented Oct 20, 2020

Implemented a Matomo class and created a useMatomo hook to provide several methods for tracking.

I have created an own package for our solution https://github.com/donni106/matomo-tracker-react-native. This makes it possible to use Matomo with Expo. The Matomo code is inspired by https://github.com/matomo-org/matomo-nodejs-tracker and https://github.com/Amsterdam/matomo-tracker.
https://github.com/BonifyByForteil/react-native-matomo does not work with Expo as it needs native modules. A feature request at Expo is not answered yet: https://expo.canny.io/feature-requests/p/matomo-tracking-integration

This PR was in process with different TODOs:

  • create own package and use it here
  • create uuid for a user and send as userId
  • move matomo setup at first place on app start
  • implement tracking per own hooks
  • implement tracking on defined places/actions
  • do not try to track when offline
  • fallback on error of matomo setup in App.js to render the app anyways
  • add user consent => will be a new PR later => combine settings and matomo #125

ℹ️ Please read the commit messages for further descriptions.

Listings in Matomo web interface:

1 2
Bildschirmfoto 2020-11-19 um 17 19 25 Bildschirmfoto 2020-11-19 um 17 19 46

@donni106 donni106 added the enhancement New feature or request label Oct 20, 2020
@donni106 donni106 self-assigned this Oct 20, 2020
@donni106 donni106 changed the title [WIP] Matomo tracking WIP: Matomo tracking Oct 20, 2020
@donni106 donni106 changed the title WIP: Matomo tracking [WIP]: Matomo tracking Oct 20, 2020
@donni106 donni106 changed the title [WIP]: Matomo tracking [WIP] Matomo tracking Oct 20, 2020
@donni106 donni106 force-pushed the feature/SVA-63-matomo-tracking branch 2 times, most recently from 064d1d9 to 4393a1d Compare October 23, 2020 13:37
@donni106 donni106 marked this pull request as draft November 11, 2020 13:11
donni106 and others added 5 commits November 17, 2020 12:27
- moved `const namespace...` to be available in the whole file
- added `matomoUrl` and `matomoSiteId` in secrets

SVA-63
- added tracking for app start
- added tracking for mounting home screen

SVA-63
- added package `matomo-tracker-react-native`
- removed Matomo files in code used before

SVA-63
- added __DEV__ to globals in eslint config, to not argue about
  it being not defined when using it elsewhere
@donni106 donni106 force-pushed the feature/SVA-63-matomo-tracking branch from ab0507c to bce6b07 Compare November 17, 2020 11:28
@donni106 donni106 requested a review from digorath November 17, 2020 11:52
- added react-native-get-random-values
  - https://github.com/LinusU/react-native-get-random-values
  - works with Expo since SDK 39
    - uuidjs/uuid#515
- with that package we are able to create uuids for several
  use cases, like the matomo user id

SVA-63
- created a central place for the namespace to avoid
  redundant creation of consts
- added storage helper methods for accessing the local storage
  for `matomoSettings`
- created a general method `matomoSettings` with reading and writing matomo
  settings from and to the local storage on app startup
  - create user id for matomo tracking using
    react-native-get-random-values
- created methods for directly creating and deleting the
  user id in the matomo settings in the local storage

SVA-63
@donni106 donni106 force-pushed the feature/SVA-63-matomo-tracking branch from 9b81aba to 52429ea Compare November 18, 2020 10:17
- refactored matomo setup to be done at very first when starting the app,
  because otherwise the tracking for app start is fired too late
- removed everything matomo related from /src/index.js
- added two comments describing the order of processing the effects
- added matomo setup in App.js
  - used the new matomo settings helper for creating the instance
    with an user ID and regarding the consent for enabling/disabling
- created a new component `AppWithFonts` for setting up fonts,
  with the addition to set `fontsLoaded` always to `true`, even if
  there is an error, because we can show the app without the correct font
  in that case
  - maybe we want to add fallback font families elsewhere?
- added the first matomo tracking for app start in `AppWithFonts` which is
  a possible here as it is a child component of the matomo provider with
  the created matomo instance

SVA-63
- updated method calls for `SplashScreen` as we get deprecation warnings:
  - SplashScreen.preventAutoHide() is deprecated in favour of SplashScreen.preventAutoHideAsync()
  - SplashScreen.hide() is deprecated in favour of SplashScreen.hideAsync()
@donni106 donni106 force-pushed the feature/SVA-63-matomo-tracking branch from 52429ea to 8961d1d Compare November 18, 2020 10:23
- created hooks for matomo tracking actions
- refactored app start and home screen tracking to use
  new hooks
- added web screen tracking with new hook

SVA-63
@donni106 donni106 added this to the 1.4.0 milestone Nov 18, 2020
@donni106 donni106 removed the request for review from marcometz November 18, 2020 10:34
App.js Outdated Show resolved Hide resolved
- if matomo setup fails, we still want to render the app
- therefore we add an error object, which we can check at rendering,
  to avoid the matomo provider

SVA-63
src/hooks/matomoHooks.js Outdated Show resolved Hide resolved
- removed the hook as it is just used once in App.js, where
  it can be implemented directly

SVA-63
@donni106 donni106 changed the title [WIP] Matomo tracking Matomo tracking Nov 19, 2020
@donni106 donni106 marked this pull request as ready for review November 19, 2020 16:01
@donni106 donni106 requested a review from digorath November 19, 2020 16:01
@donni106
Copy link
Member Author

donni106 commented Nov 19, 2020

ℹ️ user consent is still missing. this will follow in a separate PR, when the settings screen is done. therefore i will also checkup @digoraths implementation of Alert for push notifications, to do it in the same way.

@smart-village-solutions smart-village-solutions deleted a comment from codeclimate bot Nov 19, 2020
- added consts to use in tracking strings
- added helper to build tracking strings from an array with data
- added `useMatomoTrackScreenView` in every screen and detail component
  to send the request for tracking on mounting
  - added `isConnected` in the hook to jsut send data if the user
    has network connectivity
  - in `HtmlScreen` and `IndexScreen` the hook could not be used, as we need
    useEffect dependencies there
    - added custom integration for these two screens
- added keys to queries for event records, news items and tours, which are
  needed in order to set a correct tracking string

SVA-63
@donni106 donni106 force-pushed the feature/SVA-63-matomo-tracking branch from 276034b to 4a57d01 Compare November 19, 2020 16:10
Copy link
Contributor

@digorath digorath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not everything has to be fixed in this PR.

But if you agree on the general structure for FCs then we should move the matomo hooks to the "correct" spot inside of the components.

most of the points where useCallbacks should be used are related to the future introduction of the refresh time hook, and could be ignored in this pr, because they only mean minor performance improvements.

src/components/TextList.js Outdated Show resolved Hide resolved
src/components/TextList.js Show resolved Hide resolved
src/components/TextList.js Show resolved Hide resolved
src/components/screens/EventRecord.js Outdated Show resolved Hide resolved
src/components/screens/NewsItem.js Outdated Show resolved Hide resolved
src/screens/AboutScreen.js Outdated Show resolved Hide resolved
src/screens/CompanyScreen.js Show resolved Hide resolved
src/screens/CompanyScreen.js Outdated Show resolved Hide resolved
src/screens/HomeScreen.js Outdated Show resolved Hide resolved
src/screens/WebScreen.js Outdated Show resolved Hide resolved
@donni106
Copy link
Member Author

most of the points where useCallbacks should be used are related to the future introduction of the refresh time hook, and could be ignored in this pr, because they only mean minor performance improvements.

agree! let's track that for the refresh time update first with keeping in mind for other context. cannot handle this refactoring related to the matomo topics here.

- moved the method out of the component because it has no dependency on it,
  so it does not need to be re-created everytime with re-rendering
- moved `useMatomoTrackScreenView` up in components to
  have it structured in one place before `useEffect`s
- moved destructing `consts` out of components, because there is
  no dependency

SVA-63
- added `useEffect` for `WebScreen` to handle `webUrl` dependency
- added check for `title` in `HtmlScreen` to not track if it is not present
- moved early return because of undefined `query` in `IndexScreen`
  and added check for `query` inside of `useEffect` that depends on
  that variable in order to not track if it is not present

SVA-63
@ghost
Copy link

ghost commented Nov 20, 2020

Congratulations 🎉. DeepCode analyzed your code in 13.787 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@smart-village-solutions smart-village-solutions deleted a comment from codeclimate bot Nov 20, 2020
@donni106 donni106 requested a review from digorath November 20, 2020 13:12
@donni106 donni106 merged commit a0abd5b into master Nov 20, 2020
@donni106 donni106 deleted the feature/SVA-63-matomo-tracking branch November 24, 2020 14:45
Copy link
Member

@SoleCincis SoleCincis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants