Skip to content

Commit

Permalink
move wpcom tracking to a different file
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian authored and jeherve committed Oct 11, 2019
1 parent 6a6473a commit 767d527
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
6 changes: 5 additions & 1 deletion modules/contact-form/grunion-contact-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ function grunion_contact_form_require_endpoint() {
require_once GRUNION_PLUGIN_DIR . 'class-grunion-contact-form-endpoint.php';
}

require_once GRUNION_PLUGIN_DIR . 'tracks-events.php';
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
require_once GRUNION_PLUGIN_DIR . 'tracks-events-wpcom.php';
} else {
require_once GRUNION_PLUGIN_DIR . 'tracks-events.php';
}

/**
* Sets up various actions, filters, post types, post statuses, shortcodes.
Expand Down
33 changes: 33 additions & 0 deletions modules/contact-form/tracks-events-wpcom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Jetpack_Contact_Form: Add tracking for submitting contact form blocks
*
* This file is specific to Jetpack's Tracks implementation
* @package Jetpack
* @since ?
*/

/**
* Function that sends a `jetpack_contact_form_block_message_sent` event to Tracks
*
* @param int $post_id - the post_id for the CPT that is created.
* @param array $all_values - fields from the default contact form.
* @param array $extra_values - extra fields added to from the contact form.
* @return null
*/
function jetpack_wpcom_tracks_record_grunion_pre_message_sent( $post_id, $all_values, $extra_values ) {
if ( isset( $extra_values['is_block'] ) && $extra_values['is_block'] ) {
require_lib( 'tracks/client' );
tracks_record_event(
wp_get_current_user(),
'jetpack_contact_form_block_message_sent',
array(
'entry_permalink' => esc_url( $all_values['entry_permalink'] ),
'feedback_id' => absint( $all_values['feedback_id'] ),
)
);
}
}

add_action( 'grunion_pre_message_sent', 'jetpack_wpcom_tracks_record_grunion_pre_message_sent', 12, 3 );
11 changes: 3 additions & 8 deletions modules/contact-form/tracks-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/**
* Jetpack_Contact_Form: Add tracking for submitting contact form blocks
*
* This file is specific to Jetpack's Tracks implementation
*
* @package Jetpack
* @since ?
*/
Expand All @@ -16,22 +18,15 @@
* @param array $all_values - fields from the default contact form.
* @param array $extra_values - extra fields added to from the contact form.
* @return null
* @return null|void
*/
function jetpack_tracks_record_grunion_pre_message_sent( $post_id, $all_values, $extra_values ) {
$status = new Automattic\Jetpack\Status();

if ( $status->is_development_mode() ) {
return false;
}

if ( isset( $extra_values['is_block'] ) && $extra_values['is_block'] ) {
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
require_lib( 'tracks/client' );
tracks_record_event( $current_user, 'simple_payments_button_' . $event_action, $event_properties );
return;
}

$tracking = new Automattic\Jetpack\Tracking();
$tracking->tracks_record_event(
wp_get_current_user(),
Expand Down

0 comments on commit 767d527

Please sign in to comment.