@automattic/newspack-blocks 4.12.3 → 4.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/carousel/view.asset.php +1 -1
- package/dist/carousel/view.js +3 -3
- package/dist/editor.asset.php +1 -1
- package/dist/editor.js +3 -3
- package/dist/modal.asset.php +1 -1
- package/dist/modal.js +1 -1
- package/dist/modalCheckout-rtl.css +1 -1
- package/dist/modalCheckout.asset.php +1 -1
- package/dist/modalCheckout.css +1 -1
- package/dist/modalCheckout.js +1 -1
- package/includes/class-modal-checkout.php +32 -106
- package/includes/class-newspack-blocks.php +4 -0
- package/includes/modal-checkout/class-checkout-data.php +287 -0
- package/includes/tracking/class-data-events.php +5 -140
- package/newspack-blocks.php +3 -2
- package/package.json +5 -5
- package/src/blocks/checkout-button/view.php +8 -42
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php +2 -2
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php +4 -28
- package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-tiers-based.php +5 -17
- package/src/modal-checkout/analytics/ga4/checkout-attempt.js +3 -2
- package/src/modal-checkout/analytics/ga4/checkout-success.js +3 -3
- package/src/modal-checkout/analytics/ga4/dismissed.js +3 -3
- package/src/modal-checkout/analytics/ga4/loaded.js +3 -3
- package/src/modal-checkout/analytics/ga4/pagination.js +3 -2
- package/src/modal-checkout/analytics/ga4/utils/index.js +31 -17
- package/src/modal-checkout/analytics/index.js +1 -1
- package/src/modal-checkout/checkout.scss +2 -1
- package/src/modal-checkout/index.js +1 -1
- package/src/modal-checkout/modal.js +232 -253
- package/src/modal-checkout/templates/thankyou.php +3 -6
- package/src/modal-checkout/utils.js +126 -0
- package/vendor/autoload.php +1 -1
- package/vendor/composer/autoload_real.php +4 -4
- package/vendor/composer/autoload_static.php +2 -2
- package/vendor/composer/installed.php +2 -2
package/newspack-blocks.php
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Author URI: https://newspack.com/
|
|
8
8
|
* Text Domain: newspack-blocks
|
|
9
9
|
* Domain Path: /languages
|
|
10
|
-
* Version: 4.
|
|
10
|
+
* Version: 4.13.0
|
|
11
11
|
*
|
|
12
12
|
* @package Newspack_Blocks
|
|
13
13
|
*/
|
|
@@ -15,12 +15,13 @@
|
|
|
15
15
|
define( 'NEWSPACK_BLOCKS__PLUGIN_FILE', __FILE__ );
|
|
16
16
|
define( 'NEWSPACK_BLOCKS__BLOCKS_DIRECTORY', 'dist/' );
|
|
17
17
|
define( 'NEWSPACK_BLOCKS__PLUGIN_DIR', plugin_dir_path( NEWSPACK_BLOCKS__PLUGIN_FILE ) );
|
|
18
|
-
define( 'NEWSPACK_BLOCKS__VERSION', '4.
|
|
18
|
+
define( 'NEWSPACK_BLOCKS__VERSION', '4.13.0' );
|
|
19
19
|
|
|
20
20
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks.php';
|
|
21
21
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-api.php';
|
|
22
22
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-patterns.php';
|
|
23
23
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-newspack-blocks-caching.php';
|
|
24
|
+
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/modal-checkout/class-checkout-data.php';
|
|
24
25
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/class-modal-checkout.php';
|
|
25
26
|
|
|
26
27
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'includes/plugins/class-the-events-calendar.php';
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automattic/newspack-blocks",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"author": "Automattic",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@rushstack/eslint-patch": "^1.11.0",
|
|
7
7
|
"@testing-library/dom": "^10.4.0",
|
|
8
8
|
"@testing-library/user-event": "^14.6.1",
|
|
9
|
-
"@types/lodash": "^4.17.
|
|
10
|
-
"@wordpress/browserslist-config": "^6.
|
|
9
|
+
"@types/lodash": "^4.17.17",
|
|
10
|
+
"@wordpress/browserslist-config": "^6.24.0",
|
|
11
11
|
"eslint": "^8.57.0",
|
|
12
12
|
"fetch-mock-jest": "^1.5.1",
|
|
13
13
|
"html-entities": "^2.6.0",
|
|
14
14
|
"identity-obj-proxy": "^3.0.0",
|
|
15
|
-
"lint-staged": "^
|
|
15
|
+
"lint-staged": "^16.1.0",
|
|
16
16
|
"newspack-components": "^3.1.0",
|
|
17
17
|
"newspack-scripts": "^5.5.2",
|
|
18
18
|
"postcss-scss": "^4.0.9"
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"redux": "^5.0.0",
|
|
24
24
|
"redux-saga": "^1.3.0",
|
|
25
25
|
"regenerator-runtime": "^0.14.1",
|
|
26
|
-
"swiper": "11.2.
|
|
26
|
+
"swiper": "11.2.8"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
29
|
"cm": "newspack-scripts commit",
|
|
@@ -9,6 +9,7 @@ namespace Newspack_Blocks\Checkout_Button;
|
|
|
9
9
|
|
|
10
10
|
use Newspack_Blocks;
|
|
11
11
|
use Newspack_Blocks\Modal_Checkout;
|
|
12
|
+
use Newspack_Blocks\Modal_Checkout\Checkout_Data;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Register the block.
|
|
@@ -124,15 +125,6 @@ function render_callback( $attributes ) {
|
|
|
124
125
|
return '';
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
$frequency = '';
|
|
128
|
-
if ( class_exists( '\WC_Subscriptions_Product' ) && \WC_Subscriptions_Product::is_subscription( $product ) ) {
|
|
129
|
-
$frequency = \WC_Subscriptions_Product::get_period( $product );
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Get the product type.
|
|
133
|
-
$product_type = \Newspack_Blocks\Tracking\Data_Events::get_product_type( $product_id );
|
|
134
|
-
|
|
135
|
-
$name = $product->get_name();
|
|
136
128
|
$price = $product->get_price();
|
|
137
129
|
$min_price = '';
|
|
138
130
|
if ( ! empty( $attributes['price'] ) ) {
|
|
@@ -144,37 +136,8 @@ function render_callback( $attributes ) {
|
|
|
144
136
|
$min_price = \WC_Name_Your_Price_Helpers::get_minimum_price( $product_id );
|
|
145
137
|
}
|
|
146
138
|
|
|
147
|
-
$is_variable
|
|
148
|
-
$variation_id
|
|
149
|
-
$product_price_summary = Modal_Checkout::get_summary_card_price_string( $name, $price, $frequency );
|
|
150
|
-
|
|
151
|
-
// If this is a variable product without a variation picked, we're not sure about the frequency.
|
|
152
|
-
$recurrence = ! empty( $frequency ) ? $frequency : 'once';
|
|
153
|
-
if ( $is_variable && empty( $variation_id ) ) {
|
|
154
|
-
$recurrence = '';
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
$product_data = [
|
|
158
|
-
'action_type' => 'checkout_button',
|
|
159
|
-
'currency' => function_exists( 'get_woocommerce_currency' ) ? \get_woocommerce_currency() : 'USD',
|
|
160
|
-
'is_variable' => $is_variable,
|
|
161
|
-
'product_id' => $product_id,
|
|
162
|
-
'product_type' => $product_type,
|
|
163
|
-
'recurrence' => $recurrence,
|
|
164
|
-
'referrer' => substr( \get_permalink(), strlen( home_url() ) ),
|
|
165
|
-
];
|
|
166
|
-
|
|
167
|
-
if ( ! $is_variable || $variation_id ) {
|
|
168
|
-
$product_data['price'] = $price;
|
|
169
|
-
$product_data['product_price_summary'] = $product_price_summary;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if ( $variation_id ) {
|
|
173
|
-
// We're doing a lot of shuffling around to get the "right" product ID, variation ID, and product type for GA4.
|
|
174
|
-
$product_data['product_id'] = $product->get_parent_id(); // Reset Product ID as parent ID.
|
|
175
|
-
$product_data['product_type'] = \Newspack_Blocks\Tracking\Data_Events::get_product_type( $product->get_parent_id() );
|
|
176
|
-
$product_data['variation_id'] = $product_id; // Overwrite us setting the product ID as the variation ID.
|
|
177
|
-
}
|
|
139
|
+
$is_variable = $attributes['is_variable'];
|
|
140
|
+
$variation_id = $attributes['variation'];
|
|
178
141
|
|
|
179
142
|
// Check if the button should be output: it needs a price, or needs to be a product with variations to pick.
|
|
180
143
|
if ( $min_price && ! $price ) {
|
|
@@ -184,9 +147,12 @@ function render_callback( $attributes ) {
|
|
|
184
147
|
return '';
|
|
185
148
|
}
|
|
186
149
|
|
|
150
|
+
$checkout_data = Checkout_Data::get_checkout_data( $product );
|
|
151
|
+
$checkout_data['is_variable'] = $is_variable;
|
|
152
|
+
|
|
187
153
|
$form = sprintf(
|
|
188
|
-
'<form data-
|
|
189
|
-
esc_attr( wp_json_encode( $
|
|
154
|
+
'<form data-checkout="%1$s">%2$s %3$s</form>',
|
|
155
|
+
esc_attr( wp_json_encode( $checkout_data ) ),
|
|
190
156
|
$button,
|
|
191
157
|
$hidden_fields
|
|
192
158
|
);
|
|
@@ -40,7 +40,7 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
40
40
|
*
|
|
41
41
|
* @param array $attributes Block attributes.
|
|
42
42
|
*/
|
|
43
|
-
public static function get_configuration( $attributes ) {
|
|
43
|
+
public static function get_configuration( $attributes = [] ) {
|
|
44
44
|
$attributes_hash = md5( wp_json_encode( $attributes ) );
|
|
45
45
|
if ( isset( self::$configurations_cache[ $attributes_hash ] ) ) {
|
|
46
46
|
return self::$configurations_cache[ $attributes_hash ];
|
|
@@ -148,7 +148,7 @@ abstract class Newspack_Blocks_Donate_Renderer_Base {
|
|
|
148
148
|
if ( isset( $configuration['minimumDonation'] ) ) {
|
|
149
149
|
foreach ( $configuration['amounts'] as $frequency => $amounts ) {
|
|
150
150
|
foreach ( $amounts as $index => $amount ) {
|
|
151
|
-
$configuration['amounts'][ $frequency ][ $index ] = max( $configuration['minimumDonation'], $amount );
|
|
151
|
+
$configuration['amounts'][ $frequency ][ $index ] = max( (float) $configuration['minimumDonation'], $amount );
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}
|
package/src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-frequency-based.php
CHANGED
|
@@ -9,7 +9,7 @@ defined( 'ABSPATH' ) || exit;
|
|
|
9
9
|
|
|
10
10
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php';
|
|
11
11
|
|
|
12
|
-
use Newspack_Blocks\Modal_Checkout;
|
|
12
|
+
use Newspack_Blocks\Modal_Checkout\Checkout_Data;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Renders the frequency-based Donate block.
|
|
@@ -171,25 +171,13 @@ class Newspack_Blocks_Donate_Renderer_Frequency_Based extends Newspack_Blocks_Do
|
|
|
171
171
|
<div class='wp-block-newspack-blocks-donate__frequencies frequencies'>
|
|
172
172
|
<?php echo self::render_form_header( $configuration, $uid ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
173
173
|
<?php foreach ( $configuration['frequencies'] as $frequency_slug => $frequency_name ) : ?>
|
|
174
|
-
<?php
|
|
175
|
-
$amount = $configuration['amounts'][ $frequency_slug ][3];
|
|
176
|
-
$product_price_summary = Modal_Checkout::get_summary_card_price_string(
|
|
177
|
-
__( 'Donate', 'newspack-blocks' ),
|
|
178
|
-
'',
|
|
179
|
-
$frequency_slug
|
|
180
|
-
);
|
|
181
|
-
$product_data = wp_json_encode(
|
|
182
|
-
[
|
|
183
|
-
'donation_price_summary_' . $frequency_slug => $product_price_summary,
|
|
184
|
-
]
|
|
185
|
-
);
|
|
186
|
-
?>
|
|
174
|
+
<?php $amount = $configuration['amounts'][ $frequency_slug ][3]; ?>
|
|
187
175
|
<div
|
|
188
176
|
class="wp-block-newspack-blocks-donate__frequency donation-frequency__<?php echo esc_attr( $frequency_slug ); ?> frequency"
|
|
189
177
|
id='tab-panel-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>'
|
|
190
178
|
role='tabpanel'
|
|
191
179
|
aria-labelledby='tab-newspack-donate-<?php echo esc_attr( $frequency_slug . '-' . $uid ); ?>'
|
|
192
|
-
data-
|
|
180
|
+
data-checkout='<?php echo esc_attr( wp_json_encode( Checkout_Data::get_donation_checkout_data( $frequency_slug, $amount ) ) ); ?>'
|
|
193
181
|
<?php ( $frequency_slug === $configuration['defaultFrequency'] ? 'tabindex="0"' : '' ); ?>
|
|
194
182
|
>
|
|
195
183
|
<?php echo self::render_frequency_selection( $frequency_slug, $frequency_name, $uid, $configuration ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
|
|
@@ -266,18 +254,6 @@ class Newspack_Blocks_Donate_Renderer_Frequency_Based extends Newspack_Blocks_Do
|
|
|
266
254
|
<div class='wp-block-newspack-blocks-donate__tiers tiers'>
|
|
267
255
|
<?php foreach ( $suggested_amounts[ $frequency_slug ] as $index => $amount ) : ?>
|
|
268
256
|
<?php
|
|
269
|
-
$product_price_summary = Modal_Checkout::get_summary_card_price_string(
|
|
270
|
-
__( 'Donate', 'newspack-blocks' ),
|
|
271
|
-
// Don't show the amount for the "other" tier.
|
|
272
|
-
3 === $index ? '' : $amount,
|
|
273
|
-
$frequency_slug
|
|
274
|
-
);
|
|
275
|
-
$product_data = wp_json_encode(
|
|
276
|
-
[
|
|
277
|
-
'donation_price_summary_' . $frequency_slug => $product_price_summary,
|
|
278
|
-
]
|
|
279
|
-
);
|
|
280
|
-
|
|
281
257
|
$decimals = intval( $amount ) == floatval( $amount ) ? 0 : 2;
|
|
282
258
|
$format_options = [ 'decimals' => $decimals ];
|
|
283
259
|
$formatted_amount = function_exists( 'wc_price' ) ?
|
|
@@ -286,7 +262,7 @@ class Newspack_Blocks_Donate_Renderer_Frequency_Based extends Newspack_Blocks_Do
|
|
|
286
262
|
?>
|
|
287
263
|
<div
|
|
288
264
|
class='wp-block-newspack-blocks-donate__tier donation-tier__<?php echo esc_attr( $frequency_slug ); ?>'
|
|
289
|
-
data-
|
|
265
|
+
data-checkout='<?php echo esc_attr( wp_json_encode( Checkout_Data::get_donation_checkout_data( $frequency_slug, $amount ) ) ); ?>'
|
|
290
266
|
>
|
|
291
267
|
<?php if ( 3 === $index ) : // The "other" tier. ?>
|
|
292
268
|
<input
|
|
@@ -9,7 +9,7 @@ defined( 'ABSPATH' ) || exit;
|
|
|
9
9
|
|
|
10
10
|
require_once NEWSPACK_BLOCKS__PLUGIN_DIR . 'src/blocks/donate/frontend/class-newspack-blocks-donate-renderer-base.php';
|
|
11
11
|
|
|
12
|
-
use Newspack_Blocks\Modal_Checkout;
|
|
12
|
+
use Newspack_Blocks\Modal_Checkout\Checkout_Data;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Renders the tiers-based Donate block.
|
|
@@ -57,28 +57,16 @@ class Newspack_Blocks_Donate_Renderer_Tiers_Based extends Newspack_Blocks_Donate
|
|
|
57
57
|
<div class="wpbnbd__tiers__amount">
|
|
58
58
|
<span>
|
|
59
59
|
<?php foreach ( $configuration['frequencies'] as $frequency_slug => $frequency_name ) : ?>
|
|
60
|
-
<?php
|
|
61
|
-
$amount = $configuration['amounts'][ $frequency_slug ][ $index ];
|
|
62
|
-
$product_price_summary = Modal_Checkout::get_summary_card_price_string(
|
|
63
|
-
__( 'Donate', 'newspack-blocks' ),
|
|
64
|
-
$amount,
|
|
65
|
-
$frequency_slug
|
|
66
|
-
);
|
|
67
|
-
$product_data = wp_json_encode(
|
|
68
|
-
[
|
|
69
|
-
'donation_price_summary_' . $frequency_slug => $product_price_summary,
|
|
70
|
-
]
|
|
71
|
-
);
|
|
72
|
-
?>
|
|
60
|
+
<?php $amount = $configuration['amounts'][ $frequency_slug ][ $index ]; ?>
|
|
73
61
|
<span
|
|
74
62
|
style="<?php echo $frequency_slug === $selected_frequency ? '' : 'display:none;'; ?>"
|
|
75
63
|
class="donation-tier__<?php echo esc_attr( $frequency_slug ); ?>"
|
|
76
64
|
data-frequency-slug="<?php echo esc_attr( $frequency_slug ); ?>"
|
|
77
|
-
data-amount="<?php echo esc_attr( $
|
|
65
|
+
data-amount="<?php echo esc_attr( $amount ); ?>"
|
|
78
66
|
data-tier-index="<?php echo esc_attr( $index ); ?>"
|
|
79
|
-
data-
|
|
67
|
+
data-checkout="<?php echo esc_attr( wp_json_encode( Checkout_Data::get_donation_checkout_data( $frequency_slug, $amount ) ) ); ?>"
|
|
80
68
|
>
|
|
81
|
-
<?php echo wp_kses_post( Newspack_Blocks::get_formatted_amount( $
|
|
69
|
+
<?php echo wp_kses_post( Newspack_Blocks::get_formatted_amount( $amount, $frequency_slug ) ); ?>
|
|
82
70
|
</span>
|
|
83
71
|
<?php endforeach; ?>
|
|
84
72
|
</span>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getEventPayload,
|
|
1
|
+
import { getEventPayload, sendEvent } from './utils';
|
|
2
|
+
import { getCheckoutData } from '../../utils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Event fired when switching between steps of the multi-step checkout flow.
|
|
@@ -11,7 +12,7 @@ export const manageCheckoutAttempt = () => {
|
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
const params =
|
|
15
|
+
const params = getCheckoutData( 'modal-checkout-product-details' );
|
|
15
16
|
const payload = getEventPayload( 'form_submission', params );
|
|
16
17
|
sendEvent( payload );
|
|
17
18
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEventPayload,
|
|
2
|
-
|
|
1
|
+
import { getEventPayload, sendEvent } from './utils';
|
|
2
|
+
import { getCheckoutData } from '../../utils';
|
|
3
3
|
/**
|
|
4
4
|
* Event fired when switching between steps of the multi-step checkout flow.
|
|
5
5
|
*
|
|
@@ -11,7 +11,7 @@ export const manageCheckoutSuccess = () => {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const params =
|
|
14
|
+
const params = getCheckoutData( 'modal-checkout-product-details' );
|
|
15
15
|
const payload = getEventPayload( 'form_submission_success', params );
|
|
16
16
|
sendEvent( payload );
|
|
17
17
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEventPayload,
|
|
2
|
-
|
|
1
|
+
import { getEventPayload, sendEvent } from './utils';
|
|
2
|
+
import { getCheckoutData } from '../../utils';
|
|
3
3
|
/**
|
|
4
4
|
* Event fired when a checkout modal is dismissed (not when closed automatically due to a completed checkout).
|
|
5
5
|
*
|
|
@@ -10,7 +10,7 @@ export const manageDismissed = ( data ) => {
|
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
data = data ||
|
|
13
|
+
data = data || getCheckoutData( 'newspack_modal_checkout' );
|
|
14
14
|
|
|
15
15
|
const payload = getEventPayload( 'dismissed', data );
|
|
16
16
|
sendEvent( payload );
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { getEventPayload,
|
|
2
|
-
import { domReady } from '../../utils';
|
|
1
|
+
import { getEventPayload, sendEvent } from './utils';
|
|
2
|
+
import { domReady, getCheckoutData } from '../../utils';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Event fired when the modal checkout content is loaded.
|
|
@@ -9,7 +9,7 @@ export const manageLoaded = () => {
|
|
|
9
9
|
if ( 'function' !== typeof window.gtag ) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const params =
|
|
12
|
+
const params = getCheckoutData( 'modal-checkout-product-details' );
|
|
13
13
|
const payload = getEventPayload( 'loaded', params );
|
|
14
14
|
|
|
15
15
|
sendEvent( payload );
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { getEventPayload,
|
|
1
|
+
import { getEventPayload, sendEvent } from './utils';
|
|
2
|
+
import { getCheckoutData } from '../../utils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Event fired when switching between steps of the multi-step checkout flow.
|
|
@@ -22,7 +23,7 @@ export const managePagination = ( action = 'continue' ) => {
|
|
|
22
23
|
variation_id = '',
|
|
23
24
|
gate_post_id = '',
|
|
24
25
|
newspack_popup_id = '',
|
|
25
|
-
} =
|
|
26
|
+
} = getCheckoutData( 'modal-checkout-product-details' );
|
|
26
27
|
|
|
27
28
|
const params = {
|
|
28
29
|
action_type,
|
|
@@ -12,29 +12,43 @@ export const getEventPayload = ( action, extraParams = {} ) => {
|
|
|
12
12
|
return { ...extraParams, action };
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Checkout data keys that can be included in the event payload.
|
|
17
|
+
*
|
|
18
|
+
* @type {string[]}
|
|
19
|
+
*/
|
|
20
|
+
const eventKeys = [
|
|
21
|
+
'action',
|
|
22
|
+
'action_type',
|
|
23
|
+
'amount',
|
|
24
|
+
'currency',
|
|
25
|
+
'product_id',
|
|
26
|
+
'product_type',
|
|
27
|
+
'variation_id',
|
|
28
|
+
'price_summary',
|
|
29
|
+
'newspack_popup_id',
|
|
30
|
+
'gate_post_id',
|
|
31
|
+
'recurrence',
|
|
32
|
+
'referrer',
|
|
33
|
+
];
|
|
34
|
+
|
|
15
35
|
/**
|
|
16
36
|
* Send an event to GA4.
|
|
17
37
|
*
|
|
18
38
|
* @param {Object} payload Event payload.
|
|
19
39
|
* @param {string} eventName Name of the event. Defaults to `np_modal_checkout_interaction` but can be overriden if necessary.
|
|
20
40
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
41
|
+
export const sendEvent = (
|
|
42
|
+
payload,
|
|
43
|
+
eventName = 'np_modal_checkout_interaction'
|
|
44
|
+
) => {
|
|
23
45
|
if ( 'function' === typeof window.gtag && payload ) {
|
|
24
|
-
|
|
46
|
+
const filteredPayload = {};
|
|
47
|
+
for ( const key of eventKeys ) {
|
|
48
|
+
if ( payload[ key ] ) {
|
|
49
|
+
filteredPayload[ key ] = payload[ key ].toString();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
window.gtag( 'event', eventName, filteredPayload );
|
|
25
53
|
}
|
|
26
54
|
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get product details from the data-order-details attribute, for inside the iframe.
|
|
30
|
-
*
|
|
31
|
-
* @return {Object} Product details.
|
|
32
|
-
*
|
|
33
|
-
* @param {string} detailsElement ID of HTML element to get product details from.
|
|
34
|
-
*/
|
|
35
|
-
export const getProductDetails = ( detailsElement ) => {
|
|
36
|
-
const productDetailsContainer = document.getElementById( detailsElement );
|
|
37
|
-
const productDetailsJSON = productDetailsContainer ? productDetailsContainer.getAttribute( 'data-order-details' ) : false;
|
|
38
|
-
const productDetails = productDetailsJSON ? JSON.parse( productDetailsJSON ) : false;
|
|
39
|
-
return productDetails || {};
|
|
40
|
-
}
|
|
@@ -3,4 +3,4 @@ export { manageCheckoutSuccess } from './ga4/checkout-success';
|
|
|
3
3
|
export { manageDismissed } from './ga4/dismissed';
|
|
4
4
|
export { manageLoaded } from './ga4/loaded';
|
|
5
5
|
export { manageOpened } from './ga4/opened';
|
|
6
|
-
export { managePagination } from './ga4/pagination';
|
|
6
|
+
export { managePagination } from './ga4/pagination';
|
|
@@ -857,7 +857,8 @@
|
|
|
857
857
|
// Express checkout dividers.
|
|
858
858
|
// This is being replaced with JavaScript so it can be styled correctly.
|
|
859
859
|
#wcpay-express-checkout-button-separator,
|
|
860
|
-
#wc-stripe-payment-request-button-separator
|
|
860
|
+
#wc-stripe-payment-request-button-separator,
|
|
861
|
+
#wc-stripe-express-checkout-button-separator {
|
|
861
862
|
display: none !important; // !important needed to override inline styles.
|
|
862
863
|
|
|
863
864
|
&[style*="display:none"] + .newspack-ui__word-divider {
|
|
@@ -63,7 +63,7 @@ import { domReady } from './utils';
|
|
|
63
63
|
} else {
|
|
64
64
|
function init() {
|
|
65
65
|
// If present, update the markup used for the WooPayments express checkout divider.
|
|
66
|
-
$( '#wcpay-express-checkout-button-separator, #wc-stripe-payment-request-button-separator' ).after(
|
|
66
|
+
$( '#wcpay-express-checkout-button-separator, #wc-stripe-payment-request-button-separator, #wc-stripe-express-checkout-button-separator' ).after(
|
|
67
67
|
'<div class="newspack-ui__word-divider">' + newspackBlocksModalCheckout.divider_text + '</div>'
|
|
68
68
|
);
|
|
69
69
|
|