Skip to content

Commit

Permalink
My Jetpack: Add connected plugins to tracking events (#23280)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogermani authored Mar 8, 2022
1 parent b2136ca commit 90240dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion projects/packages/my-jetpack/_inc/hooks/use-analytics/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global myJetpackInitialState */
/**
* External dependencies
*/
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -42,9 +50,10 @@ const useAnalytics = () => {
tracks.recordEvent( event, {
...properties,
version: window?.myJetpackInitialState?.myJetpackVersion,
referring_plugins: connectedPluginsSlugs,
} );
},
[ tracks ]
[ tracks, connectedPluginsSlugs ]
);

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Added connected plugins slugs to My Jetpack tracking events

0 comments on commit 90240dd

Please sign in to comment.