Skip to content

Google Analytics: Add remaining enhanced eCommerce trackers#8218

Merged
dereksmart merged 15 commits intomasterfrom
add/8181-enhanced-google-analytics-moar-settings
Nov 27, 2017
Merged

Google Analytics: Add remaining enhanced eCommerce trackers#8218
dereksmart merged 15 commits intomasterfrom
add/8181-enhanced-google-analytics-moar-settings

Conversation

@allendav
Copy link
Copy Markdown
Contributor

@allendav allendav commented Nov 20, 2017

Fixes #8181

Changes proposed in this Pull Request:

  • Adds support for the following Enhanced eCommerce tracking events:

  • Remove item from cart

  • Track product impressions

  • Track product listing clicks

  • Track product detail views

  • Track checkout started

Testing instructions:

Remove From Cart

  • Use the helper plugin (wp-admin > Tools > Jetpack Google Analytics Helper) to set the following:
Google Analytics Tracking / Property ID: UA-12345678-1 (use a real tracking/property ID, not this one)
Anonymize IP Addresses: unchecked
Track Purchase Transactions: unchecked
Track Add to Cart Events: unchecked
Enable Enhanced eCommerce: CHECKED
Track Remove from Cart: CHECKED
Track Product Impressions on Listing Pages: unchecked
Track Product Clicks on Listing Pages: unchecked
Track Product Detail Views: unchecked
Track Checkout Process Initiated: unchecked
  • In your Google Analytics Dashboard ( https://analytics.google.com/ ), go to Admin for your site (it looks like a gear in the lower left corner)

  • Under View select Ecommerce Settings

  • Enable Ecommerce AND Enhanced eCommerce if you haven't already.

  • Add the SKU-less product and the SKU'd product to the cart

  • Navigate to cart view

  • View the source for the page

  • Search for "ec:" - ensure javascript is enqueued for both products

  • Open the JavaScript dev console

  • Click on the remove for each product in turn

  • Ensure no JavaScript errors appear in the console

  • Wait a few minutes

  • In your Google Analytics Dashboard, go to Real-time and then Events

  • Make sure you see the remove from cart events for the SKU-less and the SKU'd product (you might need to click on the UX category to see them)

screen shot 2017-11-20 at 5 11 23 pm

Product Impressions

  • Use the helper plugin (wp-admin > Tools > Jetpack Google Analytics Helper) to set the following:
Google Analytics Tracking / Property ID: UA-12345678-1 (use a real tracking/property ID, not this one)
Anonymize IP Addresses: unchecked
Track Purchase Transactions: unchecked
Track Add to Cart Events: unchecked
Enable Enhanced eCommerce: CHECKED
Track Remove from Cart: unchecked
Track Product Impressions on Listing Pages: CHECKED
Track Product Clicks on Listing Pages: unchecked
Track Product Detail Views: unchecked
Track Checkout Process Initiated: unchecked
  • Open the JavaScript dev console if not already open
  • Navigate to shop view (i.e. products list)
  • View the source for the page
  • Search for "ec:addImpression" - make sure that ec: command is enqueued for both products
  • Ensure no JavaScript errors appear in the console
  • Wait a few minutes
  • In your Google Analytics Dashboard, go to Conversions and then eCommerce and then Product List Performance
  • Make sure you see the entries for the SKU-less and the SKU'd product

screen shot 2017-11-20 at 5 17 07 pm

Product Clicks

  • Use the helper plugin (wp-admin > Tools > Jetpack Google Analytics Helper) to set the following:
Google Analytics Tracking / Property ID: UA-12345678-1 (use a real tracking/property ID, not this one)
Anonymize IP Addresses: unchecked
Track Purchase Transactions: unchecked
Track Add to Cart Events: unchecked
Enable Enhanced eCommerce: CHECKED
Track Remove from Cart: unchecked
Track Product Impressions on Listing Pages: unchecked
Track Product Clicks on Listing Pages: CHECKED
Track Product Detail Views: unchecked
Track Checkout Process Initiated: unchecked
  • Open the JavaScript dev console if not already open
  • Navigate to shop view (i.e. products list)
  • View the source for the page
  • Search for "ec:" - make sure that a click handler is in the page source for each product, e.g.
$( '.products .post-1390 a' ).click( function() {
  • Ensure no JavaScript errors appear in the console
  • Click on the PICTURE for each product (NOT the Add to Cart button) (and then go back and repeat for the next product)
  • Wait a few minutes
  • In your Google Analytics Dashboard, go to Conversions and then eCommerce and then Product List Performance
  • Make sure you see the entries for the SKU-less and the SKU'd product

Product Detail View

  • Use the helper plugin (wp-admin > Tools > Jetpack Google Analytics Helper) to set the following:
Google Analytics Tracking / Property ID: UA-12345678-1 (use a real tracking/property ID, not this one)
Anonymize IP Addresses: unchecked
Track Purchase Transactions: unchecked
Track Add to Cart Events: unchecked
Enable Enhanced eCommerce: CHECKED
Track Remove from Cart: unchecked
Track Product Impressions on Listing Pages: unchecked
Track Product Clicks on Listing Pages: unchecked
Track Product Detail Views: CHECKED
Track Checkout Process Initiated: unchecked
  • Open the JavaScript dev console if not already open
  • Navigate to a single product view
  • View the source for the page
  • Search for 'ec:setAction', 'detail' - make sure that an addProduct preceeds it for the product
  • Ensure no JavaScript errors appear in the console
  • Wait a few minutes
  • In your Google Analytics Dashboard, go to Conversions and then eCommerce and then Product List Performance
  • Make sure you see the entries for the SKU-less and the SKU'd product

Checkout Initiated

  • Use the helper plugin (wp-admin > Tools > Jetpack Google Analytics Helper) to set the following:
Google Analytics Tracking / Property ID: UA-12345678-1 (use a real tracking/property ID, not this one)
Anonymize IP Addresses: unchecked
Track Purchase Transactions: unchecked
Track Add to Cart Events: unchecked
Enable Enhanced eCommerce: CHECKED
Track Remove from Cart: unchecked
Track Product Impressions on Listing Pages: unchecked
Track Product Clicks on Listing Pages: unchecked
Track Product Detail Views: unchecked
Track Checkout Process Initiated: CHECKED
  • Open the JavaScript dev console if not already open
  • Navigate to a each product view and add the product to your cart
  • Proceed to checkout
  • View the source for the page
  • Search for 'ec:setAction', 'checkout' - make sure that an addProduct preceeds it for each product, e.g.:
ga( 'ec:addProduct', {"id":"12345678-0123","name":"Has SKU Two Cat","category":"Albums\/T-shirts","price":"123","quantity":1} );
ga( 'ec:addProduct', {"id":"#1389","name":"No SKU Two Cat","category":"Albums\/Singles","price":"123","quantity":1} );
ga( 'ec:setAction','checkout' );
  • Ensure no JavaScript errors appear in the console

  • Wait a few minutes

  • In your Google Analytics Dashboard, go to ??? (I couldn't find where this ends up - do you know @justinshreve ?)

  • Lastly, disable WooCommerce

  • Make sure with a tracker ID enabled, and all settings INCLUDING enhanced ecommerce enabled, that you are able to navigate the site without PHP errors

  • Make sure with a tracker ID enabled, and all settings EXCEPT enhanced ecommerce enabled, that you are able to navigate the site without PHP errors

@allendav allendav self-assigned this Nov 20, 2017
@allendav allendav requested a review from a team as a code owner November 20, 2017 21:13
@allendav allendav changed the base branch from master to add/8181-enhanced-google-analytics November 20, 2017 21:14
@allendav allendav added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 21, 2017
@emdashcodes
Copy link
Copy Markdown

@allendav For the Remove From Cart event, I seem to be having issues if I remove one item, and then another. Only the first one seems to get logged. I see a network event to the GA collect endpoint for the first product I remove. I don't see a request for the second event and that event doesn't show up.

@emdashcodes
Copy link
Copy Markdown

Checkout Initiated
I couldn't find where this ends up - do you know @justinshreve?

I saw data come in the following two places:

Conversions > eCommerce Shopping Behavior (sessions with Check-out) and Conversions -> eCommerce -> Checkout Behavior

Copy link
Copy Markdown

@emdashcodes emdashcodes left a comment

Choose a reason for hiding this comment

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

I have two questions and I am having an issue with the remove from cart event (#8218 (comment)). Otherwise, everything else seems to be testing nicely now and I see data coming into GA.

}

$item_details = array(
'id' => $product->get_id(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be sku or id like the other entries?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was wondering about that too - I'll make it consistent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 81f4fd8

$selector = ".products .post-" . esc_js( $product->get_id() ) . " a";

$item_details = array(
'id' => $product->get_id(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be sku or id like the other entries?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 81f4fd8

@allendav allendav added [Status] Needs Design Review Design has been added. Needs a review! and removed [Status] Needs Design Review Design has been added. Needs a review! labels Nov 22, 2017
@allendav
Copy link
Copy Markdown
Contributor Author

allendav commented Nov 22, 2017

@justinshreve wrote:

@allendav For the Remove From Cart event, I seem to be having issues if I remove one item, and then another. Only the first one seems to get logged. I see a network event to the GA collect endpoint for the first product I remove. I don't see a request for the second event and that event doesn't show up.

Hmmm - I'll take a look

edit: OK - I can reproduce this as well. When the first item is removed, core WooCommerce refreshes the cart display. When this happens, the jQuery added event handler for GA for a.remove gets lost. Not sure how to fix yet - this could be tricky - might need to let it bubble up to a container and listen there or something

edit: edit: Fixed in a1e5730

To verify it is working properly, add the following to remove_from_cart and then click on items to your heart's content.

console.log( 'in remove_from_cart, productDetails=', productDetails );

@allendav
Copy link
Copy Markdown
Contributor Author

@justinshreve - all items, including the remove-from-cart business, fixed and ready for re-review

Copy link
Copy Markdown

@emdashcodes emdashcodes left a comment

Choose a reason for hiding this comment

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

Looking good from my end. Everything is testing correctly.

Copy link
Copy Markdown
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

Just a quick note to help with our documentation.

$cart = WC()->cart->get_cart();

foreach ( $cart as $cart_item_key => $cart_item ) {
$product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a docblock here so as to not trip the parser? Since it's a Woocommerce filter something like /** This filter is already documented in xxxx.php */ would do the trick.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 5977a8b

@allendav allendav force-pushed the add/8181-enhanced-google-analytics-moar-settings branch from 5977a8b to 4a1eee3 Compare November 25, 2017 18:12
@dereksmart dereksmart changed the base branch from add/8181-enhanced-google-analytics to master November 27, 2017 18:07
@dereksmart dereksmart changed the base branch from master to add/8181-enhanced-google-analytics November 27, 2017 18:08
@allendav allendav changed the base branch from add/8181-enhanced-google-analytics to master November 27, 2017 18:19
@allendav allendav force-pushed the add/8181-enhanced-google-analytics-moar-settings branch from 4a1eee3 to 8688b65 Compare November 27, 2017 18:31
@oskosk oskosk added this to the 5.6 milestone Nov 27, 2017
@dereksmart dereksmart merged commit 8a61841 into master Nov 27, 2017
@dereksmart dereksmart deleted the add/8181-enhanced-google-analytics-moar-settings branch November 27, 2017 19:56
@dereksmart dereksmart removed the [Status] Needs Review This PR is ready for review. label Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants