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

feat(data-events): mailchimp connector #2233

Merged
merged 15 commits into from
Jan 26, 2023
Merged

Conversation

miguelpeixe
Copy link
Member

@miguelpeixe miguelpeixe commented Jan 17, 2023

All Submissions:

Changes proposed in this Pull Request:

Implements the Mailchimp connector using Data Events, producing a result similar to what is achieved for ActiveCampaign with RAS.

Just like the AC implementation, this also requires a "master list", or a single audience, to send the data to. It will automatically fetch from the "Mailchimp for WooCommerce" plugin setting if it's not configured in the RAS setting mailchimp_audience_id.

The UI for configuring Mailchimp's master list should be built next, not in this PR.

The data transformation borrows the logic from WooCommerce_Connection, by moving the contact generation portion to a get_contact_from_order( $order ) method so it can be reused.

The same logic used for ActiveCampaign in Newspack\Newspack_Newsletters is not reproduced, meaning:

  • No UTM integration
  • NP_Product Name is removed. This value will change with every different purchase, it's not clear to me the purpose of treating it as a singular contact data. Perhaps we need a better strategy for this?

The contact is upserted as soon as registered, with status set to transactional if it's new (not yet subscribed), through a handler attached to the reader_registered action.

Purchase updates are sent through a handler at the donation_new action. The order data is transformed with WooCommerce_Connection::get_contact_from_order( $order );.

How to test the changes in this Pull Request:

  1. Make sure you have the following constants:
define( 'NEWSPACK_AMP_PLUS_ENABLED', true );
define( 'NEWSPACK_EXPERIMENTAL_READER_ACTIVATION', true );
define( 'NEWSPACK_LOG_LEVEL', 2 );
  1. Make sure you have Mailchimp connected and reader revenue configured with either Stripe or Newspack platform
  2. Install the Mailchimp for WooCommerce plugin configure with the same account and set it to an audience (this is required only until we have our own UI for setting the master list)
  3. Configure a Reader Registration prompt
  4. In a fresh session, register a reader through the prompt without subscribing to newsletters
  5. Wait until Executing action handlers for "reader_registered" is logged
  6. Confirm the contact is created in Mailchimp with the status transactional and the following merge fields filled:
    1. NP_Account
    2. NP_Registration Page
    3. NP_Registration Method
  7. Make a purchase and confirm the data from get_contact_from_order() is updated to the same contact
  8. Through the "My Account" page subscribe to the newsletter and confirm the you're subscribed without any merge field data being altered/removed

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?

@miguelpeixe miguelpeixe self-assigned this Jan 19, 2023
@miguelpeixe miguelpeixe marked this pull request as ready for review January 19, 2023 18:21
@miguelpeixe miguelpeixe requested a review from a team as a code owner January 19, 2023 18:21
@miguelpeixe miguelpeixe added the [Status] Needs Review The issue or pull request needs to be reviewed label Jan 19, 2023
@miguelpeixe miguelpeixe requested a review from adekbadek January 19, 2023 18:22
@miguelpeixe
Copy link
Member Author

Requesting a review from @adekbadek because it uses a lot of his code on a different backend strategy to produce a similar result.

@leogermani
Copy link
Contributor

I've tested everything just from a functional point of view, following the instructions, and everything worked just fine.

I also tested making a donation before registering and that did not sync (not sure it was expected to)

@miguelpeixe
Copy link
Member Author

I also tested making a donation before registering and that did not sync (not sure it was expected to)

It will bail if a contact (registered user) is not available, but if a reader is created during (after) the donation is made we might need to tweak it on the WC integration side so that it becomes available at the hook.

Copy link
Member

@adekbadek adekbadek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since @leogermani did functional testing, I've only looked at the code. The changes to class-woocommerce-connection.php look fine. Left one note about argument order – after this is fixed we're good to merge.

includes/oauth/class-mailchimp-api.php Outdated Show resolved Hide resolved
includes/oauth/class-mailchimp-api.php Outdated Show resolved Hide resolved
@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Jan 25, 2023
@adekbadek
Copy link
Member

NP_Product Name is removed. This value will change with every different purchase, it's not clear to me the purpose of treating it as a singular contact data. Perhaps we need a better strategy for this?

This field (and a few others) are based on the assumption that a reader would buy a single product, which aligns with a membership-driven model. Newspack supports more models, but this specific integration was requested by a membership-focused third party.

@miguelpeixe
Copy link
Member Author

This field (and a few others) are based on the assumption that a reader would buy a single product, which aligns with a membership-driven model.

In the interest of feature parity, 89e9566 implements the NP_Product Name support through the donation_subscription_new action, instead of every donation. In this case, every new recurring donation will trigger an update in MC's contact. WDYT?

It can be extended to also handle donation_subscription_cancelled, but I wonder about its use.

@miguelpeixe miguelpeixe requested a review from adekbadek January 25, 2023 20:44
@miguelpeixe
Copy link
Member Author

I also tested making a donation before registering and that did not sync (not sure it was expected to)

@leogermani I tried on both Stripe and Newspack platforms and an anonymous donation (fresh session) did sync without issues. Which platform were you using, can you provide more details?

@adekbadek
Copy link
Member

NP_Product Name support through the donation_subscription_new action

Sounds good!

@miguelpeixe miguelpeixe merged commit 08060c6 into master Jan 26, 2023
@miguelpeixe miguelpeixe deleted the feat/data-events-mailchimp branch January 26, 2023 21:00
matticbot pushed a commit that referenced this pull request Feb 17, 2023
# [1.103.0-alpha.2](v1.103.0-alpha.1...v1.103.0-alpha.2) (2023-02-17)

### Bug Fixes

