Google Analytics distinguish between first and automatic recurring payments
remcotolsma opened this issue · comments
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:
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 );
}
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.