Skip to content

Commit

Permalink
Merge pull request #492 from newfold-labs/enhance/sitegen-events
Browse files Browse the repository at this point in the history
Sitegen: Analytics
  • Loading branch information
arunshenoy99 authored Feb 28, 2024
2 parents cbb1890 + b39e6eb commit ca6ee0a
Show file tree
Hide file tree
Showing 24 changed files with 590 additions and 89 deletions.
19 changes: 19 additions & 0 deletions src/OnboardingSPA/chapters/siteGen/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { __ } from '@wordpress/i18n';

import { CHAPTER_SITEGEN_CORE } from '../../../constants';
import { Chapter } from '../../data/models/Chapter';
import { stepSiteGenSiteDetails } from '../../steps/SiteGen/SiteDetails/step';
import { stepSiteGenSiteLogo } from '../../steps/SiteGen/SiteLogo/step';
import { stepSiteGenSocialMedia } from '../../steps/SiteGen/SocialMedia/step';

const steps = [
stepSiteGenSiteDetails,
stepSiteGenSocialMedia,
stepSiteGenSiteLogo,
];

export const siteGenCore = new Chapter( {
id: CHAPTER_SITEGEN_CORE,
name: __( 'Sitegen Core', 'wp-module-onboarding' ),
steps,
} );
14 changes: 14 additions & 0 deletions src/OnboardingSPA/chapters/siteGen/design.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { __ } from '@wordpress/i18n';

import { CHAPTER_SITEGEN_DESIGN } from '../../../constants';
import { Chapter } from '../../data/models/Chapter';
import { stepSiteGenEditor } from '../../steps/SiteGen/Editor/step';
import { stepSiteGenPreview } from '../../steps/SiteGen/Preview/step';

const steps = [ stepSiteGenPreview, stepSiteGenEditor ];

export const siteGenDesign = new Chapter( {
id: CHAPTER_SITEGEN_DESIGN,
name: __( 'Sitegen Design', 'wp-module-onboarding' ),
steps,
} );
14 changes: 14 additions & 0 deletions src/OnboardingSPA/chapters/siteGen/features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { __ } from '@wordpress/i18n';

import { CHAPTER_SITEGEN_FEATURES } from '../../../constants';
import { Chapter } from '../../data/models/Chapter';
import { stepSiteGenBuilding } from '../../steps/SiteGen/Building/step';
import { stepSiteGenExperience } from '../../steps/SiteGen/Experience/step';

const steps = [ stepSiteGenExperience, stepSiteGenBuilding ];

export const siteGenFeatures = new Chapter( {
id: CHAPTER_SITEGEN_FEATURES,
name: __( 'Sitegen Features', 'wp-module-onboarding' ),
steps,
} );
28 changes: 0 additions & 28 deletions src/OnboardingSPA/chapters/sitegen.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SiteGenPreviewSelectableCard = ( {
overlay = false,
skeletonLoadingTime = 2500,
slug,
position,
title,
isFavorite,
palette,
Expand All @@ -28,19 +29,19 @@ const SiteGenPreviewSelectableCard = ( {

const onPreview = () => {
if ( typeof handlePreview === 'function' ) {
return handlePreview( slug );
return handlePreview( slug, position );
}
};

const onRegenerate = () => {
if ( typeof handleRegenerate === 'function' ) {
return handleRegenerate( slug, palette, isFavorite );
return handleRegenerate( slug, palette, isFavorite, position );
}
};

const onFavorite = () => {
if ( typeof handleFavorite === 'function' ) {
return handleFavorite( slug );
return handleFavorite( slug, position );
}
};

Expand Down
107 changes: 88 additions & 19 deletions src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ import {
SKIP_FLOW_ERROR_CODE_DATABASE,
SKIP_FLOW_ERROR_CODE_20,
} from '../../../../constants';
import {
OnboardingEvent,
trackOnboardingEvent,
} from '../../../utils/analytics/hiive';
import {
ACTION_ONBOARDING_CHAPTER_COMPLETE,
ACTION_ONBOARDING_CHAPTER_STARTED,
} from '../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../data/flows/constants';

// Wrapping the NewfoldInterfaceSkeleton with the HOC to make theme available
const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
Expand All @@ -35,29 +44,15 @@ const ThemedNewfoldInterfaceSkeleton = themeToggleHOC(
);

const SiteGen = () => {
const { newfoldBrand } = useSelect( ( select ) => {
return {
newfoldBrand: select( nfdOnboardingStore ).getNewfoldBrand(),
};
}, [] );

// Update Title and Tagline on the site.
const { editEntityRecord } = useDispatch( coreStore );
const { getEditedEntityRecord } = useSelect( ( select ) => {
return select( coreStore );
}, [] );

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
}, [ newfoldBrand ] );
const location = useLocation();

const {
currentData,
initialize,
pluginInstallHash,
siteGenErrorStatus,
interactionDisabled,
newfoldBrand,
currentStep,
lastChapter,
} = useSelect( ( select ) => {
return {
currentData:
Expand All @@ -69,11 +64,28 @@ const SiteGen = () => {
select( nfdOnboardingStore ).getSiteGenErrorStatus(),
interactionDisabled:
select( nfdOnboardingStore ).getInteractionDisabled(),
newfoldBrand: select( nfdOnboardingStore ).getNewfoldBrand(),
currentStep: select( nfdOnboardingStore ).getCurrentStep(),
lastChapter: select( nfdOnboardingStore ).getCurrentChapter(),
};
} );

const { setCurrentOnboardingData, updateSiteGenErrorStatus } =
useDispatch( nfdOnboardingStore );
const {
setCurrentOnboardingData,
updateSiteGenErrorStatus,
setActiveChapter,
} = useDispatch( nfdOnboardingStore );

// Update Title and Tagline on the site.
const { editEntityRecord } = useDispatch( coreStore );
const { getEditedEntityRecord } = useSelect( ( select ) => {
return select( coreStore );
}, [] );

useEffect( () => {
document.body.classList.add( `nfd-brand-${ newfoldBrand }` );
}, [ newfoldBrand ] );
const location = useLocation();

const prevSiteGenErrorStatus = useRef();

Expand Down Expand Up @@ -147,6 +159,14 @@ const SiteGen = () => {
) {
return;
}

if ( ! window.nfdOnboarding?.siteGenTimerInterval ) {
window.nfdOnboarding.siteGenTime = 0;
window.nfdOnboarding.siteGenTimerInterval = setInterval( () => {
window.nfdOnboarding.siteGenTime += 1;
}, 1000 );
}

let identifiers = await getSiteGenIdentifiers();
identifiers = identifiers.body;

Expand Down Expand Up @@ -187,6 +207,55 @@ const SiteGen = () => {
};
};

const trackChapters = () => {
const currentChapter = currentStep?.chapter;

if ( lastChapter !== currentChapter ) {
if ( lastChapter ) {
if ( currentData.data.chapters[ lastChapter ] ) {
currentData.data.chapters[ lastChapter ].completed = true;
}
trackOnboardingEvent(
new OnboardingEvent(
ACTION_ONBOARDING_CHAPTER_COMPLETE,
lastChapter,
{
source: SITEGEN_FLOW,
}
)
);
}

if ( currentChapter ) {
if ( currentData.data.chapters[ currentChapter ] ) {
currentData.data.chapters[
currentChapter
].completed = false;
}
trackOnboardingEvent(
new OnboardingEvent(
ACTION_ONBOARDING_CHAPTER_STARTED,
currentChapter,
{
source: SITEGEN_FLOW,
}
)
);
}

setActiveChapter( currentChapter );
}

if ( currentChapter && currentData.data.chapters[ currentChapter ] ) {
currentData.data.chapters[ currentChapter ].lastStep =
currentStep?.path ?? '';
}
};

useEffect( () => {
trackChapters();
}, [ currentStep ] );

Check warning on line 257 in src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js

View workflow job for this annotation

GitHub Actions / Run Lint Checks

React Hook useEffect has a missing dependency: 'trackChapters'. Either include it or remove the dependency array

useEffect( () => {
if ( initialize ) {
initializePlugins( pluginInstallHash );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { SITEGEN_FLOW } from '../../../../../../data/flows/constants';
import {
OnboardingEvent,
trackOnboardingEvent,
} from '../../../../../../utils/analytics/hiive';
import { ACTION_COLORS_SELECTED } from '../../../../../../utils/analytics/hiive/constants';
import './stylesheet.scss';

const ColorPaletteIcon = ( {
Expand All @@ -16,6 +22,13 @@ const ColorPaletteIcon = ( {
const handleClick = () => {
setSelectedPalette( idx );
setSelectedColor( colors[ idx ] );
const { isDefault, ...colorsForEvent } = colors[ idx ];
trackOnboardingEvent(
new OnboardingEvent( ACTION_COLORS_SELECTED, 'generated', {
colors: colorsForEvent,
source: SITEGEN_FLOW,
} )
);
if ( setShowCustomColors ) {
setShowCustomColors( false );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { store as nfdOnboardingStore } from '../../../../../store';
import { __ } from '@wordpress/i18n';
// eslint-disable-next-line import/no-extraneous-dependencies
import { cloneDeep } from 'lodash';
import {
OnboardingEvent,
trackOnboardingEvent,
} from '../../../../../utils/analytics/hiive';
import { ACTION_COLORS_SELECTED } from '../../../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../../../data/flows/constants';

const DesignColorsPanel = forwardRef(
(
Expand Down Expand Up @@ -150,6 +156,13 @@ const DesignColorsPanel = forwardRef(
setIsEditingCustomColors( false );
setSelectedPalette( 'custom' );
setCustomColors( selectedColor );
const { isDefault, ...colorsForEvent } = selectedColor;
trackOnboardingEvent(
new OnboardingEvent( ACTION_COLORS_SELECTED, 'custom', {
colors: colorsForEvent,
source: SITEGEN_FLOW,
} )
);
};

const handleEditCustomColors = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { PanelBody, PanelRow, Button } from '@wordpress/components';
import './stylesheet.scss';
import { store as nfdOnboardingStore } from '../../../../../store';
import { __ } from '@wordpress/i18n';
import {
OnboardingEvent,
trackOnboardingEvent,
} from '../../../../../utils/analytics/hiive';
import { ACTION_FONTS_SELECTED } from '../../../../../utils/analytics/hiive/constants';
import { SITEGEN_FLOW } from '../../../../../data/flows/constants';

const FontGroup = ( {
baseClassName,
Expand Down Expand Up @@ -336,6 +342,16 @@ const DesignFontsPanel = forwardRef(
setShowCustomFonts( false );
}
setSelectedGroup( groupId );
const eventFonts = {
headings: fontGroups[ groupId ].headings,
body: fontGroups[ groupId ].body,
};
trackOnboardingEvent(
new OnboardingEvent( ACTION_FONTS_SELECTED, 'generated', {
fonts: eventFonts,
source: SITEGEN_FLOW,
} )
);
};

const handleSelectYourOwnFonts = () => {
Expand All @@ -360,6 +376,12 @@ const DesignFontsPanel = forwardRef(
const handleApplyCustomFonts = () => {
setSelectedGroup( null );
setSelectedCustomFont( customFont );
trackOnboardingEvent(
new OnboardingEvent( ACTION_FONTS_SELECTED, 'custom', {
fonts: customFont,
source: SITEGEN_FLOW,
} )
);
setIsEditingCustomFont( false );
setSelectedGroup( 'custom' );
};
Expand Down
Loading

0 comments on commit ca6ee0a

Please sign in to comment.