Skip to content
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

Add Tracks Analytics on frontend #185

Merged
merged 87 commits into from
Nov 15, 2024
Merged

Conversation

mehmoodak
Copy link
Member

@mehmoodak mehmoodak commented Oct 30, 2024

Description

Add Tracks Analytics by using the @automattic/calypso-analytics package. With each track event, the following properties will be tracked:

  • Properties related to VIP Platform (e.g. org_id, env_id).
  • Properties related to Remote Data Blocks (e.g. plugin_version).
  • Event specific properties.

Note: This tracking will only work if site is hosted on VIP Platform or if the analytics is enabled via filter.

How to test?

  1. Create a site using vip dev-env which will have the MU Plugins.

  2. Move remote-data-blocks plugin to the plugins folder.

  3. Add filter in plugin-loader.php to enable tracking.

    add_filter( 'remote_data_blocks_enable_tracks_analytics', '__return_true' );
  4. Checkout this wp-calypso PR, build and link the @automattic/calypso-analytics package.

  5. To allow tracking on local env comment check on PHP and JS side.

  6. Trigger track events, use "Live View" to verify that the events are getting logged.

mehmoodak and others added 30 commits October 2, 2024 15:35
Co-authored-by: Chris Zarate <chris.zarate@automattic.com>
@@ -66,6 +66,7 @@ function BoundBlockEdit( props: BoundBlockEditProps ) {
attributes={ attributes }
availableBindings={ availableBindings }
blockName={ blockName }
remoteDataName={ remoteDataName }
Copy link
Member

Choose a reason for hiding this comment

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

Instead of prop drilling the container block name, I think we should just prop drill the sendTracksEvent function with the data_source_type baked in

Copy link
Member Author

Choose a reason for hiding this comment

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

We'll need prop drilling in either case, to me passing blockName seems simpler than passing the function.

@mehmoodak mehmoodak requested a review from chriszarate November 5, 2024 20:19
Copy link
Contributor

@maxschmeling maxschmeling left a comment

Choose a reason for hiding this comment

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

Looks like a really good start. Some minor pedantic things I might do a little different, but not worth nit picking. I like it.

tsconfig.json Outdated Show resolved Hide resolved
@@ -51,11 +55,23 @@ export function BlockBindingControls( props: BlockBindingControlsProps ) {
function updateFieldBinding( target: string, field: string ): void {
if ( ! field ) {
removeBinding( target );
sendTracksEvent( 'remotedatablocks_remote_data_container_actions', {
action: 'remove_binding',
data_source_type: getBlockDataSourceType( remoteDataName ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also have a remote_data_field property?

Copy link
Member Author

Choose a reason for hiding this comment

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

For remove_binding action we don't get field value and that's why I haven't included remote_data_field in track props. Let me know if you think we should include it, I will find an alternative.

Base automatically changed from cafe-942/add-tracks-analytics to trunk November 15, 2024 07:42
@mehmoodak mehmoodak merged commit ad58e6b into trunk Nov 15, 2024
10 checks passed
@mehmoodak mehmoodak deleted the cafe-942/add-tracks-analytics-on-js branch November 15, 2024 09:36
mehmoodak added a commit that referenced this pull request Nov 21, 2024
Pull request #185 has caused an issue with the withBlockBinding tests, which attempt to use the Tracks API. To resolve this, the Tracks function was mocked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants