-
Notifications
You must be signed in to change notification settings - Fork 2k
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
A4A: Setup Google Analytics. #90805
base: trunk
Are you sure you want to change the base?
A4A: Setup Google Analytics. #90805
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
) => { | ||
if ( isJetpackEnv ) { | ||
return TRACKING_IDS.jetpackGoogleAnalyticsGtag; | ||
} else if ( isAkismetEnv ) { | ||
return TRACKING_IDS.akismetGoogleAnalyticsGtag; | ||
} else if ( isA4AEnv ) { | ||
return TRACKING_IDS.a4aGoogleGA4GTag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I need a separate tracking ID here? It seems that Jetpack and Akismet are using different tags. I'm not sure whats the difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the tracking IDs is for Google Analytics previous to GA4. One of them starts with UA-
and GA4 codes start with G-
the one that you have. I am not sure if we absolutely need to have both, I'll defer to @robertsreberski on that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't need both, I'd say we should remove A4A from this getGaGtag
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all UA (Universal Analytics). It's a bit confusing because the Gtag is used across Google Products, e.g., Google Ads, Tag Manager (I think), and the old Universal Analytics.
UA does not process data anymore, and it's deprecated/read-only. These will be cleaned up, so there should be no reason to add the tag here. You can see in analytics/ad-tracking/google-analytics.js this is called in setupGoogleAnalyticsGtag
, but prior to that the other Gtag setup for GA4 is called (GA4.setup( params )
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this one is good finding 😅 It's indeed obsolete, unused code. We can write down a follow-up clean up maintenance task for that.
@@ -41,7 +41,8 @@ export function fireGoogleAnalyticsPageView( | |||
urlPath, | |||
pageTitle, | |||
useJetpackGoogleAnalytics = false, | |||
useAkismetGoogleAnalytics = false | |||
useAkismetGoogleAnalytics = false, | |||
useA4AGoogleAnalytics = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I be changing fireGoogleAnalyticsPageView
function for us to track page view?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I believe that is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's needed 👍
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~258 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Sections (~11165 bytes removed 📉 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
04fa5a1
to
c3092bc
Compare
I am Adding Martech as a reviewer to double-check that I am changing the right files and covering everything needed for the initial setup. |
Hmm, I tried functional testing per the testing instructions above, however I am not seeing any googletagmanager tracking requests... 🤔 |
@elliottprogrammer, Thank you for looking into this. You may need to sign up for an Agency account. I'll add it in the test instructions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the scope of this PR is, but to actually track the page views, I believe you have to use the PageViewTracker component defined here
Example usage:
wp-calypso/client/my-sites/checkout/checkout-thank-you/jetpack-checkout-thank-you.tsx
Lines 54 to 59 in 80157a6
<PageViewTracker | |
options={ { useJetpackGoogleAnalytics: true } } | |
path="/checkout/jetpack/thank-you/:site/:product" | |
properties={ { product_slug: productSlug } } | |
title="Checkout > Jetpack Thank You" | |
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments. :)
The setup here looks good in terms of tracking IDs, environment setup, etc. I tested by signing up for an A4A account, and I can see the Gtag being initialized.
Local testing
I tested building it locally with yarn start-a8c-for-agencies
, where I changed the development.json
config to allow ad-tracking (to avoid the URL flags). Note: I also need to add the cookie-banner
as I'm in the GDPR zone, and the trackers won't fire unless the consent is accepted.
diff --git a/config/a8c-for-agencies-development.json b/config/a8c-for-agencies-development.json
index 351c2c67fc..d7cff47031 100644
--- a/config/a8c-for-agencies-development.json
+++ b/config/a8c-for-agencies-development.json
@@ -28,7 +28,8 @@
],
"oauth_client_id": 95928,
"features": {
- "ad-tracking": false,
+ "ad-tracking": true,
+ "cookie-banner": true,
"a8c-for-agencies": true,
"a8c-for-agencies/wpcom-creator-plan-purchase-flow": true,
"a8c-for-agencies/import-site-from-wpcom": true,
I also tested removing the ID in getGaGtag
, and it works as expected (as this is old UA code).
Page views
I see recordPageView
is called from calypso/lib/analytics/page-view
. So, that should already be handled. Example in ./sections/overview/controller.tsx
.
Note: I think the default behavior in GA4 is to automatically trigger page views as well.
It tries to guess when that happens in a SPA, but it's not as predictable as firing these off ourselves. It gives us "dirty" page views, e.g. where data is not "normalized.", making it harder to see page views for a given route since the route may contain a unique parameter.
One example is http://agencies.localhost:3000/purchases/invoices
. I don't have any invoices, but I imagine the URLs like http://agencies.localhost:3000/purchases/invoices/12341234
, where we'd track the individual invoice slug, like http://agencies.localhost:3000/purchases/invoices/<id>
, instead of having many slugs with 1-2 views each (per invoice ID).
Turning off history tracking and using the page view functionality may clean up page views and prevent duplicates. Also, Google Analytics has limits on how many unique slugs it can keep track of -- so you'd get a lot of data sampling.
I checked the property, and the history-based page view detection is active (while on WPcom it's turned off). I can turn it off, or we can ship and check the data (probably the best option).
@@ -64,7 +68,7 @@ export function fireGoogleAnalyticsPageView( | |||
|
|||
window.gtag( | |||
'config', | |||
getGaGtag( useJetpackGoogleAnalytics, useAkismetGoogleAnalytics ), | |||
getGaGtag( useJetpackGoogleAnalytics, useAkismetGoogleAnalytics, useA4AGoogleAnalytics ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just leaving a note here, but I wonder if we should change this structure at some point. It seems a bit messy to pass in arguments like this. Initially, it was just for Jetpack, but it gets a bit out of hand as we keep adding sites. It's not a blocker for this, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've documented the possible improvement on our maintenance board - as it relates in a large chunk to Jetpack/Akismet use cases.
@@ -41,7 +41,8 @@ export function fireGoogleAnalyticsPageView( | |||
urlPath, | |||
pageTitle, | |||
useJetpackGoogleAnalytics = false, | |||
useAkismetGoogleAnalytics = false | |||
useAkismetGoogleAnalytics = false, | |||
useA4AGoogleAnalytics = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's needed 👍
) => { | ||
if ( isJetpackEnv ) { | ||
return TRACKING_IDS.jetpackGoogleAnalyticsGtag; | ||
} else if ( isAkismetEnv ) { | ||
return TRACKING_IDS.akismetGoogleAnalyticsGtag; | ||
} else if ( isA4AEnv ) { | ||
return TRACKING_IDS.a4aGoogleGA4GTag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all UA (Universal Analytics). It's a bit confusing because the Gtag is used across Google Products, e.g., Google Ads, Tag Manager (I think), and the old Universal Analytics.
UA does not process data anymore, and it's deprecated/read-only. These will be cleaned up, so there should be no reason to add the tag here. You can see in analytics/ad-tracking/google-analytics.js this is called in setupGoogleAnalyticsGtag
, but prior to that the other Gtag setup for GA4 is called (GA4.setup( params )
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some additional comments, but the implementation looks largely good.
) => { | ||
if ( isJetpackEnv ) { | ||
return TRACKING_IDS.jetpackGoogleAnalyticsGtag; | ||
} else if ( isAkismetEnv ) { | ||
return TRACKING_IDS.akismetGoogleAnalyticsGtag; | ||
} else if ( isA4AEnv ) { | ||
return TRACKING_IDS.a4aGoogleGA4GTag; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this one is good finding 😅 It's indeed obsolete, unused code. We can write down a follow-up clean up maintenance task for that.
@@ -64,7 +68,7 @@ export function fireGoogleAnalyticsPageView( | |||
|
|||
window.gtag( | |||
'config', | |||
getGaGtag( useJetpackGoogleAnalytics, useAkismetGoogleAnalytics ), | |||
getGaGtag( useJetpackGoogleAnalytics, useAkismetGoogleAnalytics, useA4AGoogleAnalytics ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've documented the possible improvement on our maintenance board - as it relates in a large chunk to Jetpack/Akismet use cases.
f44fedb
to
4e41cd7
Compare
Thanks everyone for the great feedback. I truly appreciate it. I apologize for the delay in responding to the PR. I had some other stuff to prioritize. I've made some adjustments to address the comments made. 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on the changes, the code looks good!
One functional change, I've realized by debugging (btw, I recommend Analytics Debugger Chrome extension) that we just track page view event for WPCOM tracker on /overview page.
The implementation of page view changes look good, but we need to extend the usage of to make use of them (i.e. here: https://github.com/Automattic/wp-calypso/blob/trunk/client/a8c-for-agencies/sections/overview/controller.tsx).
It should be something like this:
<PageViewTracker
title="Overview"
path={ context.path }
options={ { useA8CForAgenciesGoogleAnalytics: true } }
/>
So to leverage the changes from client/lib/analytics/page-view.js
.
Thanks. I've made the necessary changes so all pages pass the correct options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works well for me, I receive the page view for the correct tag id on /overview
!
This PR updates the Google Analytics package to recognize the A4A environment and use the correct Gtag ID. The main goal is for the initial setup. We can track page views.
Proposed Changes
Why are these changes being made?
Testing Instructions
/signup
./overview?flags=ad-tracking
Pre-merge Checklist