Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make email tagging process more clear #258

Open
zackarno opened this issue Nov 12, 2024 · 0 comments
Open

make email tagging process more clear #258

zackarno opened this issue Nov 12, 2024 · 0 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@zackarno
Copy link
Collaborator

zackarno commented Nov 12, 2024

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

tag_emails <- function(interest_tag, geo_ids) {
purrr$map_chr(
.x = member_list,
.f = \(member) {
member_tags <- purrr$map_chr(member$tags, \(tag) tag$name)
interest_tag <- interest_tag %in% member_tags
if (interest_tag && (!hs_dry_run$hs_dry_run() || "hdx-signals-test" %in% member_tags)) {
# only check for locations if they were interested in the indicator
# returns email if they were signed up to any of the geographies signalled
# otherwise it returns an empty character vector
if (any(as.logical(member$interests[geo_ids]))) {
return(
member$email_address
)
}
}
return(
NA_character_
)
}
)
}

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.

# filter members to the specific indicator, by interest if a public subscription
# otherwise we filter by manual tagging for indicators that are privately added
if (!is.na(df_ind$mc_interest)) {
member_emails <- interest_emails(interest = df_ind$mc_interest, geo_ids = geo_ids)
} else {
# keeps members tagged with this indicator
member_emails <- tag_emails(interest_tag = df_ind$mc_tag, geo_ids = geo_ids)
}
member_emails[!is.na(member_emails)]
}

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 ....

dry_run <- hs_dry_run$hs_dry_run()
purrr$map_chr(
.x = member_list,
.f = \(member) {
ind_interest <- member$interests[[interest_id]]
if (ind_interest && (!dry_run || "hdx-signals-test" %in% purrr$map_chr(member$tags, \(tag) tag$name))) {
# only check for locations if they were interested in the indicator
# returns email if they were signed up to any of the geographies signalled
# otherwise it returns an empty character vector
if (any(as.logical(member$interests[geo_ids]))) {
return(
member$email_address
)
}
}
return(
NA_character_
)
}
)

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

@zackarno zackarno added enhancement New feature or request question Further information is requested labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant