Skip to content

Improve detection of GA3 and GA4 to more accurately suggest correct tracking set up guides #20380

@tsteur

Description

@tsteur

In some other plugin we're detecting GA based on these rules:

//only one of these has to match to detect ga3, ga4 or gtm
        $this->tests['GA3'][] = "/UA-\d{5,}-\d{1,}/";
        $this->tests['GA3'][] = "/google\-analytics\.com\/analytics\.js/";
        $this->tests['GA3'][] = "/window\.ga\s?=\s?window\.ga/";
        $this->tests['GA3'][] = "/google[ _\-]{0,1}analytics/i";

        // GA4 Measurement ID
        $this->tests['GA4'][] = "/properties\/[^\/]/";
        $this->tests['GA4'][] = "/G-[A-Z0-9]{7,10}/";
        $this->tests['GA4'][] = "/gtag\/js\?id=G-/";

and also additionally for GTM we can look for this
        $this->tests['GTM'][] = "/googletagmanager/i";
        $this->tests['GTM'][] = "/gtm\.start/i";

Noticed we have two different detections for this in core in SiteContentDetector and GtmSiteTypeGuesser. And we currently might not detect as many GA installs as we could

Metadata

Metadata

Assignees

Labels

EnhancementFor new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions