Page MenuHomePhabricator

Need to see UTM Source/UTM Campaign in Civi
Closed, ResolvedPublic2 Estimated Story Points

Description

The contribution record currently doesn't show the UTM source and/or UTM campaign.

We need to be able to track which donations resulted from specific landing pages.

Example: CID 13456878 donated via the MG annual appeal email, but we have no way of telling in Civi that he donated via the Benefactor level specific landing page.

Thanks for your help!

Event Timeline

LeanneS raised the priority of this task from to Unbreak Now!.
LeanneS updated the task description. (Show Details)

@LeanneS can you provide some information to help us prioritize this work?

  1. this is the appeal landing page:

https://donate.wikimedia.org/w/index.php?title=Special:FundraiserLandingPage&appeal=Appeal-MGAnnual&form-countryspecific=Form-countryspecific-MGAnnual&utm_medium=MGAnnual&utm_source=MGAnnual_2015&utm_campaign=MGAnnual_2015

@CCogdill_WMF can you verify that link is correct?

  1. We need donations made on this page to appear in Civi as Direct Mail Appeal: Fundraiser Mailing 2015

Timing: We need this today or tomorrow.

Thanks @CaitVirtue and @LeanneS. I'm hearing that this is high priority... and now see that it's "Unbreak Now!"
Right now, Tech is working on some critical issues for the online campaign.
We'll plan to triage this on Monday and get back to you about complexity. Moving to "high" priority.

atgo lowered the priority of this task from Unbreak Now! to High.Dec 11 2015, 11:33 PM

If we're going to wait until Monday, we should add in a solution to bulk correct all the donations that are coming in without this designation. Given the volume of records, it will be very time consuming to correct all of them by hand.

@CaitVirtue they are being noted in the database with the utm_campaign (I just checked using mysql), so we probably just need to figure out how to surface this in the UI.

I can help @LeanneS get a list of all the donations from this utm_campaign,
if tech can help us import the data into Civi.

Timing: We need this today or tomorrow.

Geez. Okay, there are complications here. We used to dump utm_campaign into the Appeal (direct_mail_appeal) column, but we had to stop with the recent Civi upgrade because that's a multiple-choice column rather than freeform text.

For the short term, the best workaround is if you create a new option here:
https://civicrm.wikimedia.org/civicrm/admin/options?gid=39&reset=1
which exactly matches the utm_campaign string in your appeals. *However* that must happen before you send out the mailings, so it's probably too late for whatever you're trying to do.

The long-term solution is to create a new free-text custom fields, and we'll go back to storing utm_* data directly into these.

The data is all available by joining with contribution_tracking, where the raw utm_campaign is stored, so a backfill script would be easy to write.

@CaitVirtue does the ease of backfilling address your concerns?

@atgo All I understand in Adam's comments is "a backfill script would be easy to write." Does that mean this will be easy to correct this week? Both the past and future donations on this page?

@CaitVirtue - the donations are being tagged with the Campaign, just not in a way that we're able to surface in civi right now. What that means is that we should be able to correct the records that are wrong pretty easily with a script (yay!).

I'm not 100% confident in how easy it'll be to fix this such that it appears in Civi for new donations, say, by Monday. But knowing that we have the data tracked means that at a minimum we can pull that data for you daily or something until we have the fix out. I'm happy to do that manually with support from tech if that's what's needed.

@Eileenmcnaughton this is top priority to at least have a stop-gap solution in place. Thanks!

Change 258918 had a related patch set uploaded (by Eileen):
CRM-17700 allow contribution get to bypass permissions

https://gerrit.wikimedia.org/r/258918

Change 258919 had a related patch set uploaded (by Eileen):
T121284 fix direct_mail field check

https://gerrit.wikimedia.org/r/258919

Change 258920 had a related patch set uploaded (by Eileen):
Add tests for campaign field check.

https://gerrit.wikimedia.org/r/258920

