OCHA-DAP / hdx-signals

HDX Signals
https://un-ocha-centre-for-humanitarian.gitbook.io/hdx-signals/
GNU General Public License v3.0
6 stars 0 forks source link

make email tagging process more clear #258

Open zackarno opened 1 week ago

zackarno commented 1 week ago

It is probably more of a me problem, but it took me a good hour to figure out how emails were designated as test. This all spawned from testing test-custom_segmentation and slowly stepping through function and trying to understand each piece. Eventually I was lead to the tag_emails() function in custom-segmentation.R

https://github.com/OCHA-DAP/hdx-signals/blob/37fd8ab78787c40c7ad93911a741be306e4e52f7/src/email/mailchimp/custom_segmentation.R#L140-L161

which appears to be controlling it and is 1 of the 2 places in this .R script where hs_dry_run() is used... However, in my testing/debugging when I eventually make it to mc_subscriber_emails() it's not actually used as the df_ind$mc_interest var is not NA. It' not clear to me from the comments when this would be NA or not - there are 2 comments that I don't fully understand that I think are related.

https://github.com/OCHA-DAP/hdx-signals/blob/37fd8ab78787c40c7ad93911a741be306e4e52f7/src/email/mailchimp/custom_segmentation.R#L98-L107

So anyway that leads me to interest_emails() func which also has the hs_dry_run().... now after staring at this code chunk for quite some time ....

https://github.com/OCHA-DAP/hdx-signals/blob/37fd8ab78787c40c7ad93911a741be306e4e52f7/src/email/mailchimp/custom_segmentation.R#L114-L134

i think I MIGHT GET IT... Basically, no matter what it loops through all relevant members of interest group, if hs_dry_run() is FALSE it skips it would do some matching and actually give you the email address. If TRUE (default) ...it would .... wait what!? WRONG -THATS NOT IT, I thought I was on to it...

okay so now! it looks like the test emails are being controlled by something completely different than hs_dry_run() and in fact they are a "hdx-signals-test" attribute that is tored as a tag attribute for each member. This must be done externally by some process/setting on mailchimp website? So anyways the conditional on line 120 of last code chunk says that if this tag is present return the email address.

So there we have it, I think I got there in the end, but will leave this brain dump here in the hopes that it will inspire us to simplify this. Don't see why it is not as simple as filtering a data.frame to the email addresses designated as test emails. I see the desire to pull from the mailchimp server, but geeeesh, thats tricky