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

[WooCommerce Analytics] Add clickhouse param to record events in w.gif #41476

Open
wants to merge 6 commits into
base: release/woocommerce-analytics-0.4.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
puntope marked this conversation as resolved.
Show resolved Hide resolved
Type: changed

Add clickhouse param to record events
16 changes: 9 additions & 7 deletions projects/packages/woocommerce-analytics/src/class-my-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public function track_tabs() {
if ( isset( $core_endpoints['view-order'] ) && $core_endpoints['view-order'] === $key && is_numeric( $value ) ) {
$initiator = get_query_var( '_wca_initiator' );
if ( 'number' === $initiator ) {
$this->record_event( 'woocommerceanalytics_my_account_order_number_click' );
$this->record_event( 'woocommerceanalytics_my_account_order_number_click', array(), null, false );
continue;
}
if ( 'action' === $initiator ) {
$this->record_event( 'woocommerceanalytics_my_account_order_action_click', array( 'action' => 'view' ) );
$this->record_event( 'woocommerceanalytics_my_account_order_action_click', array( 'action' => 'view' ), null, false );
continue;
}
}
Expand All @@ -81,12 +81,12 @@ public function track_tabs() {
continue;
}

$this->record_event( 'woocommerceanalytics_my_account_address_click', array( 'address' => $value ) );
$this->record_event( 'woocommerceanalytics_my_account_address_click', array( 'address' => $value ), null, false );
continue;
}

if ( isset( $core_endpoints['add-payment-method'] ) && $core_endpoints['add-payment-method'] === $key ) {
$this->record_event( 'woocommerceanalytics_my_account_payment_add' );
$this->record_event( 'woocommerceanalytics_my_account_payment_add', array(), null, false );
continue;
}

Expand Down Expand Up @@ -121,7 +121,7 @@ public function track_tabs() {
$key = array_search( $key, $core_endpoints, true );
}

$this->record_event( 'woocommerceanalytics_my_account_page_view', array( 'tab' => $key ) );
$this->record_event( 'woocommerceanalytics_my_account_page_view', array( 'tab' => $key ), null, false );
}
}
}
Expand Down Expand Up @@ -178,7 +178,7 @@ public function track_order_cancel_event() {
*/
public function track_order_pay_event() {
if ( isset( $_GET['_wca_initiator'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized,WordPress.Security.NonceVerification.Recommended
$this->record_event( 'woocommerceanalytics_my_account_order_action_click', array( 'action' => 'pay' ) );
$this->record_event( 'woocommerceanalytics_my_account_order_action_click', array( 'action' => 'pay' ), null, false );
}
}

Expand Down Expand Up @@ -289,7 +289,9 @@ public function trigger_queued_events() {
foreach ( $events as $event ) {
$this->record_event(
$event['event_name'],
$event['event_props']
$event['event_props'],
null,
false
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,15 @@ private function render_properties_as_js( $properties ) {
/**
* Record an event with optional product and custom properties.
*
* @param string $event_name The name of the event to record.
* @param array $properties Optional array of (key => value) event properties.
* @param integer $product_id The id of the product relating to the event.
* @param string $event_name The name of the event to record.
* @param array $properties Optional array of (key => value) event properties.
* @param integer|null $product_id The id of the product relating to the event.
* @param boolean $clickhouse Send event to clickhouse.
*
* @return string|void
*/
public function record_event( $event_name, $properties = array(), $product_id = null ) {
$js = $this->process_event_properties( $event_name, $properties, $product_id );
public function record_event( $event_name, $properties = array(), $product_id = null, $clickhouse = true ) {
$js = $this->process_event_properties( $event_name, $properties, $product_id, $clickhouse );
wc_enqueue_js( "_wca.push({$js});" );
}

Expand Down Expand Up @@ -376,13 +377,14 @@ public function get_product_categories_concatenated( $product ) {
/**
* Compose event properties.
*
* @param string $event_name The name of the event to record.
* @param array $properties Optional array of (key => value) event properties.
* @param integer $product_id Optional id of the product relating to the event.
* @param string $event_name The name of the event to record.
* @param array $properties Optional array of (key => value) event properties.
* @param integer|null $product_id Optional id of the product relating to the event.
* @param boolean $clickhouse Send event to clickhouse.
*
* @return string|void
*/
public function process_event_properties( $event_name, $properties = array(), $product_id = null ) {
public function process_event_properties( $event_name, $properties = array(), $product_id = null, $clickhouse = true ) {

// Only set product details if we have a product id.
if ( $product_id ) {
Expand Down Expand Up @@ -412,6 +414,10 @@ public function process_event_properties( $event_name, $properties = array(), $p

$js = "{'_en': '" . esc_js( $event_name ) . "'";

if ( $clickhouse ) {
$js .= ", '_ch':'1'";
}

if ( isset( $product_details ) ) {
$all_props = array_merge( $all_props, $product_details );
}
Expand Down
Loading