PageSourceSearch

https://diamondiptv.eu/wp-content/plugins/cartflows-pro/assets/js/analytics.js?ver=3.3.0

js diamondiptv.eu collected 2026-10-09 17:07:48 UTC 4,645 bytes, 156 lines download raw bytes

1( function ( $ ) {
2	function setCookie( cName, cValue, expDays ) {
3		const date = new Date();
4		date.setTime( date.getTime() + expDays * 24 * 60 * 60 * 1000 );
5		const expires = 'expires=' + date.toUTCString();
6		document.cookie = cName + '=' + cValue + '; ' + expires + '; path=/';
7	}
8
9	function getCookie( cName ) {
10		const name = cName + '=';
11		const cDecoded = decodeURIComponent( document.cookie ); //to be careful
12		const cArr = cDecoded.split( '; ' );
13		let res = [];
14		cArr.forEach( ( val ) => {
15			if ( val.indexOf( name ) === 0 ) {
16				res = val.substring( name.length );
17			}
18		} );
19		return res;
20	}
21
22	async function load_frontend_analytics() {
23		if ( cartflows && '' !== cartflows.current_step ) {
24			const flow_id = cartflows.current_flow,
25				step_id = cartflows.current_step,
26				flow_cookie = cartflows.flow_cookie + flow_id,
27				step_cookie = cartflows.step_cookie + flow_id;
28
29			let flow_cookieData = getCookie( flow_cookie );
30
31			if ( flow_cookieData.length > 0 ) {
32				flow_cookieData = JSON.parse(
33					decodeURIComponent( flow_cookieData )
34				);
35			}
36
37			const is_returning = flow_cookieData.includes( step_id );
38
39			if ( ! is_returning ) {
40				flow_cookieData.push( step_id );
41			}
42
43			setCookie(
44				flow_cookie,
45				encodeURIComponent( JSON.stringify( flow_cookieData ) ),
46				cartflows.analytics_cookie_expire_time
47			);
48
49			let base_url = cartflows?.analytics_base_url;
50
51			// Added a fallback if the URL is not formed or empty or does not have the complete website URL.
52			if (
53				'' === base_url ||
54				'null' === base_url ||
55				'/wp-json/cartflows-pro/v1/flow-analytics/' === base_url
56			) {
57				const basePath =
58						window.location.pathname.split( '/' )[ 1 ] || '',
59					full_url =
60						window.location.origin + '/' + basePath + '/wp-json';
61
62				base_url = `${ full_url }cartflows-pro/v1/flow-analytics/`;
63			}
64
65			const url = base_url,
66				urlParams = new URLSearchParams( window.location.search ),
67				paramsArray = [];
68
69			if ( urlParams.size > 0 ) {
70				urlParams.forEach( function ( value, key ) {
71					paramsArray.push( { name: key, value } );
72				} );
73			}
74
75			let step_cookieData = getCookie( step_cookie );
76
77			const data = {
78				step_id: cartflows.current_step,
79				flow_id: cartflows.current_flow,
80				is_returning,
81				flow_cookie_data: JSON.stringify( flow_cookieData ),
82				step_cookie_data: step_cookieData,
83				url_params: JSON.stringify( paramsArray ),
84				analytics_nonce: cartflows.analytics_nonce,
85			};
86			try {
87				fetch( url, {
88					method: 'POST', // *GET, POST, PUT, DELETE, etc.
89					mode: 'cors', // no-cors, *cors, same-origin
90					cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
91					credentials: 'same-origin', // Required: the endpoint verifies a nonce, which is user-scoped.
92					headers: {
93						'Content-Type': 'application/json',
94						// Lets WordPress authenticate the cookie on a REST request; without
95						// it the request is treated as anonymous and the analytics nonce
96						// below cannot verify for a logged-in visitor.
97						'X-WP-Nonce': cartflows.analytics_rest_nonce,
98					},
99					redirect: 'follow', // manual, *follow, error
100					referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
101					body: JSON.stringify( data ), // body data type must match "Content-Type" header
102				} )
103					.then( ( js_data ) => js_data.json() )
104					.then( ( response ) => {
105						if ( response.success ) {
106							step_cookieData = getCookie( step_cookie );
107							const prev_control_id = response.prev_control_id;
108
109							step_cookieData =
110								step_cookieData.length > 0
111									? JSON.parse(
112											decodeURIComponent(
113												step_cookieData
114											)
115									  )
116									: {};
117
118							if (
119								prev_control_id &&
120								step_cookieData.hasOwnProperty(
121									prev_control_id
122								)
123							) {
124								step_cookieData[ prev_control_id ].conversion =
125									'yes';
126
127								setCookie(
128									step_cookie,
129									encodeURIComponent(
130										JSON.stringify( step_cookieData )
131									),
132									cartflows.analytics_cookie_expire_time
133								);
134							}
135							step_cookieData[ cartflows.control_step ] =
136								JSON.parse( response.current_step_visit );
137
138							setCookie(
139								step_cookie,
140								encodeURIComponent(
141									JSON.stringify( step_cookieData )
142								),
143								cartflows.analytics_cookie_expire_time
144							);
145						}
146					} );
147			} catch ( error ) {
148				console.log( error );
149			}
150		}
151	}
152
153	$( function () {
154		load_frontend_analytics();
155	} );
156} )( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.