The scripts transfer the information from the utm_campaign field to the custom field that shows the direct mail. Not all the utm_campaign possibilities are really direct mail campaigns but prior to the upgrade CiviCRM api would accept any data and store it in the custom field. After the upgrade CiviCRM started validating against the options configured here civicrm/admin/options?gid=39&reset=1

At first I though just enabling the options would cause them to start coming in but a minor error in early Nov added a check in the script but used the title rather than the name field, resulting in no values being passed through.

There is a patch for that here https://gerrit.wikimedia.org/r/#/c/258919/

I also added a test, but the test https://gerrit.wikimedia.org/r/#/c/258920/ depends on a CiviCRM fix https://issues.civicrm.org/jira/browse/CRM-17700 | https://gerrit.wikimedia.org/r/#/c/258918/ being merged & then a submodule commit.

Note that once the patch has been applied the correct options need to be configured. There are a lot of options we are currently ignoring and I presume that we want to continue to ignore most of them.

In terms of potentially missing data this query gives a list of contributions since the start of Oct which have a campaign which has not been put into the direct mail appeal field:

SELECT * FROM (SELECT min(ts), utm_campaign, count(*) as c FROM drupal.contribution_tracking LEFT JOIN civicrm.civicrm_contribution c ON c.id = contribution_id LEFT JOIN civicrm.civicrm_value_1_gift_data_7 v ON v.entity_id = c.id WHERE ts > '20151001' AND c.id IS NOT NULL AND ts IS NOT NULL AND v.appeal IS NULL
GROUP BY utm_campaign ) as m ORDER BY c DESC;

+----------------+--------------------------------+--------+

min(ts)utm_campaignc

+----------------+--------------------------------+--------+

