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.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / assets / js / frontend / order-attribution.js
woocommerce / assets / js / frontend Last commit date
add-payment-method.js 3 years ago add-payment-method.min.js 2 years ago add-to-cart-variation.js 3 years ago add-to-cart-variation.min.js 2 years ago add-to-cart.js 2 years ago add-to-cart.min.js 2 years ago address-i18n.js 5 years ago address-i18n.min.js 2 years ago cart-fragments.js 3 years ago cart-fragments.min.js 2 years ago cart.js 2 years ago cart.min.js 2 years ago checkout.js 2 years ago checkout.min.js 2 years ago country-select.js 5 years ago country-select.min.js 2 years ago credit-card-form.js 8 years ago credit-card-form.min.js 8 years ago geolocation.js 2 years ago geolocation.min.js 2 years ago lost-password.js 8 years ago lost-password.min.js 8 years ago order-attribution.js 2 years ago order-attribution.min.js 2 years ago password-strength-meter.js 2 years ago password-strength-meter.min.js 2 years ago price-slider.js 5 years ago price-slider.min.js 2 years ago single-product.js 3 years ago single-product.min.js 2 years ago tokenization-form.js 5 years ago tokenization-form.min.js 2 years ago woocommerce.js 3 years ago woocommerce.min.js 2 years ago wp-consent-api-integration.js 2 years ago wp-consent-api-integration.min.js 2 years ago
order-attribution.js
187 lines
1 ( function ( wc_order_attribution ) {
2 'use strict';
3 // Cache params reference for shorter reusability.
4 const params = wc_order_attribution.params;
5
6 // Helper functions.
7 const $ = document.querySelector.bind( document );
8 const propertyAccessor = ( obj, path ) => path.split( '.' ).reduce( ( acc, part ) => acc && acc[ part ], obj );
9 const returnNull = () => null;
10 const stringifyFalsyInputValue = ( value ) => value === null || value === undefined ? '' : value;
11
12 // Hardcode Checkout store key (`wc.wcBlocksData.CHECKOUT_STORE_KEY`), as we no longer have `wc-blocks-checkout` as a dependency.
13 const CHECKOUT_STORE_KEY = 'wc/store/checkout';
14
15 /**
16 * Get the order attribution data.
17 *
18 * Returns object full of `null`s if tracking is disabled.
19 *
20 * @returns {Object} Schema compatible object.
21 */
22 function getData() {
23 const accessor = params.allowTracking ? propertyAccessor : returnNull;
24 const entries = Object.entries( wc_order_attribution.fields )
25 .map( ( [ key, property ] ) => [ key, accessor( sbjs.get, property ) ] );
26 return Object.fromEntries( entries );
27 }
28
29 /**
30 * Update `wc_order_attribution` input elements' values.
31 *
32 * @param {Object} values Object containing field values.
33 */
34 function updateFormValues( values ) {
35 // Update `<wc-order-attribution-inputs>` elements if any exist.
36 for( const element of document.querySelectorAll( 'wc-order-attribution-inputs' ) ) {
37 element.values = values;
38 }
39
40 };
41
42 /**
43 * Update Checkout extension data.
44 *
45 * @param {Object} values Object containing field values.
46 */
47 function updateCheckoutBlockData( values ) {
48 // Update Checkout block data if available.
49 if ( window.wp && window.wp.data && window.wp.data.dispatch && window.wc && window.wc.wcBlocksData ) {
50 window.wp.data.dispatch( window.wc.wcBlocksData.CHECKOUT_STORE_KEY ).__internalSetExtensionData(
51 'woocommerce/order-attribution',
52 values,
53 true
54 );
55 }
56 }
57
58 /**
59 * Initialize sourcebuster & set data, or clear cookies & data.
60 *
61 * @param {boolean} allow Whether to allow tracking or disable it.
62 */
63 wc_order_attribution.setOrderTracking = function( allow ) {
64 params.allowTracking = allow;
65 if ( ! allow ) {
66 // Reset cookies, and clear form data.
67 removeTrackingCookies();
68 } else {
69 // If not done yet, initialize sourcebuster.js which populates `sbjs.get` object.
70 sbjs.init( {
71 lifetime: Number( params.lifetime ),
72 session_length: Number( params.session ),
73 timezone_offset: '0', // utc
74 } );
75 }
76 const values = getData();
77 updateFormValues( values );
78 updateCheckoutBlockData( values );
79 }
80
81 /**
82 * Remove sourcebuster.js cookies.
83 * To be called whenever tracking is disabled or consent is revoked.
84 */
85 function removeTrackingCookies() {
86 const domain = window.location.hostname;
87 const sbCookies = [
88 'sbjs_current',
89 'sbjs_current_add',
90 'sbjs_first',
91 'sbjs_first_add',
92 'sbjs_session',
93 'sbjs_udata',
94 'sbjs_migrations',
95 'sbjs_promo'
96 ];
97
98 // Remove cookies
99 sbCookies.forEach( ( name ) => {
100 document.cookie = `${name}=; path=/; max-age=-999; domain=.${domain};`;
101 } );
102 }
103
104 // Run init.
105 wc_order_attribution.setOrderTracking( params.allowTracking );
106
107 // Work around the lack of explicit script dependency for the checkout block.
108 // Conditionally, wait for and use 'wp-data' & 'wc-blocks-checkout.
109
110 // Wait for (async) block checkout initialization and set source values once loaded.
111 function eventuallyInitializeCheckoutBlock() {
112 if (
113 window.wp && window.wp.data && typeof window.wp.data.subscribe === 'function'
114 ) {
115 // Update checkout block data once more if the checkout store was loaded after this script.
116 const unsubscribe = window.wp.data.subscribe( function () {
117 unsubscribe();
118 updateCheckoutBlockData( getData() );
119 }, CHECKOUT_STORE_KEY );
120 }
121 };
122 // Wait for DOMContentLoaded to make sure wp.data is in place, if applicable for the page.
123 if (document.readyState === "loading") {
124 document.addEventListener("DOMContentLoaded", eventuallyInitializeCheckoutBlock);
125 } else {
126 eventuallyInitializeCheckoutBlock();
127 }
128
129 /**
130 * Define an element to contribute order attribute values to the enclosing form.
131 * To be used with the classic checkout.
132 */
133 window.customElements.define( 'wc-order-attribution-inputs', class extends HTMLElement {
134 // Our bundler version does not support private class members, so we use a convention of `_` prefix.
135 // #values
136 // #fieldNames
137 constructor(){
138 super();
139 // Cache fieldNames available at the construction time, to avoid malformed behavior if they change in runtime.
140 this._fieldNames = Object.keys( wc_order_attribution.fields );
141 // Allow values to be lazily set before CE upgrade.
142 if ( this.hasOwnProperty( '_values' ) ) {
143 let values = this.values;
144 // Restore the setter.
145 delete this.values;
146 this.values = values || {};
147 }
148 }
149 /**
150 * Stamp input elements to the element's light DOM.
151 *
152 * We could use `.elementInternals.setFromValue` and avoid sprouting `<input>` elements,
153 * but it's not yet supported in Safari.
154 */
155 connectedCallback() {
156 let inputs = '';
157 for( const fieldName of this._fieldNames ) {
158 const value = stringifyFalsyInputValue( this.values[ fieldName ] );
159 inputs += `<input type="hidden" name="${params.prefix}${fieldName}" value="${value}"/>`;
160 }
161 this.innerHTML = inputs;
162 }
163
164 /**
165 * Update form values.
166 */
167 set values( values ) {
168 this._values = values;
169 if( this.isConnected ) {
170 for( const fieldName of this._fieldNames ) {
171 const input = this.querySelector( `input[name="${params.prefix}${fieldName}"]` );
172 if( input ) {
173 input.value = stringifyFalsyInputValue( this.values[ fieldName ] );
174 } else {
175 console.warn( `Field "${fieldName}" not found. Most likely, the '<wc-order-attribution-inputs>' element was manipulated.`);
176 }
177 }
178 }
179 }
180 get values() {
181 return this._values;
182 }
183 } );
184
185
186 }( window.wc_order_attribution ) );
187