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

My Jetpack: Fire Tracks event when clicking CTA button on product Interstitial page #22672

Merged
merged 3 commits into from
Feb 4, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ function Price( { value, currency, isOld } ) {
/**
* Product Detail component.
*
* @param {object} props - Component props.
* @param {string} props.slug - Product slug
* @returns {object} ProductDetailCard react component.
* @param {object} props - Component props.
* @param {string} props.slug - Product slug
* @param {Function} props.trackButtonClick - Function to call for tracking clicks on Call To Action button
* @returns {object} ProductDetailCard react component.
*/
export function ProductDetail( { slug } ) {
const ProductDetail = ( { slug, trackButtonClick } ) => {
const { detail } = useProduct( slug );
const { title, longDescription, features } = detail;
const price = 9;
Expand Down Expand Up @@ -95,15 +96,27 @@ export function ProductDetail( { slug } ) {
</div>
</div>

<Button isLink isPrimary href="#" className={ styles[ 'checkout-button' ] }>
<Button
onClick={ trackButtonClick }
isLink
isPrimary
href="#"
className={ styles[ 'checkout-button' ] }
>
{
/* translators: placeholder is product name. */
sprintf( __( 'Add %s', 'jetpack-my-jetpack' ), title )
}
</Button>
</div>
);
}
};

ProductDetail.defaultProps = {
trackButtonClick: () => {},
};

export { ProductDetail };

/**
* ProductDetailCard component.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import React, { useEffect } from 'react';
import React, { useCallback, useEffect } from 'react';
import { Container, Col } from '@automattic/jetpack-components';

/**
Expand All @@ -28,10 +28,14 @@ export default function ProductInterstitial( { slug, children = null } ) {
useEffect( () => {
recordEvent( 'jetpack_myjetpack_product_interstitial_view', { product: slug } );
}, [ recordEvent, slug ] );

const trackProductClick = useCallback( () => {
recordEvent( 'jetpack_myjetpack_product_interstitial_add_link_click', { product: slug } );
}, [ recordEvent, slug ] );
return (
<Container className={ styles.container } horizontalSpacing={ 0 } horizontalGap={ 0 }>
<Col sm={ 4 } md={ 4 } lg={ 5 }>
<ProductDetail slug={ slug } />
<ProductDetail slug={ slug } trackButtonClick={ trackProductClick } />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the event should be named onAdd(), or something like that. If you agree, we can rename it in a follow-up PR

Suggested change
<ProductDetail slug={ slug } trackButtonClick={ trackProductClick } />
<ProductDetail slug={ slug } onAdd={ trackProductClick } />

</Col>
<Col sm={ 4 } md={ 4 } lg={ 7 } className={ styles.imageContainer }>
{ children }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Fire Tracks event when clicking CTA button on product Interstitial page