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 new actions for tracking #264

Merged
merged 2 commits into from
Apr 27, 2023
Merged

Conversation

puntope
Copy link
Contributor

@puntope puntope commented Apr 10, 2023

Changes proposed in this Pull Request:

Closes part of #227

This PR implements a set of new actions and their respective tracking functions for handling GA events with addAction hook.

Replace this with a good description of your changes & reasoning.

Checks:

  • Does your code follow the WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Detailed test instructions:

  1. For testing the actions I added this list of doActions (see after), you can see how GTag events run in Google Analytics Debugger.
  2. See that are no duplicates with WC Blocks (WC Blocks shows a log in console too console.log( Tracking event ${ eventName } );)
  3. Compare the actions with the ones in WC Blocks
  4. You can also test to add other actions with same name in different namespace so you can check they are not deleted.

List of doActions.

const product = {
	id: '1234',
	name: 'Test',
	list_name: 'List test',
	categories: [ { name: 'cat 1' }, { name: 'cat 2' } ],
	prices: {
		price: 2222,
		currency_minor_unit: 2,
	},
};

const product2 = {
	id: '12345',
	name: 'Test 2',
	list_name: 'List test',
	categories: [ { name: 'cat 1' }, { name: 'cat 2' } ],
	prices: {
		price: 2222,
		currency_minor_unit: 2,
	},
};

const storeCart = {
	cartItems: [ product, product2 ],
	cartCoupons: [
		{
			code: '123',
		},
	],
	cartTotals: {
		currency_code: 'EUR',
		total_price: 2222,
		currency_minor_unit: 2,
	},
};

doAction( `${ ACTION_PREFIX }-store-notice-create`, {
	status: 'error',
	content: 'test',
} );

doAction( `${ ACTION_PREFIX }-store-notice-create`, {
	status: 'other',
	content: 'test',
} );

doAction( `${ ACTION_PREFIX }-product-render`, { product, listName: 'test' } );
doAction( `${ ACTION_PREFIX }-product-search`, { searchTerm: 'joe' } );
doAction( `${ ACTION_PREFIX }-product-view-link`, {
	product,
	listName: 'test',
} );

doAction( `${ ACTION_PREFIX }-cart-add-item`, { product, quantity: 2 } );
doAction( `${ ACTION_PREFIX }-cart-remove-item`, { product, quantity: 1 } );
doAction( `${ ACTION_PREFIX }-cart-set-item-quantity`, {
	product,
	quantity: 3,
} );

doAction( `${ ACTION_PREFIX }-product-list-render`, {
	products: [ product, product2 ],
} );

doAction( `${ ACTION_PREFIX }-checkout-render-checkout-form`, { storeCart } );
doAction( `${ ACTION_PREFIX }-checkout-set-email-address`, { storeCart } );
doAction( `${ ACTION_PREFIX }-checkout-set-shipping-address`, { storeCart } );
doAction( `${ ACTION_PREFIX }-checkout-set-billing-address`, { storeCart } );
doAction( `${ ACTION_PREFIX }-checkout-set-phone-number`, {
	step: 'shipping',
	storeCart,
} );

doAction( `${ ACTION_PREFIX }-checkout-set-selected-shipping-rate`, {
	shippingRateId: 'hello',
} );

doAction( `${ ACTION_PREFIX }-checkout-set-active-payment-method`, {
	paymentMethodSlug: 'hello',
} );

Additional details:

⚠️ JS Unit Tests support are not included in this PR

Changelog entry

Add - Implement tracking with Actions Hooks

@puntope puntope self-assigned this Apr 10, 2023
@puntope puntope requested a review from a team April 13, 2023 14:59
@puntope puntope marked this pull request as ready for review April 13, 2023 15:03
Copy link
Contributor

@martynmjones martynmjones left a comment

Choose a reason for hiding this comment

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

Hey @puntope, thanks for your work on modernising the tracking!

This PR is working as expected and does a really nice job of replacing the core tracking but all the events are following the structure for Universal Analytics instead of GA4.

As UA will be retired on the 1st of July 2023 it seems like these changes should be made to support GA4.

I've left a couple of comments but haven't gone through each event as it looks like they will all need to be adjusted.

return;
}

trackEvent( step === 0 ? 'begin_checkout' : 'checkout_progress', {
Copy link
Contributor

Choose a reason for hiding this comment

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

GA4 drops checkout_progress completely and doesn't include checkout_step option

listName = __( 'Product List', 'woocommerce-google-analytics-integration' ),
} ) => {
trackEvent( 'view_item_list', {
event_category: 'engagement',
Copy link
Contributor

@martynmjones martynmjones Apr 26, 2023

Choose a reason for hiding this comment

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

GA4 drops the event_category and event_label structure in favor of individual parameters for each event. Ref: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#view_item_list

),
items: products.map( ( product, index ) => ( {
...getProductImpressionObject( product, listName ),
list_position: index + 1,
Copy link
Contributor

@martynmjones martynmjones Apr 26, 2023

Choose a reason for hiding this comment

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

Again a UA/GA4 issue and I know it wasn't introduced in this PR but getProductImpressionObject parameter names have things like id and name instead of item_id and item_name.

For the map here, list_position would become index.

assets/js/src/utils.js Show resolved Hide resolved
@puntope
Copy link
Contributor Author

puntope commented Apr 26, 2023

Hello @martynmjones Thanks for the GA changes catch. Since this PR is not going to be merged into develop branch (yet) I will discuss it with the WC Blocks team and perform the updates in other PR if that's ok.

In regards to your comment about the missed key, it's already clarified

@puntope puntope requested a review from martynmjones April 26, 2023 15:47
Copy link
Contributor

@martynmjones martynmjones left a comment

Choose a reason for hiding this comment

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

Hey @puntope,

Thanks for the clarification 👍

@puntope puntope merged commit 6953bb2 into feature/analytics-wc-blocks Apr 27, 2023
@puntope puntope deleted the wc-blocks-actions branch April 27, 2023 08:30
@eason9487 eason9487 added the changelog: add A new feature, function, or functionality was added. label May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: add A new feature, function, or functionality was added.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants