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

Media Library: add track events for upload from URL feature #41620

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions projects/packages/external-media/changelog/media-tracks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Media Library: add track events for upload from URL feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ function MediaBrowser( {
);

const onCopyAndInsert = useCallback( () => {
tracks.recordEvent( 'jetpack_external_media_modal_cta_click', {
page_source: pageSource,
tracks.recordEvent( 'jetpack_external_media_modal_submit', {
page: pageSource,
media_source: mediaSource,
media_count: selected.length,
multiple: !! multiple,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { useSelect } from '@wordpress/data';

const usePageSource = () => {
const isSiteEditor = useSelect( select => !! select( 'core/edit-site' ), [] );
const postType = useSelect( select => select( 'core/editor' )?.getCurrentPostType(), [] );
const isEditor = useSelect( select => !! select( 'core/editor' ), [] );

if ( ! postType ) {
return 'jetpack-external-media-import-page';
if ( isEditor ) {
return 'editor';
}

if ( isSiteEditor ) {
return 'site-editor';
}

return postType === 'page' ? 'page-editor' : 'post-editor';
return 'media-library';
};

export default usePageSource;
4 changes: 4 additions & 0 deletions projects/packages/jetpack-mu-wpcom/changelog/media-tracks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Media Library: add track events for upload from URL feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { __ } from '@wordpress/i18n';
import clsx from 'clsx';
import { useState } from 'react';
import { wpcomTrackEvent } from '../../../common/tracks';

import './style.scss';

const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, isEditor } ) => {
const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, page } ) => {
const [ url, setUrl ] = useState( '' );

const [ show, setShow ] = useState( false );
Expand All @@ -25,6 +26,10 @@ const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, isEditor } ) => {
}
e.preventDefault();

wpcomTrackEvent( 'wpcom_media_upload_from_url_submit', {
page,
} );

const formData = new FormData();
formData.append( 'action', action );
formData.append( 'url', url );
Expand All @@ -48,7 +53,7 @@ const WpcomMediaUrlUploadForm = ( { ajaxUrl, action, nonce, isEditor } ) => {
.collection.add( attachmentToAdd );
};

if ( isEditor ) {
if ( page === 'editor' ) {
const mediaLibraryTab = window.wp.media.frame.state( 'library' );
mediaLibraryTab.trigger( 'open' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function wpcom_media_url_upload() {

$data = wp_json_encode(
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'action' => 'wpcom_media_url_upload',
'nonce' => wp_create_nonce( 'wpcom_media_url_upload' ),
'isEditor' => $pagenow !== 'upload.php',
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'action' => 'wpcom_media_url_upload',
'nonce' => wp_create_nonce( 'wpcom_media_url_upload' ),
'page' => $pagenow === 'upload.php' ? 'media-library' : 'editor',
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we need to support media-new.php as well. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How so? The pluploader does not work there...

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Let's address this when we want to add the button there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I remember now; I didn't implement there because the pluploader logic is a bit different there. It's the same reason why VideoPress is only available on upload.php but not media-new.php

)
);

Expand Down
Loading