Find a way to exclude donors who have a single recurring donation in 2024 (those who initiated a recurring donation in December or have had only one processed in 2024) from the thank you campaign.
Note: This has been approved by Mariana and legal.
Context: To better assist donors who may need help updating or canceling their donations, we’d like to minimize any unnecessary back-and-forth that arises from confusion caused by emails sent to one-time donors and deceased donors. Here are some examples:
CIDs 60803149, 39147378, and 47609686 each had only one donation in 2023 and received the summary receipt.
Description
Details
| Subject | Author | Repo | Branch | Lines +/- | |
|---|---|---|---|---|---|
| Update EOYMakeJob to exclude one-off | Eileen | wikimedia/fundraising/crm | master | +57 -7 | |
| Remove old EOY data | Eileen | wikimedia/fundraising/crm | master | +5 -1 |
Related Objects
- Mentioned In
- T413907: Suppress recurrings with only one charge from the recurring email receipt
T381781: Request to please begin the deployment of the Auto TY email receipt ("End of Year Receipt") on January 13th (date changed from Jan 6th)
T380330: Check that end of year (EOY) email receipt templates are ready for January 2025 and send them
Event Timeline
There are a high volume of donations like this (Sandra has included a few examples above).
These are cases where an unintentional recurring donation was started and then cancelled but the supporter opted to leave the donation with us. They receive their initial receipt, however receiving the summary in January causes confusion in many cases - the donor wonders if their recurring was cancelled at all, they are worried they will get charged again etc.
Our goal is to filter for single recurring transactions - where a donor has made a single recurring gift then cancelled their recurring donations going forward, and suppress them from the TY summary.
Change #1107574 had a related patch set uploaded (by Eileen; author: Eileen):
[wikimedia/fundraising/crm@master] Remove old EOY data
There are 2 ways to do this - with slightly different results
Baseline - current query as run on staging
INSERT INTO wmf_eoy_receipt_donor (year, email, status) SELECT 2024, email.email, 'queued'
FROM civicrm_contribution_recur contribution_recur
INNER JOIN civicrm_contribution contribution ON contribution.contribution_recur_id =
contribution_recur.id
INNER JOIN civicrm_email email
ON email.contact_id = contribution.contact_id
AND email.is_primary
INNER JOIN civicrm_contact contact ON contact.id = email.contact_id
AND contact.is_deleted = 0
LEFT JOIN wmf_eoy_receipt_donor eoy ON email.email = eoy.email AND eoy.year = 2024 WHERE receive_date BETWEEN '2024-01-01 10:00:00' AND '2025-01-01 09:59:59' AND contribution.contribution_status_id = 1 AND eoy.email IS NULL AND contribution_recur.frequency_unit != 'year'
GROUP BY email.email;Query OK, 892611 rows affected (5 min 31.411 sec)
- Alter the main query to this - I just tested on staging & it took 8 mins - although I did do this first https://gerrit.wikimedia.org/r/c/wikimedia/fundraising/crm/+/1107574?usp=dashboard
Query OK, 839155 rows affected (8 min 19.149 sec)
INSERT INTO wmf_eoy_receipt_donor (year, email, status)
SELECT 2024, email, 'queued'
FROM (SELECT email.email, count(*) as c
FROM civicrm_contribution_recur contribution_recur
INNER JOIN civicrm_contribution contribution
ON contribution.contribution_recur_id = contribution_recur.id
INNER JOIN civicrm_email email
ON email.contact_id = contribution.contact_id
AND email.is_primary
INNER JOIN civicrm_contact contact ON contact.id = email.contact_id
AND contact.is_deleted = 0
LEFT JOIN wmf_eoy_receipt_donor eoy ON email.email = eoy.email AND eoy.year = 2024
WHERE receive_date BETWEEN '2024-01-01 10:00:00' AND '2025-01-01 09:59:59'
AND contribution.contribution_status_id = 1
AND eoy.email IS NULL
-- We exclude annual recurring contributions when deciding WHO to email.
-- if they have an annual recurring AND a monthly then both (all) donations
-- will still be included in the WHAT to email.
AND contribution_recur.frequency_unit != 'year'
GROUP BY email.email
HAVING c > 1) as emails- Run the original query and then DELETE any rows with only 1 contribution in the year
At the margin this will get more contacts - as the first query requires them to have more than 1 for any given recurring contribution (ie would not pick up 2 contributions against 2 separate attempts to set up recurring contributions). I think a case could be made either way - the 2 separate attempts would have had emails at the time
- currently running this for timing
DELETE FROM wmf_eoy_receipt_donor WHERE email IN (
SELECT email FROM
(
SELECT d.email, count(c.id) as n FROM wmf_eoy_receipt_donor d
LEFT JOIN civicrm_email e ON e.email = d.email
AND is_primary = 1
LEFT JOIN civicrm_contribution c ON e.contact_id = c.contact_id
AND receive_date BETWEEN '2024-01-01 10:00:00' AND '2025-01-01 09:59:59'
AND contribution_status_id = 1
GROUP BY d.email
HAVING n < 2) as m);That second one didn't get there but this worked
CREATE TABLE wmf_eoy_no_email (
`email` varchar(254) DEFAULT NULL,
INDEX email(email));
INSERT INTO wmf_eoy_no_email
SELECT email FROM
(
SELECT d.email, count(c.id) as n FROM wmf_eoy_receipt_donor d
LEFT JOIN civicrm_email e ON e.email = d.email
AND is_primary = 1
-- this is a cheap way to drop out the ones that are on hold.
AND on_hold = 0
LEFT JOIN civicrm_contribution c ON e.contact_id = c.contact_id
AND receive_date BETWEEN '2024-01-01 10:00:00' AND '2025-01-01 09:59:59'
AND contribution_status_id = 1
GROUP BY d.email
HAVING n < 2) as m;
--- Query OK, 60242 rows affected (3 min 19.405 sec)
DELETE d FROM wmf_eoy_receipt_donor d INNER JOIN wmf_eoy_no_email e ON e.email = d.email;
--- Query OK, 60242 rows affected (1.423 sec)
DROP TABLE wmf_eoy_no_email;Change #1108496 had a related patch set uploaded (by Eileen; author: Eileen):
[wikimedia/fundraising/crm@master] Update EOYMakeJob to exclude one-off
We agreed on the option where we only include donors who have more than one donation on a single recurring record - meaning that they will have at least 1 unreceipted donation
Change #1107574 merged by jenkins-bot:
[wikimedia/fundraising/crm@master] Remove old EOY data
Change #1108496 merged by jenkins-bot:
[wikimedia/fundraising/crm@master] Update EOYMakeJob to exclude one-off