20151001070501C1516_en6C_dsk_FR934346
20151001000002C15_Email1563321
20151001170451C1516_frFR_dsk_hi_FR111758
20151001070625C1516_en6C_mob_FR108530
20151005080259C1516_itIT_dsk_hi_FR92864
20151104150237C1516_enWW_dsk_lw_FR41747
20151001070544C1516_en6C_ipd_FR38535
20151001170133C1516_enFR_dsk_hi_FR18469
20151012181303C1516_itIT_mob_FR18164
20151001005506C13_en.wikipedia.org17892
20151016170500C1516_frFR_mob_hi_FR14162
20151001024147C11_Waystogive10804
20151005080045C1516_enIT_dsk_hi_FR10506
20151104150351C1516_mlWW_dsk_lw_FR8912
20151202172301C1516_frCA_dsk_FR8276
20151001061819NULL7186
20151016170433C1516_frFR_ipd_hi_FR6245
20151021080249C1516_enGB_dsk_FR6245
20151012180800C1516_itIT_ipd_FR5442
20151001084156spontaneous5246
20151130145050C1516_enAUNZ_dsk_FR4404
20151001003116C15_mlWW_dsk_lw_FR3876
20151001000040C1516_enUS_dsk_FR3615
20151001012503C15_enWW_dsk_lw_FR3570
20151202165718C1516_en6C_dsk_backup_FR3498
20151104191521C1516_enWW_mob_lw_FR3277
20151001072617C13_fr.wikipedia.org3180
20151001082602C13_wikimediafoundation.org2546
20151005130626C1516_ptBR_dsk_hi_FR2065
20151001055502C13_it.wikipedia.org1995
20151002173937C14_Email11745
20151104193316C1516_enWW_ipd_lw_FR1601
20151001025318ThankYouPage1261
20151012181101C1516_enIT_mob_FR1226
20151005130425C1516_enBR_dsk_hi_FR1036
20151016170521C1516_enFR_mob_hi_FR1023
20151001044145C1516_enBELU_dsk_hi_FR1013
20151104203945C1516_mlWW_mob_lw_FR954
20151001032312C1516_frBELU_dsk_hi_FR913
20151001075300C15_mlWW_mob_lw_FR896
20151104214052C1516_mlWW_ipd_lw_FR675
20151001042642C1516_nlBELU_dsk_hi_FR670
20151016170431C1516_enFR_ipd_hi_FR624
20151001042526C1516_mlBELU_mob_hi_FR610
20151210220112MGAnnual_2015589
20151005131725C1516_ptBR_mob_hi_FR520
20151012182438C1516_enIT_ipd_FR506
20151001082116C13_de.wikipedia.org427
20151001024216C15_mlWW_ipd_lw_FR388
20151001172432C13_es.wikipedia.org349
20151001024538C1516_mlBELU_ipd_hi_FR334
20151001042210C15_enWW_mob_lw_FR294
20151001053730C1516_deBELU_dsk_hi_FR234
20151115160735Android215
20151001081241C15_enWW_ipd_lw_FR168
20151005135342C1516_enBR_mob_hi_FR155
20151001130310C13_nl.wikipedia.org148
20151005144405C1516_ptBR_ipd_hi_FR130
20151029131244C13_ja.wikipedia.org127
2015100103063720120521SB001112
20151003193256C13_zh.wikipedia.org92
20151002090819C13_sv.wikipedia.org80
20151005133359C1516_enBR_ipd_hi_FR47
20151001045142C14_Email243
20151010153541C13_meta.wikimedia.org31
20151013191257C13_pl.wikipedia.org28
20151002135523C13_da.wikipedia.org26
2015110200393920101204SB00225
20151013165823C13_cs.wikipedia.org23
20151006224629C13_no.wikipedia.org22
20151011054041C_FAQ21
20151010180054C13_hu.wikipedia.org21
20151001140148C13_ca.wikipedia.org19
20151003085413C13_ru.wikipedia.org19
20151102053620C16_Email117
20151126193224buffer14
20151108135418C13_en.wikinews.org14
20151002210108C13_he.wikipedia.org12
20151006074108C13_simple.wikipedia.org11
20151124120101C11_SocialMedia10
20151024191235C13_en.wiktionary.org10
2015120611081820120717SB00110
20151125190717C13_en.wikibooks.org9
20151110154508C13_ro.wikipedia.org8
20151021101427C13_fr.wiktionary.org7
20151006071452C13_uk.wikipedia.org7
20151004180955C12_en.wikipedia.org7
20151106201919C13_en.wikiquote.org5
20151006021430C13_en.wikiversity.org5
20151003160238C13_en.wikisource.org4
20151023112930C13_wikisource.org4
20151029065919C13_sl.wikipedia.org4
20151004183409C13_sk.wikipedia.org4
20151026171416C13_tr.wikipedia.org4
20151121180927xkcd_april14
20151111113215C13_zh-yue.wikipedia.org3
20151105064119C13_ko.wikipedia.org3
20151002075848C13_fr.wikiversity.org3
20151118171445MajorGifts20143
20151128175539C13_wikidata.org3
20151006064258C13_lv.wikipedia.org3
20151031130714C13_bg.wikipedia.org3
20151125065220C13_th.wikipedia.org2
20151126164416C13_lt.wikipedia.org2
20151010180317C13_eo.wikipedia.org2
20151104090020C14_en5C_dec_dsk_FR2
20151030153058C13_ru.wiktionary.org2
20151031080256C13_fr.wikinews.org2
20151031102508C13_it.wikibooks.org2
20151105220300C13_Email12
20151129232707C11_Foundationwiki_US2
20151104085556C12_nl.wikipedia.org2
20151107073453C13_zh.wikinews.org2
20151121100736C13_wpnd_zhCN_FR2
20151118025526C13_vi.wikipedia.org2
20151031030150C13_se.wikipedia.org1
20151116173802C11_1114_AvsB_IT1
20151104235702none1
20151207173652C12_iwpdeW1_FR_AT1
20151118054819C13_zh.wiktionary.org1
20151108204807C13_ur.wikipedia.org1
20151128164516C13_ar.wikipedia.org1
20151031203652C13_de.wikinews.org1
20151208164258C13_ta.wikipedia.org1
20151122215023C12_it.wikivoyage.org1
20151122223101C13_or.wikipedia.org1
2015111419534820111228EM21
20151210053446C13_it.wikisource.org1
20151127174352C13_zh-classical.wikipedia.org1
20151004115911C1516_enfrnldeBELU_dsk_hi_FR1
20151202093701C13_fa.wikipedia.org1
20151213224244C13_bn.wikipedia.org1
20151101031657C13_ka.wikipedia.org1
20151104044901C13_de.wiktionary.org1
20151111150710C13_oc.wikipedia.org1
20151129161639C14_mlWW_dsk_lw_FR1
20151206043108C11_1122_SYMBOLS_JP_JP1
20151129132812C13_fr.wikisource.org1
20151201151838reddit-wikipedia1
20151127154215C12_iwpfrCA_FR_CA1
20151103144513C13_it.wikiquote.org1
20151213213618C13_cy.wikipedia.org1
20151109131444C13_species.wikimedia.org1
20151202015553knoppix1
20151201223345C13_ja.wiktionary.org1
20151206133056C13_zh.wikibooks.org1
20151104110857C14_frFR_dsk_FR1

+----------------+--------------------------------+--------+

Here is the query & result for those appeals that have been configured

SELECT * FROM (SELECT min(ts), utm_campaign, count(*) as c FROM drupal.contribution_tracking LEFT JOIN civicrm.civicrm_contribution c ON c.id = contribution_id LEFT JOIN civicrm.civicrm_value_1_gift_data_7 v ON v.entity_id = c.id WHERE ts > '20151001' AND c.id IS NOT NULL AND ts IS NOT NULL AND v.appeal IS NULL AND utm_campaign IN ( SELECT value COLLATE utf8_unicode_ci FROM civicrm.civicrm_option_value ov WHERE ov.option_group_id=39 AND is_active = 1 ) GROUP BY utm_campaign ) as m ORDER BY c DESC;

+----------------+----------------+-----+

min(ts)utm_campaignc

+----------------+----------------+-----+

20151210220112MGAnnual_2015589
20151118171445MajorGifts20143

+----------------+----------------+-----+
2 rows in set (1 min 37.17 sec)

And assuming we configure the correct mail groups first then we can then run an upgrade script. It would be close to this

UPDATE
drupal.contribution_tracking

LEFT JOIN civicrm.civicrm_contribution c ON c.id = contribution_id
LEFT JOIN civicrm.civicrm_value_1_gift_data_7 v ON v.entity_id = c.id
SET v.appeal = utm_campaign

WHERE
ts > '20151001' AND
c.id IS NOT NULL
AND v.appeal IS NULL
AND utm_campaign IN (

SELECT value COLLATE utf8_unicode_ci FROM civicrm.civicrm_option_value ov WHERE ov.option_group_id=39 AND is_active = 1

)
;

However, that sql involves 2 DBs & I'm not sure if that is outside the scope of a drupal upgrade script to touch 2 dbs in one query like that - since I assume there are mysql user permission issues. I might discuss that with others tomorrow & switch to the other issue for now.

Re longer term - options include always adding the option for the direct mail before doing a new mailing, adding a hook to the option value so that a script like the above runs when an option value is enabled, adding options on-the-fly when data comes in or switching to a text field like awight suggested. Probably worth a conversation as it's mostly about what is most usable for people

Hey @Eileenmcnaughton, does this mean that the team will need to run sql
queries to get reports for this one? We can check in tomorrow if that's
easier.

So, I do have a habit of putting lots of info on tickets :-)

What it means is

  1. the team should determine which of the above list of campaigns they want recorded as direct mailing options - & together we can add them to the configured options
  2. once the code is reviewed & deployed real-time updates will happen for all the configured options from that point on
  3. we need to run a script / query to backfill the missed data. I will check with the others the best way to do that.

We should be able to get that all sorted tomorrow.

Ok, let me confirm my understanding here, mostly for @CaitVirtue and
@CCogdill_WMF

We have these 2 campaigns: "MGAnnual_2015" and "MajorGifts2014". The team
needs to confirm that they want both of these to be possibilities for the
"Direct Mail Appeal" field.

Once that's decided, @Eileenmcnaughton + fr-tech will do some work to
update the old records and make sure the new ones come in labeled
appropriately. The new records fix will likely happen before the old ones
are backfilled.

