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: campaigns listeners for the data events api #2291

Merged
merged 4 commits into from
Feb 22, 2023

Conversation

leogermani
Copy link
Contributor

@leogermani leogermani commented Feb 19, 2023

All Submissions:

Changes proposed in this Pull Request:

This PR adds new events to the Data Events API to track interaction with Campaigns on the back-end.

In order to track the "lifecycle" of a campaign, we trigger a series of the same event, called "campaign_interaction", with action values for each state. It can be

  • rendered: for when the campaign is rendered in the page (not necessarily seen by the user)
  • form_submission: for when there's a submission to a form inside a popup. We are adding a newspack_popup_id to forms inside a popup to be able to identify it. We'll need to handle all forms we need to to track in this way. This PR does it for the Registration and Newsletter Subscription blocks.
  • form_submission_success: for when the form submission returns success
  • form_submission_failure: for when the form submission fails

How to test the changes in this Pull Request:

  1. Checkout this PR. Checkout feat: add popups ids to forms in prompts newspack-popups#1057 in the popups plugin, and feat: add support to campaigns data event listeners newspack-newsletters#1087 in the newsletters plugin
  2. Create a prompt that displays the Registration block and make it appear on your site
  3. Add this snippet to your site:
Data_Events::register_handler( 'debug_popups_events', 'campaign_interaction' );

function debug_popups_events( $timestamp, $data, $user_id ) {
	error_log( print_r( $data, true ) );
}
  1. Watch the error log
  2. Load a page where the prompt will be displayed
  3. Register through the prompt
  4. Confirm registration works
  5. Check your log after all the handlers are executed (you might need to refresh the page a couple of times, or you can go to Tools > Action Scheduler and manually run the campaign_interaction events)
  6. In your log, you should be able to find this sequence:
[21-Feb-2023 14:05:11 UTC] [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::handle]: Executing action handlers for "campaign_interaction".
[21-Feb-2023 14:05:11 UTC] Array
(
    [title] => Registration Overlay
    [frequency] => always
    [placement] => center
    [has_registration_block] => 1
    [has_donation_block] => 
    [has_newsletter_block] =>
    [action] => rendered
)

[21-Feb-2023 14:05:57 UTC] [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::handle]: Executing action handlers for "campaign_interaction".
[21-Feb-2023 14:05:57 UTC] Array
(
    [title] => Registration Overlay
    [frequency] => always
    [placement] => center
    [has_registration_block] => 1
    [has_donation_block] => 
    [has_newsletter_block] =>
    [action] => form_submission
)

[21-Feb-2023 14:05:57 UTC] [NEWSPACK-DATA-EVENTS][Newspack\Data_Events::handle]: Executing action handlers for "campaign_interaction".
[21-Feb-2023 14:05:57 UTC] Array
(
    [title] => Registration Overlay
    [frequency] => always
    [placement] => center
    [has_registration_block] => 1 
    [has_donation_block] => 
    [has_newsletter_block] => 
    [action] => form_submission_success
)
  1. Logout and visit the site again
  2. Try to register again with the same email
  3. Check your logs and see that you have the same events fired, but now the last one is form_submission_failure instead of success.
  4. Repeat steps 5 to 9 but now with a Newsletters Subscription block.
  5. On the logs, you should see has_newsletter_block as 1
  6. Trying to subscribe to the same newsletter again with the same email won't trigger an failure - we don't consider this an error.

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?

@leogermani leogermani self-assigned this Feb 21, 2023
@leogermani leogermani added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 21, 2023
@leogermani leogermani marked this pull request as ready for review February 21, 2023 14:38
@leogermani leogermani requested a review from a team as a code owner February 21, 2023 14:38
Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

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

Beautiful! The sequence of reporting via action hooks, form fields, and Data Events is very easy to follow.

@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 Feb 21, 2023
@leogermani leogermani merged commit ab407d4 into master Feb 22, 2023
@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 📦🚀

@miguelpeixe miguelpeixe deleted the add/campaigns-data-listeners branch February 27, 2023 19:14
matticbot pushed a commit that referenced this pull request Mar 3, 2023
# [1.106.0-alpha.1](v1.105.0...v1.106.0-alpha.1) (2023-03-03)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

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

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Mar 14, 2023
# [1.106.0](v1.105.1...v1.106.0) (2023-03-14)

### Bug Fixes

* **ads:** gam api availability according to error type ([#2289](#2289)) ([024fe08](024fe08))
* show handoff to finish Newspack setup only if setup is incomplete ([#2343](#2343)) ([1173b5b](1173b5b))

### Features

* add a Add new button to subscription lists ([#2314](#2314)) ([9543ad2](9543ad2))
* add ga4 user registered handler ([#2281](#2281)) ([5eb2336](5eb2336))
* add pid to Logger ([#2290](#2290)) ([fd3011c](fd3011c))
* Add popup info to donations ([#2300](#2300)) ([7ea800b](7ea800b))
* allow external links in dashboard via a filter ([#2279](#2279)) ([3943b1a](3943b1a))
* campaigns listeners for the data events api ([#2291](#2291)) ([ab407d4](ab407d4))
* disable save button for unchanged settings ([#2259](#2259)) ([e06d72f](e06d72f)), closes [#1531](#1531)
* **donate-block:** support modal checkout ([#2256](#2256)) ([34226dd](34226dd))
* Normalize donation events ([#2299](#2299)) ([2624d53](2624d53))
* **perfmatters:** improve config ([267306e](267306e))
* prevent homepage from being unpublished ([#2307](#2307)) ([a151d53](a151d53))
* Remove the campaign rendered event ([#2301](#2301)) ([23caa1d](23caa1d))
* Stripe Subscriptions to WC subscriptions migrator ([#2298](#2298)) ([6904356](6904356)), closes [#2251](#2251)
* **wc:** force allowing subscription switching ([#2305](#2305)) ([c13e741](c13e741))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.106.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.

3 participants