Skip to content

Detect GA3, GA4 or GTM during installation and suggest migration guides #19957

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

Merged
merged 34 commits into from
Nov 13, 2022

Conversation

bx80
Copy link
Contributor

@bx80 bx80 commented Nov 6, 2022

Description:

Checks for GA3, GA4 or GTM usage on a site when showing the tracking code / getting started screen and if present, will show a link to the appropriate guide on how to migrate to Matomo.

Ref: DEV-3005

Review

Ben and others added 23 commits September 30, 2022 12:35
…mail these instuctions' button, add consent manager link to instructions email, add link to the privacy 'asking for consent' page
…or site content test data, added UI tests for consent manager detection
@bx80 bx80 added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Nov 6, 2022
@bx80 bx80 added this to the 4.12.4 milestone Nov 6, 2022
@bx80 bx80 self-assigned this Nov 6, 2022
@bx80 bx80 added the Needs Review PRs that need a code review label Nov 7, 2022
…dded new fixture to installation UI test to prevent site content detection request
@peterhashair peterhashair removed the Needs Review PRs that need a code review label Nov 9, 2022
@bx80
Copy link
Contributor Author

bx80 commented Nov 9, 2022

The installation test was failing because the site content detection values required by the instructions email and tracking code templates were not being populated for fresh installs. I've updated the installation controller to do a site content detection request as part of the install wizard and provide the required values. I've also added a new fixture which will mock the site content detector finding nothing on the site and added this to the installation UI test so that the test doesn't make live requests to the test site.

@peterhashair
Copy link
Contributor

peterhashair commented Nov 9, 2022

@bx80 installation works now, once the tests are passed, will do another review :)

Copy link
Contributor

@peterhashair peterhashair left a comment

Choose a reason for hiding this comment

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

Reviewed functionality and code, working as expected.
The only I am wondering about in the SiteContentDetector class, there is a set of test data for the fixture, which works for me, not sure if there is a different approach.

@bx80
Copy link
Contributor Author

bx80 commented Nov 9, 2022

@peterhashair If you mean the data in the getConsentManagerDefinitions() method, that's not test data, it's the data used to detect the known consent managers and their guide URLs. This PR is branched from #19821, which is where that code is used. We could move the definitions to a set of external files, but I can't see much benefit to this.

@peterhashair
Copy link
Contributor

@bx80 sorry I mean, those functions private function checkForTestData() : bool below that as well.

@bx80
Copy link
Contributor Author

bx80 commented Nov 10, 2022

@peterhashair The site content detector gets called as part of the UI tests and while it's possible to mock class methods using PHPUnit for unit tests, I haven't seen a good way to do this with UI tests which will interact with the class method by way of an API call. The nearest existing pattern I found in the codebase was the location provider where a mock location provider class is set as the default provider via an option setting. The approach here is broadly similar, where the test fixture can set test data as an option and the class will check for it and return the test data values if they exist. Not the most elegant solution, but it works and is flexible. I'm open to better ideas though,

@sgiehl Do you have a recommended approach for this scenario?

@sgiehl
Copy link
Member

sgiehl commented Nov 10, 2022

@sgiehl Do you have a recommended approach for this scenario?

I guess we have this solved in various ways. I haven't had a look at the detailed solution here. But I guess I would have tried to somehow solve it using DI. So the class responsible for the detection is loaded using DI. And for ui tests, you could then overwrite the used class with some sort of test class, that returns fake response.

@bx80
Copy link
Contributor Author

bx80 commented Nov 11, 2022

Thanks @sgiehl, I've reworked the UI tests to use DI 👍

@bx80 bx80 added the Needs Review PRs that need a code review label Nov 13, 2022
Copy link
Contributor

@peterhashair peterhashair left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@peterhashair peterhashair merged commit 71dcd54 into 4.x-dev Nov 13, 2022
@peterhashair peterhashair deleted the detect-ga-suggest-guide branch November 13, 2022 20:34
@elabuwa elabuwa removed the Needs Review PRs that need a code review label Nov 22, 2022
{% endif %}

{% if ga4Used %}
{{ 'SitesManager_GA4DetectedEmail'|translate('Google Analytics 4', 'GA', 'https://matomo.org/faq/how-to/migrate-from-google-analytics-4-to-matomo/')|raw }}
Copy link
Contributor

Choose a reason for hiding this comment

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

@bx80 @sgiehl I cannot seem to find the translation for GA4DetectedEmail and GTMDetectedEmail in the translation file is this a bug ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Its a bug, have fixed it in my upcoming Pr for cloudflare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Development

Successfully merging this pull request may close these issues.

5 participants