ok I've been talking to @awight. So the longer list is all the campaigns that are getting donations at all right now, which we haven't historically surfaced in the UI. We could change this, but I think that's out of scope for what @CaitVirtue and @CCogdill_WMF are looking for here. Can you 2 confirm?

I'm staying out of this decision and leaving it to @CaitVirtue. The
categorization of these campaigns doesn't impact my work — I was just
trying to help Leanne find the data she needed as a workaround.

Eileenmcnaughton set Security to None.

I'm putting this in review because this patch

https://gerrit.wikimedia.org/r/258919

needs review.

However, it needs more work on the update script

Change 259161 had a related patch set uploaded (by Eileen):
CRM-17691 add the campaign id to selector even though it ? is not used?

https://gerrit.wikimedia.org/r/259161

Change 259185 had a related patch set uploaded (by Eileen):
Add script to fill missing appeal data

https://gerrit.wikimedia.org/r/259185

In discussion with Anne I renamed the option 'MGAnnual_2015' to "Fundraiser Mailing 2015" (the value needs to match utm_campaign - the label can be as desired). There was an existing option with that label but only 3 contributions had been given it. I updated those 3 to have the renamed field (via the UI).

The patch (waiting review) for bringing this data across correctly in future is https://gerrit.wikimedia.org/r/#/c/258919/

I'm still completing the script for filling missing entries but this is in the review column since the above patch needs review

@Eileenmcnaughton - now that I'm thinking about it, can you identify those
3 contributions for @LeanneS to confirm? Thanks

They are still the only 3 contributions with that option!

NB - I think the update script is OK now - I'm going to rebase it once the other is merged since it was being wierd on me. There wasn't as much data on staging to be updated but I found some evidence of success doing queries -

https://gerrit.wikimedia.org/r/#/c/259185/

Change 258919 merged by jenkins-bot:
Fix direct_mail field check

https://gerrit.wikimedia.org/r/258919

Change 259161 merged by jenkins-bot:
CRM-17691 add the campaign id to selector even though it ? is not used?

https://gerrit.wikimedia.org/r/259161

Clarification: The 3 records are tagged properly, but they did not get tagged that way via the online form. Leanne used them as test cases when she did the most recent Engage import.

A couple more are tagged now - I'll do some mysql checks tomorrow & fix up the issues from CR in the upgrade script

Change 259185 merged by jenkins-bot:
Add script to fill missing appeal data

https://gerrit.wikimedia.org/r/259185

The upgrade script is pending deploy now - @awight - I think it might be up to a 30 sec upgrade query - does that suggest I need to ? stop queues? It potentially locks the contribution_tracking table which I think is more serious than the Civi ones...

Numbers are looking good now - ok to close @CaitVirtue ?

I think so. When I search via Find Contributions for Direct Mail Appeal = Fundraising Mailing 2015, I'm seeing 1294 donations with that tag.

@LeanneS does that seem right to you?

Followup task: it would be great to have access to the contribution_tracking ID from Civi.

Change 258918 merged by jenkins-bot:
(merged into 4.7) CRM-17700 allow contribution get to bypass permissions

https://gerrit.wikimedia.org/r/258918

Change 258920 merged by Eileen:
Add tests for campaign field check.

https://gerrit.wikimedia.org/r/258920

OK, I believe this is fixed.

Change 285805 had a related patch set uploaded (by Eileen):
CRM-17691 add the campaign id to selector even though it ? is not used?

https://gerrit.wikimedia.org/r/285805

Change 285816 had a related patch set uploaded (by Eileen):
(merged into 4.7) CRM-17700 allow contribution get to bypass permissions

https://gerrit.wikimedia.org/r/285816

Change 285805 merged by Eileen:
CRM-17691 add the campaign id to selector even though it ? is not used?

https://gerrit.wikimedia.org/r/285805

Change 285816 merged by Eileen:
(merged into 4.7) CRM-17700 allow contribution get to bypass permissions

https://gerrit.wikimedia.org/r/285816