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

fix(sync): strip unsuffixed UTM meta keys from normalized contact data #3623

Open
wants to merge 3 commits into
base: release
Choose a base branch
from

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Dec 12, 2024

All Submissions:

Changes proposed in this Pull Request:

For ESP metadata data syncing, UTM-related meta keys must have a suffix to denote the particular UTM parameter. These are typically:

  • source
  • medium
  • campaign
  • term
  • content

Although some publishers/marketers might create their own non-standard parameters for custom analytics purposes. However, some UTM parameter suffix must be present in order to be synced to the ESP contact. We should never be syncing a meta field like NP_Payment UTM: to the ESP. We've seen this happen in the wild at times, resulting in useless unsuffixed meta fields being created in the connected ESP and polluting the publishers' data.

This PR safeguards against this issue going forward by stripping unsuffixed UTM-related meta fields from normalized contact data.

Bad fields will not be automatically removed from connected ESP accounts that already have them. To remove them, use the new wp newspack esp merge-fields delete CLI command included here.

How to test the changes in this Pull Request:

I was unable to replicate the conditions in which unsuffixed UTM fields are added to contact metadata, but you can test by manually adding some using WP shell:

  1. Under Newspack > Engagement > Reader Activation > Advanced Settings > Sync contacts to ESP, make sure syncing is enabled and both Signup UTM and Payment UTM fields are enabled for syncing.
  • Note: You might need to add a NEWSPACK_FORCE_ALLOW_ESP_SYNC constant to wp-config.php and ensure that Newspack Subscriptions is in live mode in order to enable ESP contact syncing.
  1. While on release, start a wp shell session.
  2. Get some contact data: $contact = Newspack\Reader_Activation\Sync\WooCommerce::get_contact_from_customer( <user ID> );
  3. Add some unsuffixed UTM params to the contact data (make sure you use both a prefixed key and a "raw" key): $contact['metadata'] = array_merge( $contact['metadata'], [ 'NP_Signup UTM: ' => 'foo', 'payment_page_utm' => 'bar' ] );
  4. Normalize the contact data: $normalized = Newspack\Reader_Activation\Sync\Metadata::normalize_contact_data( $contact )
  5. On release, observe that the unsuffixed UTM keys are still present on the normalized contact data. If this data is synced to the ESP using Newspack\Reader_Activation\ESP_Sync::sync( $contact ), the unsuffixed keys will be synced as contact meta fields in the ESP.
  6. Terminate the wp shell session and check out this branch.
  7. Start a new wp shell session and repeat steps 3–6 but confirm that the unsuffixed keys are stripped from the contact data by normalize_contact_data.
  8. Smoke test completing a transaction from a page with UTM params in the URL and confirm that the suffixed NP_Payment UTM fields are still synced with the URL params.

CLI command to delete merge fields

This PR also includes a new CLI command to delete Mailchimp merge fields. This can be used to identify and delete unwanted fields from the connected Mailchimp account.

  1. In your connected Mailchimp account, go to Audience > All contacts > Settings > Audience fields & *MERGE* tags and add unsuffixed merge fields (NP_Signup UTM: , NP_Payment UTM: ). Also make sure you have or add some suffixed fields too (NP_Signup UTM: campaign, NP_Payment UTM: content, etc.).
  2. Run wp newspack esp merge-fields delete --fields=payment_page_utm,signup_page_utm --dry-run. Confirm that the script reports (but doesn't delete) the matching unsuffixed fields, and does NOT report the suffixed fields:
Would delete merge field NP_Payment UTM:.
Would delete merge field NP_Signup UTM:.
Success: Would delete 2 merge fields.
  1. Run wp newspack esp merge-fields delete --fields=payment_page_utm,signup_page_utm and confirm that the fields are deleted from Mailchimp.
  2. Re-run it but specify a suffixed field (e.g. wp newspack esp merge-fields delete --fields=payment_page_utm_content) and confirm that the matching suffixed field is reported/deleted.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo added [Status] Needs Review The issue or pull request needs to be reviewed Reader Activation labels Dec 12, 2024
@dkoo dkoo self-assigned this Dec 12, 2024
@dkoo dkoo requested a review from a team as a code owner December 12, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reader Activation [Status] Needs Review The issue or pull request needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant