pronamic / wp-pronamic-pay

The Pronamic Pay plugin allows you to easily accept payments with payment methods like credit card, iDEAL, Bancontact and Sofort through a variety of payment providers on your WordPress website.
https://pronamicpay.com
34 stars 14 forks source link

Google Analytics distinguish between first and automatic recurring payments #300

Closed remcotolsma closed 1 year ago

remcotolsma commented 2 years ago

Request from customer:

Wij stuiten op een rapportage probleem als we via Google Analytics metingen willen doen. Er is bij een betaling geen onderscheid te maken tussen een eerste handmatige iDeal betaling en opvolgende automatische recurring betalingen.

We hebben in Gravity Forms een productveld genaamd '€10 Lidmaatschap'. Hoe zorgen wij ervoor dat bij een automatische recurring betaling, er een onderscheid gemaakt kan worden? Bijvoorbeeld '€10 recurring'.

@rvdsteege mentioned the following custom solution:

Er is een WordPress filter pronamic_pay_google_analytics_ecommerce_item_name waarop je kunt inhaken om de naam van het item dat naar GA wordt gestuurd aan te passen. Zie documentatie:

Via $line->get_payment() kun je dan de Pronamic Pay betaling opvragen. De manier om te controleren of het om een terugkerende betaling gaat of niet, is net aan het wijzigen binnen onze plugin. Je kunt daarvoor daarom het beste het volgende codevoorbeeld gebruiken:

$is_recurring = \method_exists( $payment, 'get_recurring' ) ? $payment->get_recurring() : 'recurring' === $payment->get_meta( 'mollie_sequence_type' );

The customer unfortunately failed to implement this and asked us to implement this.

Somewhat related:

rvdsteege commented 2 years ago

Sample code (untested) for Pronamic Pay version >= 8.0:

\add_filter( 'pronamic_pay_google_analytics_ecommerce_item_name', 'pronamic_pay_ecommerce_recurring_item_name', 10, 2 );

function pronamic_pay_ecommerce_recurring_item_name( $name, $line ) {
    if ( 'recurring' !== $line->get_payment()->get_meta( 'mollie_sequence_type' ) ) {
        return $name;
    }

    return \sprintf( '%s (recurring)', $name );
}
remcotolsma commented 1 year ago

This has not come up in recent months, so I am marking this issue as not planned for now, also because the current Google Analytics integration will end on July 1, 2023.

Google Analytics 4 is our next-generation measurement solution, and it's replacing Universal Analytics. On July 1, 2023, standard Universal Analytics properties will stop processing new hits. If you still rely on Universal Analytics, we recommend that you prepare to use Google Analytics 4 going forward.

Originally posted by @LeoOosterloo in https://github.com/pronamic/wp-pronamic-pay/discussions/311#discussioncomment-2477630

If we start supporting Google Analytics 4, this will probably be included in a separate (premium) add-on.