Skip to content

Update EDD tracking to include item_id and price #11743

@zutigrm

Description

@zutigrm

Feature Description

Existing add_to_cart and purchase events should be updated to include item_id for each item in the cart/purchase items list, as well as price.

EDD add_to_cart event can be also updated a bit to pull value from the cart total from the details object directly, instead of using individual item's value


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Easy Digital Downloads add_to_cart event items include item_id (in addition to the existing item_name/price).
  • Easy Digital Downloads purchase event includes an items list that mirrors the add_to_cart item fields (item_id, item_name, price).
  • purchase event fires regardless of gtagUserData flag; only user_data is conditional.

Implementation Brief

  • Update includes/Core/Conversion_Tracking/Conversion_Event_Providers/Easy_Digital_Downloads.php to keep using window._googlesitekit.edddata.purchase and extend its payload with purchase product data.
    • In maybe_add_purchase_data_from_session, build purchase product payload from $purchase_session['cart_details'] on the server side:
      • Map each cart item to item_id, item_name, price.
      • Include cart total value from purchase session details.
      • Keep payload normalized so frontend can consume directly without deep optional chaining.
    • Keep user_data generation in the same payload, but only attach user_data when gtagUserData is enabled and extracted data is non-empty.
    • Update provider event/hook gating so purchase is part of tracked EDD events regardless of gtagUserData feature flag.
  • Update assets/js/event-providers/easy-digital-downloads.js:
    • Extend parseCartItemHTML to return item_id from .edd-remove-from-cart[data-download-id].
    • In edd_cart_item_added, include item_id in items.
    • Use cart total value from the details object for add_to_cart (instead of deriving total from the single parsed item price).
    • Fire purchase whenever global._googlesitekit?.edddata?.purchase exists.
    • Keep user_data attachment behind gtagUserData check only.

Test Coverage

  • Update assets/js/event-providers/easy-digital-downloads.test.js to include tests for item_id

QA Brief

  • Follow the setup steps in the QAB of Implement Easy Digital Downloads integration #11011 but do not enable gtagUserData
  • Ensure that when adding a product to the cart, the add_to_cart event is triggered
    • It should have the currency, value (cart total), and an array of items, each with item_id, item_name and price
  • Ensure that when finalizing the checkout, the purchase event is tracked
    • When gtagUserData is disabled, it should have the currency, value (cart total), and an array of items, each with item_id, item_name and price
    • When gtagUserData is enabled, it should also have user_data
  • Ensure that the gtagUserData feature flag only affects whether user_data is included or not. The rest of the fields should be sent regardless of gtagUserData

Changelog entry

  • Improve enhanced conversion tracking for Easy Digital Downloads to include additional details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Medium priorityTeam MIssues for Squad 2Type: EnhancementImprovement of an existing feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions