Skip to content

Commit

Permalink
move tracking for close article to trigger from sidebar as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Addison-Stavlo committed Jun 20, 2024
1 parent 95c269f commit a8a6d93
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
6 changes: 1 addition & 5 deletions client/blocks/reader-full-post/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,7 @@ export class FullPostView extends Component {

handleBack = ( event ) => {
event.preventDefault();
recordAction( 'full_post_close' );
recordGaEvent( 'Closed Full Post Dialog' );
recordTrackForPost( 'calypso_reader_article_closed', this.props.post );

this.props.onClose && this.props.onClose();
this.props.onClose && this.props.onClose( this.props.post );
};

handleCommentClick = () => {
Expand Down
17 changes: 15 additions & 2 deletions client/reader/full-post/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import page from '@automattic/calypso-router';
import { defer } from 'lodash';
import AsyncLoad from 'calypso/components/async-load';
import { trackPageLoad } from 'calypso/reader/controller-helper';
import { recordAction, recordGaEvent, recordTrackForPost } from 'calypso/reader/stats';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';

const analyticsPageTitle = 'Reader';
Expand All @@ -27,7 +28,11 @@ export function blogPost( context, next ) {
trackPageLoad( basePath, fullPageTitle, 'full_post' );

const lastRoute = context.lastRoute || '/';
function closer() {
function closer( post ) {
recordAction( 'full_post_close' );
recordGaEvent( 'Closed Full Post Dialog' );
recordTrackForPost( 'calypso_reader_article_closed', post );

page.back( lastRoute );
}

Expand All @@ -50,6 +55,8 @@ export function blogPost( context, next ) {
placeholder={ null }
returnPath={ lastRoute }
onClose={ closer }
postId={ postId }
blogId={ blogId }
/>
);
}
Expand All @@ -67,7 +74,11 @@ export function feedPost( context, next ) {
trackPageLoad( basePath, fullPageTitle, 'full_post' );

const lastRoute = context.lastRoute || '/';
function closer() {
function closer( post ) {
recordAction( 'full_post_close' );
recordGaEvent( 'Closed Full Post Dialog' );
recordTrackForPost( 'calypso_reader_article_closed', post );

page.back( lastRoute );
}

Expand All @@ -89,6 +100,8 @@ export function feedPost( context, next ) {
placeholder={ null }
returnPath={ lastRoute }
onClose={ closer }
postId={ postId }
feedId={ feedId }
/>
);
}
Expand Down
11 changes: 8 additions & 3 deletions client/reader/sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import page from '@automattic/calypso-router';
import { hasTranslation } from '@wordpress/i18n';
import closest from 'component-closest';
import i18n, { localize } from 'i18n-calypso';
import { defer, startsWith } from 'lodash';
import { defer, pickBy, startsWith } from 'lodash';
import { Component } from 'react';
import { connect } from 'react-redux';
import QueryReaderLists from 'calypso/components/data/query-reader-lists';
Expand Down Expand Up @@ -33,6 +33,7 @@ import { getShouldShowGlobalSidebar } from 'calypso/state/global-sidebar/selecto
import { recordReaderTracksEvent } from 'calypso/state/reader/analytics/actions';
import { getSubscribedLists } from 'calypso/state/reader/lists/selectors';
import { getReaderOrganizations } from 'calypso/state/reader/organizations/selectors';
import { getPostByKey } from 'calypso/state/reader/posts/selectors';
import {
toggleReaderSidebarLists,
toggleReaderSidebarTags,
Expand Down Expand Up @@ -297,7 +298,7 @@ export class ReaderSidebar extends Component {
requireBackLink: true,
siteTitle: i18n.translate( 'Reader' ),
backLinkHref: this.props.returnPath || '/sites',
onClose: this.props.onClose,
onClose: this.props.onClose && ( () => this.props.onClose( this.props.post ) ),
};
return (
<GlobalSidebar { ...props }>
Expand Down Expand Up @@ -333,7 +334,7 @@ export class ReaderSidebar extends Component {

export default withCurrentRoute(
connect(
( state, { currentSection } ) => {
( state, { currentSection, postId, blogId, feedId } ) => {
const sectionGroup = currentSection?.group ?? null;
const sectionName = currentSection?.name ?? null;
const siteId = getSelectedSiteId( state );
Expand All @@ -343,13 +344,17 @@ export default withCurrentRoute(
sectionGroup,
sectionName
);
const postKey = pickBy( { feedId: +feedId, blogId: +blogId, postId: +postId } );
const post = getPostByKey( state, postKey ) || { _state: 'pending' };

return {
isListsOpen: isListsOpen( state ),
isTagsOpen: isTagsOpen( state ),
subscribedLists: getSubscribedLists( state ),
teams: getReaderTeams( state ),
organizations: getReaderOrganizations( state ),
shouldShowGlobalSidebar,
post,
};
},
{
Expand Down

0 comments on commit a8a6d93

Please sign in to comment.