diff --git a/projects/packages/my-jetpack/_inc/hooks/use-analytics/index.js b/projects/packages/my-jetpack/_inc/hooks/use-analytics/index.js index ac1f474506895..a0cd174db37ca 100644 --- a/projects/packages/my-jetpack/_inc/hooks/use-analytics/index.js +++ b/projects/packages/my-jetpack/_inc/hooks/use-analytics/index.js @@ -1,3 +1,4 @@ +/* global myJetpackInitialState */ /** * External dependencies */ @@ -8,6 +9,7 @@ import useMyJetpackConnection from '../use-my-jetpack-connection'; const useAnalytics = () => { const { isUserConnected, userConnectionData = {} } = useMyJetpackConnection(); const { login, ID } = userConnectionData.currentUser?.wpcomUser || {}; + const { connectedPlugins } = myJetpackInitialState; /** * Initialize tracks with user data. @@ -19,6 +21,12 @@ const useAnalytics = () => { } }, [ ID, isUserConnected, login ] ); + // Concatenated plugins slugs in alphabetical order + const connectedPluginsSlugs = Object.keys( connectedPlugins || {} ) + .sort() + .join( ',' ) + .replaceAll( 'jetpack-', '' ); + const { clearedIdentity, ga, @@ -42,9 +50,10 @@ const useAnalytics = () => { tracks.recordEvent( event, { ...properties, version: window?.myJetpackInitialState?.myJetpackVersion, + referring_plugins: connectedPluginsSlugs, } ); }, - [ tracks ] + [ tracks, connectedPluginsSlugs ] ); return { diff --git a/projects/packages/my-jetpack/changelog/add-referring-plugins-to-tracks b/projects/packages/my-jetpack/changelog/add-referring-plugins-to-tracks new file mode 100644 index 0000000000000..62e8aa00c7c3c --- /dev/null +++ b/projects/packages/my-jetpack/changelog/add-referring-plugins-to-tracks @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +Added connected plugins slugs to My Jetpack tracking events