* **ads-wizard:** cancelled state of unit displayed on the list ([#2272](#2272)) ([e10b592](e10b592))
* **ads:** remove fixed height setting ([#2255](#2255)) ([0031b89](0031b89))
* change default auth strategy to "link" ([#2261](#2261)) ([c4b2e2c](c4b2e2c))
* update package.json to resolve a merge conflict with master ([f2408a3](f2408a3))
* **webhooks:** check if endpoint exists ([#2276](#2276)) ([5a95e2c](5a95e2c))

### Features

* bootstrap GA4 connector ([#2241](#2241)) ([f7582a4](f7582a4))
* **data-events:** mailchimp connector ([#2233](#2233)) ([08060c6](08060c6))
* **data-events:** standardize the use of "user_id" and "email" ([#2263](#2263)) ([d6b6903](d6b6903))
* **donations:** add payment metadata and update renewal description ([#2254](#2254)) ([b039304](b039304))
* **my-account:** display stripe billing link regardless of RR platform ([df540fe](df540fe))
* **perfmatters:** defaults adjustments, remove feature flag ([#2271](#2271)) ([cf5ad51](cf5ad51))
* **performance:** minify all inline CSS ([#2239](#2239)) ([fbb415f](fbb415f))
* **ras:** enable custom contact metadata prefixes ([#2249](#2249)) ([e9843e4](e9843e4))
* require all woo plugins for RAS ([#2260](#2260)) ([5f6a818](5f6a818))
* **stripe:** create native WC Subscriptions (if feature flag is set) ([#2251](#2251)) ([009a8a5](009a8a5))
* **webhooks:** support label for endpoints ([#2262](#2262)) ([39da7be](39da7be))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.103.0-alpha.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 17, 2023
# [1.104.0-alpha.1](v1.103.0...v1.104.0-alpha.1) (2023-02-17)

### Bug Fixes

* **ads-wizard:** cancelled state of unit displayed on the list ([#2272](#2272)) ([e10b592](e10b592))
* **ads:** remove fixed height setting ([#2255](#2255)) ([0031b89](0031b89))
* change default auth strategy to "link" ([#2261](#2261)) ([c4b2e2c](c4b2e2c))
* **webhooks:** check if endpoint exists ([#2276](#2276)) ([5a95e2c](5a95e2c))

### Features

* bootstrap GA4 connector ([#2241](#2241)) ([f7582a4](f7582a4))
* **data-events:** mailchimp connector ([#2233](#2233)) ([08060c6](08060c6))
* **data-events:** standardize the use of "user_id" and "email" ([#2263](#2263)) ([d6b6903](d6b6903))
* **donations:** add payment metadata and update renewal description ([#2254](#2254)) ([b039304](b039304))
* **my-account:** display stripe billing link regardless of RR platform ([df540fe](df540fe))
* **perfmatters:** defaults adjustments, remove feature flag ([#2271](#2271)) ([cf5ad51](cf5ad51))
* **performance:** minify all inline CSS ([#2239](#2239)) ([fbb415f](fbb415f))
* **ras:** enable custom contact metadata prefixes ([#2249](#2249)) ([e9843e4](e9843e4))
* require all woo plugins for RAS ([#2260](#2260)) ([5f6a818](5f6a818))
* **stripe:** create native WC Subscriptions (if feature flag is set) ([#2251](#2251)) ([009a8a5](009a8a5))
* **webhooks:** support label for endpoints ([#2262](#2262)) ([39da7be](39da7be))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.104.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 20, 2023
# [1.105.0-alpha.1](v1.104.0...v1.105.0-alpha.1) (2023-02-20)

### Bug Fixes

* **ads-wizard:** cancelled state of unit displayed on the list ([#2272](#2272)) ([e10b592](e10b592))
* **ads:** remove fixed height setting ([#2255](#2255)) ([0031b89](0031b89))
* change default auth strategy to "link" ([#2261](#2261)) ([c4b2e2c](c4b2e2c))
* **webhooks:** check if endpoint exists ([#2276](#2276)) ([5a95e2c](5a95e2c))

### Features

* bootstrap GA4 connector ([#2241](#2241)) ([f7582a4](f7582a4))
* **data-events:** mailchimp connector ([#2233](#2233)) ([08060c6](08060c6))
* **data-events:** standardize the use of "user_id" and "email" ([#2263](#2263)) ([d6b6903](d6b6903))
* **donations:** add payment metadata and update renewal description ([#2254](#2254)) ([b039304](b039304))
* **my-account:** display stripe billing link regardless of RR platform ([df540fe](df540fe))
* **perfmatters:** defaults adjustments, remove feature flag ([#2271](#2271)) ([cf5ad51](cf5ad51))
* **performance:** minify all inline CSS ([#2239](#2239)) ([fbb415f](fbb415f))
* **ras:** enable custom contact metadata prefixes ([#2249](#2249)) ([e9843e4](e9843e4))
* require all woo plugins for RAS ([#2260](#2260)) ([5f6a818](5f6a818))
* **stripe:** create native WC Subscriptions (if feature flag is set) ([#2251](#2251)) ([009a8a5](009a8a5))
* **webhooks:** support label for endpoints ([#2262](#2262)) ([39da7be](39da7be))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.105.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.105.0-hotfix-hpb-amp-optimisations.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 28, 2023
# [1.105.0](v1.104.1...v1.105.0) (2023-02-28)

### Bug Fixes

* **ads-wizard:** cancelled state of unit displayed on the list ([#2272](#2272)) ([e10b592](e10b592))
* **ads:** remove fixed height setting ([#2255](#2255)) ([0031b89](0031b89))
* change default auth strategy to "link" ([#2261](#2261)) ([c4b2e2c](c4b2e2c))
* **webhooks:** check if endpoint exists ([#2276](#2276)) ([5a95e2c](5a95e2c))

### Features

* bootstrap GA4 connector ([#2241](#2241)) ([f7582a4](f7582a4))
* **data-events:** mailchimp connector ([#2233](#2233)) ([08060c6](08060c6))
* **data-events:** standardize the use of "user_id" and "email" ([#2263](#2263)) ([d6b6903](d6b6903))
* **donations:** add payment metadata and update renewal description ([#2254](#2254)) ([b039304](b039304))
* **my-account:** display stripe billing link regardless of RR platform ([df540fe](df540fe))
* **perfmatters:** defaults adjustments, remove feature flag ([#2271](#2271)) ([cf5ad51](cf5ad51))
* **performance:** minify all inline CSS ([#2239](#2239)) ([fbb415f](fbb415f))
* **ras:** enable custom contact metadata prefixes ([#2249](#2249)) ([e9843e4](e9843e4))
* require all woo plugins for RAS ([#2260](#2260)) ([5f6a818](5f6a818))
* **stripe:** create native WC Subscriptions (if feature flag is set) ([#2251](#2251)) ([009a8a5](009a8a5))
* **webhooks:** support label for endpoints ([#2262](#2262)) ([39da7be](39da7be))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.105.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants