Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Add getEcommerceItems getter #567

Closed

Conversation

SassNinja
Copy link
Contributor

This PR adds the missing getter.

Since the whole architecture is designed for pushing to matomo (pushInstruction) and not pulling, I've tried to find a way to access all those methods, mentioned in the matomo docs.

My solution is using window.Matomo.getAsyncTrackers() because an asyncTracker seems to provide all those methods. Not sure if that's the intended/best usage, but it's at least working.
I've added a private method callMethod so it can be reused for other missing getters if someone needs it.

Closes #566

The underlying method returns an empty array in that case. The integration should behave indentically.
This is crucial because otherwise window.Matomo is undefined and cannot be used.
This can't be called befire matomo is loaded.
// Return all ecommerce items currently in the untracked ecommerce order.
// https://matomo.org/docs/ecommerce-analytics
getEcommerceItems(): EcommerceItems {
return (this.callMethod('getEcommerceItems') || {}) as EcommerceItems
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use a generic here instead of casting it? Then it would be this.callMethod<EcommerceItems>

@jonkoops
Copy link
Owner

Closing this due to inactivity, if this should be reopened please let me know.

@jonkoops jonkoops closed this Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing ecommerce getter
3 participants