Version Description
- 29/06/2021 =
- Fixed remarketing code bug
Download this release
Release Info
Developer | Tatvic |
Plugin | Enhanced Ecommerce Google Analytics Plugin for WooCommerce |
Version | 3.1.2 |
Comparing to | |
See all releases |
Code changes from version 3.1.1 to 3.1.2
- admin/class-.txt +276 -0
- admin/class-survey.php +321 -0
- admin/class-tvc-admin-helper.php +42 -6
- admin/partials/general-fields.php +1 -0
- enhanced-ecommerce-google-analytics.php +2 -2
- includes/class-enhanced-ecommerce-google-analytics.php +12 -1
- includes/data/class-tvc-ajax-file.php +15 -0
- includes/setup/CustomApi.php +79 -0
- public/class-enhanced-ecommerce-google-analytics-public-pro.php +1736 -0
- public/class-enhanced-ecommerce-google-analytics-public.php +35 -25
- public/js/tvc-ee-google-analytics.js +512 -0
- readme.txt +5 -2
admin/class-.txt
ADDED
@@ -0,0 +1,276 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! class_exists( 'TVC_Survey' ) ) {
|
3 |
+
|
4 |
+
class TVC_Survey {
|
5 |
+
public $api_url = '';
|
6 |
+
public $name;
|
7 |
+
public $plugin;
|
8 |
+
public function __construct( $name = '', $plugin = '' ){
|
9 |
+
$this->name = $name;
|
10 |
+
$this->plugin = $plugin;
|
11 |
+
if ( $this->is_dev_url() ) {
|
12 |
+
return;
|
13 |
+
}
|
14 |
+
|
15 |
+
add_action( 'admin_print_scripts', array( $this, 'tvc_js' ), 20 );
|
16 |
+
add_action( 'admin_print_scripts', array( $this, 'tvc_css' ) );
|
17 |
+
add_action( 'admin_footer', array( $this, 'tvc_modal' ) );
|
18 |
+
}
|
19 |
+
public function is_dev_url() {
|
20 |
+
$url = network_site_url( '/' );
|
21 |
+
$is_local_url = false;
|
22 |
+
// Trim it up
|
23 |
+
$url = strtolower( trim( $url ) );
|
24 |
+
if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) {
|
25 |
+
$url = 'http://' . $url;
|
26 |
+
}
|
27 |
+
$url_parts = parse_url( $url );
|
28 |
+
$host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false;
|
29 |
+
if ( ! empty( $url ) && ! empty( $host ) ) {
|
30 |
+
if ( false !== ip2long( $host ) ) {
|
31 |
+
if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
|
32 |
+
$is_local_url = true;
|
33 |
+
}
|
34 |
+
} else if ( 'localhost' === $host ) {
|
35 |
+
$is_local_url = true;
|
36 |
+
}
|
37 |
+
|
38 |
+
$tlds_to_check = array( '.dev', '.local', ':8888' );
|
39 |
+
foreach ( $tlds_to_check as $tld ) {
|
40 |
+
if ( false !== strpos( $host, $tld ) ) {
|
41 |
+
$is_local_url = true;
|
42 |
+
continue;
|
43 |
+
}
|
44 |
+
|
45 |
+
}
|
46 |
+
if ( substr_count( $host, '.' ) > 1 ) {
|
47 |
+
$subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' );
|
48 |
+
foreach ( $subdomains_to_check as $subdomain ) {
|
49 |
+
$subdomain = str_replace( '.', '(.)', $subdomain );
|
50 |
+
$subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain );
|
51 |
+
if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) {
|
52 |
+
$is_local_url = true;
|
53 |
+
continue;
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
return $is_local_url;
|
59 |
+
}
|
60 |
+
public function is_plugin_page() {
|
61 |
+
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
|
62 |
+
if ( empty( $screen ) ) {
|
63 |
+
return false;
|
64 |
+
}
|
65 |
+
return ( ! empty( $screen->id ) && in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) );
|
66 |
+
}
|
67 |
+
public function tvc_js() {
|
68 |
+
|
69 |
+
if ( ! $this->is_plugin_page() ) {
|
70 |
+
return;
|
71 |
+
}
|
72 |
+
?>
|
73 |
+
<script type="text/javascript">
|
74 |
+
jQuery(function($){
|
75 |
+
var $deactivateLink = $('#the-list').find('[data-slug="<?php echo $this->plugin; ?>"] span.deactivate a'),
|
76 |
+
$overlay = $('#ee-survey-<?php echo $this->plugin; ?>'),
|
77 |
+
$form = $overlay.find('form'),
|
78 |
+
formOpen = false;
|
79 |
+
// Plugin listing table deactivate link.
|
80 |
+
$deactivateLink.on('click', function(event) {
|
81 |
+
event.preventDefault();
|
82 |
+
$overlay.css('display', 'table');
|
83 |
+
formOpen = true;
|
84 |
+
$form.find('.ee-survey-option:first-of-type input[type=radio]').focus();
|
85 |
+
});
|
86 |
+
// Survey radio option selected.
|
87 |
+
$form.on('change', 'input[type=radio]', function(event) {
|
88 |
+
event.preventDefault();
|
89 |
+
$form.find('input[type=text], .error').hide();
|
90 |
+
$form.find('.ee-survey-option').removeClass('selected');
|
91 |
+
$(this).closest('.ee-survey-option').addClass('selected').find('input[type=text]').show();
|
92 |
+
});
|
93 |
+
// Survey Skip & Deactivate.
|
94 |
+
$form.on('click', '.ee-survey-deactivate', function(event) {
|
95 |
+
event.preventDefault();
|
96 |
+
location.href = $deactivateLink.attr('href');
|
97 |
+
});
|
98 |
+
// Survey submit.
|
99 |
+
$form.submit(function(event) {
|
100 |
+
event.preventDefault();
|
101 |
+
if (! $form.find('input[type=radio]:checked').val()) {
|
102 |
+
$form.find('.ee-survey-footer').prepend('<span class="error"><?php echo esc_js( __( 'Please select an option', 'google-analytics-for-wordpress' ) ); ?></span>');
|
103 |
+
return;
|
104 |
+
}
|
105 |
+
var data = {
|
106 |
+
code: $form.find('.selected input[type=radio]').val(),
|
107 |
+
reason: $form.find('.selected .ee-survey-option-reason').text(),
|
108 |
+
details: $form.find('.selected input[type=text]').val(),
|
109 |
+
site: '<?php echo esc_url( home_url() ); ?>',
|
110 |
+
plugin: '<?php echo sanitize_key( $this->name ); ?>'
|
111 |
+
}
|
112 |
+
var submitSurvey = $.post('<?php echo $this->api_url; ?>', data);
|
113 |
+
submitSurvey.always(function() {
|
114 |
+
location.href = $deactivateLink.attr('href');
|
115 |
+
});
|
116 |
+
});
|
117 |
+
// Exit key closes survey when open.
|
118 |
+
$(document).keyup(function(event) {
|
119 |
+
if (27 === event.keyCode && formOpen) {
|
120 |
+
$overlay.hide();
|
121 |
+
formOpen = false;
|
122 |
+
$deactivateLink.focus();
|
123 |
+
}
|
124 |
+
});
|
125 |
+
});
|
126 |
+
</script>
|
127 |
+
<?php
|
128 |
+
}
|
129 |
+
public function tvc_css() {
|
130 |
+
|
131 |
+
if ( ! $this->is_plugin_page() ) {
|
132 |
+
return;
|
133 |
+
}
|
134 |
+
?>
|
135 |
+
<style type="text/css">
|
136 |
+
.ee-survey-modal {
|
137 |
+
display: none;
|
138 |
+
table-layout: fixed;
|
139 |
+
position: fixed;
|
140 |
+
z-index: 9999;
|
141 |
+
width: 100%;
|
142 |
+
height: 100%;
|
143 |
+
text-align: center;
|
144 |
+
font-size: 14px;
|
145 |
+
top: 0;
|
146 |
+
left: 0;
|
147 |
+
background: rgba(0,0,0,0.8);
|
148 |
+
}
|
149 |
+
.ee-survey-wrap {
|
150 |
+
display: table-cell;
|
151 |
+
vertical-align: middle;
|
152 |
+
}
|
153 |
+
.ee-survey {
|
154 |
+
background-color: #fff;
|
155 |
+
max-width: 550px;
|
156 |
+
margin: 0 auto;
|
157 |
+
padding: 30px;
|
158 |
+
text-align: left;
|
159 |
+
}
|
160 |
+
.ee-survey .error {
|
161 |
+
display: block;
|
162 |
+
color: red;
|
163 |
+
margin: 0 0 10px 0;
|
164 |
+
}
|
165 |
+
.ee-survey-title {
|
166 |
+
display: block;
|
167 |
+
font-size: 18px;
|
168 |
+
font-weight: 700;
|
169 |
+
text-transform: uppercase;
|
170 |
+
border-bottom: 1px solid #ddd;
|
171 |
+
padding: 0 0 18px 0;
|
172 |
+
margin: 0 0 18px 0;
|
173 |
+
}
|
174 |
+
.ee-survey-title span {
|
175 |
+
color: #999;
|
176 |
+
margin-right: 10px;
|
177 |
+
}
|
178 |
+
.ee-survey-desc {
|
179 |
+
display: block;
|
180 |
+
font-weight: 600;
|
181 |
+
margin: 0 0 18px 0;
|
182 |
+
}
|
183 |
+
.ee-survey-option {
|
184 |
+
margin: 0 0 10px 0;
|
185 |
+
}
|
186 |
+
.ee-survey-option-input {
|
187 |
+
margin-right: 10px !important;
|
188 |
+
}
|
189 |
+
.ee-survey-option-details {
|
190 |
+
display: none;
|
191 |
+
width: 90%;
|
192 |
+
margin: 10px 0 0 30px;
|
193 |
+
}
|
194 |
+
.ee-survey-footer {
|
195 |
+
margin-top: 18px;
|
196 |
+
}
|
197 |
+
.ee-survey-deactivate {
|
198 |
+
float: right;
|
199 |
+
font-size: 13px;
|
200 |
+
color: #ccc;
|
201 |
+
text-decoration: none;
|
202 |
+
padding-top: 7px;
|
203 |
+
}
|
204 |
+
</style>
|
205 |
+
<?php
|
206 |
+
}
|
207 |
+
public function tvc_modal() {
|
208 |
+
|
209 |
+
if ( ! $this->is_plugin_page() ) {
|
210 |
+
return;
|
211 |
+
}
|
212 |
+
|
213 |
+
$options = array(
|
214 |
+
1 => array(
|
215 |
+
"title" => esc_html__("No longer need the plugin","enhanced-e-commerce-for-woocommerce-store"),
|
216 |
+
),
|
217 |
+
2 => array(
|
218 |
+
'title' => esc_html__("Switching to a different plugin","enhanced-e-commerce-for-woocommerce-store"),
|
219 |
+
'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ),
|
220 |
+
),
|
221 |
+
3 => array(
|
222 |
+
'title' => esc_html__("Couldn't get the plugin to work","enhanced-e-commerce-for-woocommerce-store"),
|
223 |
+
),
|
224 |
+
4 => array(
|
225 |
+
'title' => esc_html__("It's a temporary deactivation","enhanced-e-commerce-for-woocommerce-store"),
|
226 |
+
),
|
227 |
+
5 => array(
|
228 |
+
'title' => esc_html__("No longer need the plugin","enhanced-e-commerce-for-woocommerce-store"),
|
229 |
+
'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ),
|
230 |
+
),
|
231 |
+
);
|
232 |
+
?>
|
233 |
+
<div class="ee-survey-modal" id="ee-survey-<?php echo $this->plugin; ?>">
|
234 |
+
<div class="ee-survey-wrap">
|
235 |
+
<form class="ee-survey" method="post">
|
236 |
+
<span class="ee-survey-title"><span class="dashicons dashicons-testimonial"></span><?php echo ' ' . esc_html__( 'Quick Feedback', 'google-analytics-for-wordpress' ); ?></span>
|
237 |
+
<span class="ee-survey-desc">
|
238 |
+
<?php
|
239 |
+
// Translators: Placeholder for the plugin name.
|
240 |
+
echo sprintf( esc_html__('If you have a moment, please share why you are deactivating %s:', 'google-analytics-for-wordpress' ), $this->name );
|
241 |
+
?>
|
242 |
+
</span>
|
243 |
+
<div class="ee-survey-options">
|
244 |
+
<?php foreach ( $options as $id => $option ) : ?>
|
245 |
+
<div class="ee-survey-option">
|
246 |
+
<label for="ee-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="ee-survey-option-label">
|
247 |
+
<input id="ee-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="ee-survey-option-input" type="radio" name="code" value="<?php echo $id; ?>" />
|
248 |
+
<span class="ee-survey-option-reason"><?php echo $option['title']; ?></span>
|
249 |
+
</label>
|
250 |
+
<?php if ( ! empty( $option['details'] ) ) : ?>
|
251 |
+
<input class="ee-survey-option-details" type="text" placeholder="<?php echo $option['details']; ?>" />
|
252 |
+
<?php endif; ?>
|
253 |
+
</div>
|
254 |
+
<?php endforeach; ?>
|
255 |
+
</div>
|
256 |
+
<div class="ee-survey-footer">
|
257 |
+
<button type="submit" class="ee-survey-submit button button-primary button-large">
|
258 |
+
<?php
|
259 |
+
// Translators: Adds an ampersand.
|
260 |
+
echo sprintf( esc_html__('Submit %s Deactivate', 'google-analytics-for-wordpress' ), '&' );
|
261 |
+
?>
|
262 |
+
</button>
|
263 |
+
<a href="#" class="ee-survey-deactivate">
|
264 |
+
<?php
|
265 |
+
// Translators: Adds an ampersand.
|
266 |
+
echo sprintf( esc_html__('Skip %s Deactivate', 'google-analytics-for-wordpress' ), '&' );
|
267 |
+
?>
|
268 |
+
</a>
|
269 |
+
</div>
|
270 |
+
</form>
|
271 |
+
</div>
|
272 |
+
</div>
|
273 |
+
<?php
|
274 |
+
}
|
275 |
+
}
|
276 |
+
}
|
admin/class-survey.php
ADDED
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if ( ! class_exists( 'TVC_Survey' ) ) {
|
3 |
+
|
4 |
+
class TVC_Survey {
|
5 |
+
public $api_url = TVC_API_CALL_URL.'/customersurvey';
|
6 |
+
public $name;
|
7 |
+
public $plugin;
|
8 |
+
protected $TVC_Admin_DB_Helper;
|
9 |
+
protected $apiCustomerId;
|
10 |
+
protected $subscriptionId;
|
11 |
+
public function __construct( $name = '', $plugin = '' ){
|
12 |
+
$this->name = $name;
|
13 |
+
$this->plugin = $plugin;
|
14 |
+
if ( $this->is_dev_url() ) {
|
15 |
+
return;
|
16 |
+
}
|
17 |
+
$this->TVC_Admin_Helper = new TVC_Admin_Helper();
|
18 |
+
$this->apiCustomerId = $this->TVC_Admin_Helper->get_api_customer_id();
|
19 |
+
$this->subscriptionId = $this->TVC_Admin_Helper->get_subscriptionId();
|
20 |
+
|
21 |
+
add_action( 'admin_print_scripts', array( $this, 'tvc_js' ), 20 );
|
22 |
+
add_action( 'admin_print_scripts', array( $this, 'tvc_css' ) );
|
23 |
+
add_action( 'admin_footer', array( $this, 'tvc_modal' ) );
|
24 |
+
}
|
25 |
+
public function is_dev_url() {
|
26 |
+
$url = network_site_url( '/' );
|
27 |
+
$is_local_url = false;
|
28 |
+
// Trim it up
|
29 |
+
$url = strtolower( trim( $url ) );
|
30 |
+
if ( false === strpos( $url, 'http://' ) && false === strpos( $url, 'https://' ) ) {
|
31 |
+
$url = 'http://' . $url;
|
32 |
+
}
|
33 |
+
$url_parts = parse_url( $url );
|
34 |
+
$host = ! empty( $url_parts['host'] ) ? $url_parts['host'] : false;
|
35 |
+
if ( ! empty( $url ) && ! empty( $host ) ) {
|
36 |
+
if ( false !== ip2long( $host ) ) {
|
37 |
+
if ( ! filter_var( $host, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) {
|
38 |
+
$is_local_url = true;
|
39 |
+
}
|
40 |
+
} else if ( 'localhost' === $host ) {
|
41 |
+
$is_local_url = true;
|
42 |
+
}
|
43 |
+
|
44 |
+
$tlds_to_check = array( '.dev', '.local', ':8888' );
|
45 |
+
foreach ( $tlds_to_check as $tld ) {
|
46 |
+
if ( false !== strpos( $host, $tld ) ) {
|
47 |
+
$is_local_url = true;
|
48 |
+
continue;
|
49 |
+
}
|
50 |
+
|
51 |
+
}
|
52 |
+
if ( substr_count( $host, '.' ) > 1 ) {
|
53 |
+
$subdomains_to_check = array( 'dev.', '*.staging.', 'beta.', 'test.' );
|
54 |
+
foreach ( $subdomains_to_check as $subdomain ) {
|
55 |
+
$subdomain = str_replace( '.', '(.)', $subdomain );
|
56 |
+
$subdomain = str_replace( array( '*', '(.)' ), '(.*)', $subdomain );
|
57 |
+
if ( preg_match( '/^(' . $subdomain . ')/', $host ) ) {
|
58 |
+
$is_local_url = true;
|
59 |
+
continue;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
return $is_local_url;
|
65 |
+
}
|
66 |
+
public function is_plugin_page() {
|
67 |
+
$screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;
|
68 |
+
if ( empty( $screen ) ) {
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
return ( ! empty( $screen->id ) && in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) );
|
72 |
+
}
|
73 |
+
public function tvc_js() {
|
74 |
+
|
75 |
+
if ( ! $this->is_plugin_page() ) {
|
76 |
+
return;
|
77 |
+
}
|
78 |
+
?>
|
79 |
+
<script type="text/javascript">
|
80 |
+
jQuery(function($){
|
81 |
+
var $deactivateLink = $('#the-list').find('[data-slug="<?php echo $this->plugin; ?>"] span.deactivate a'),
|
82 |
+
$overlay = $('#ee-survey-<?php echo $this->plugin; ?>'),
|
83 |
+
$form = $overlay.find('form'),
|
84 |
+
formOpen = false;
|
85 |
+
// Plugin listing table deactivate link.
|
86 |
+
$deactivateLink.on('click', function(event) {
|
87 |
+
event.preventDefault();
|
88 |
+
$overlay.css('display', 'table');
|
89 |
+
formOpen = true;
|
90 |
+
$form.find('.ee-survey-option:first-of-type input[type=radio]').focus();
|
91 |
+
});
|
92 |
+
// Survey radio option selected.
|
93 |
+
$form.on('change', 'input[type=radio]', function(event) {
|
94 |
+
event.preventDefault();
|
95 |
+
$form.find('input[type=text], .error').hide();
|
96 |
+
$form.find('.ee-survey-option').removeClass('selected');
|
97 |
+
$(this).closest('.ee-survey-option').addClass('selected').find('input[type=text]').show();
|
98 |
+
});
|
99 |
+
// Survey Skip & Deactivate.
|
100 |
+
$form.on('click', '.ee-survey-deactivate', function(event) {
|
101 |
+
event.preventDefault();
|
102 |
+
var data = {
|
103 |
+
action:'tvc_call_add_survey',
|
104 |
+
customer_id:'<?php echo $this->apiCustomerId; ?>',
|
105 |
+
subscription_id:'<?php echo $this->subscriptionId; ?>',
|
106 |
+
radio_option_val: "skip",
|
107 |
+
other_reason: "",
|
108 |
+
site_url: '<?php echo esc_url( home_url() ); ?>',
|
109 |
+
plugin_name: 'ee-woocommerce'
|
110 |
+
}
|
111 |
+
add_survey(data);
|
112 |
+
});
|
113 |
+
// Survey submit.
|
114 |
+
$form.submit(function(event) {
|
115 |
+
event.preventDefault();
|
116 |
+
if (! $form.find('input[type=radio]:checked').val()) {
|
117 |
+
$form.find('.ee-survey-footer').prepend('<span class="error"><?php echo esc_js( __( 'Please select an option', 'google-analytics-for-wordpress' ) ); ?></span>');
|
118 |
+
return;
|
119 |
+
}
|
120 |
+
var data = {
|
121 |
+
action:'tvc_call_add_survey',
|
122 |
+
customer_id:'<?php echo $this->apiCustomerId; ?>',
|
123 |
+
subscription_id:'<?php echo $this->subscriptionId; ?>',
|
124 |
+
radio_option_val: $form.find('.selected input[type=radio]').val(),
|
125 |
+
other_reason: $form.find('.selected input[type=text]').val(),
|
126 |
+
site_url: '<?php echo esc_url( home_url() ); ?>',
|
127 |
+
plugin_name: 'ee-woocommerce'
|
128 |
+
}
|
129 |
+
add_survey(data);
|
130 |
+
/*var submitSurvey = $.post('<?php echo $this->api_url; ?>', data);
|
131 |
+
submitSurvey.always(function() {
|
132 |
+
$(".ee-survey-modal").hide(100);
|
133 |
+
location.href = $deactivateLink.attr('href');
|
134 |
+
});*/
|
135 |
+
});
|
136 |
+
// Exit key closes survey when open.
|
137 |
+
$(document).keyup(function(event) {
|
138 |
+
if (27 === event.keyCode && formOpen) {
|
139 |
+
$overlay.hide();
|
140 |
+
formOpen = false;
|
141 |
+
$deactivateLink.focus();
|
142 |
+
}
|
143 |
+
});
|
144 |
+
function add_survey(data){
|
145 |
+
$.ajax({
|
146 |
+
type: "POST",
|
147 |
+
dataType: "json",
|
148 |
+
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
149 |
+
data: data,
|
150 |
+
beforeSend: function(){
|
151 |
+
//$('.ee-survey-submit').html("Thanks..");
|
152 |
+
$('.ee-survey-submit').prop('disabled', true);
|
153 |
+
$('.ee-survey-deactivate').hide();
|
154 |
+
},
|
155 |
+
success: function(response){
|
156 |
+
$(".ee-survey-modal").hide();
|
157 |
+
location.href = $deactivateLink.attr('href');
|
158 |
+
}
|
159 |
+
});
|
160 |
+
}
|
161 |
+
});
|
162 |
+
</script>
|
163 |
+
<?php
|
164 |
+
}
|
165 |
+
public function tvc_css() {
|
166 |
+
|
167 |
+
if ( ! $this->is_plugin_page() ) {
|
168 |
+
return;
|
169 |
+
}
|
170 |
+
?>
|
171 |
+
<style type="text/css">
|
172 |
+
.ee-survey-modal {
|
173 |
+
width: 100%;
|
174 |
+
height: 100%;
|
175 |
+
display: none;
|
176 |
+
table-layout: fixed;
|
177 |
+
position: fixed;
|
178 |
+
z-index: 9999;
|
179 |
+
text-align: center;
|
180 |
+
font-size: 14px;
|
181 |
+
top: 0;
|
182 |
+
left: 0;
|
183 |
+
background: rgba(0,0,0,0.8);
|
184 |
+
}
|
185 |
+
.ee-survey-wrap {
|
186 |
+
display: table-cell;
|
187 |
+
vertical-align: middle;
|
188 |
+
}
|
189 |
+
.ee-survey {
|
190 |
+
background-color: #fff;
|
191 |
+
padding: 32px;
|
192 |
+
max-width: 540px;
|
193 |
+
margin: 0 auto;
|
194 |
+
text-align: left;
|
195 |
+
border-radius: 40px;
|
196 |
+
}
|
197 |
+
.ee-survey .error {
|
198 |
+
display: block;
|
199 |
+
color: red;
|
200 |
+
margin: 0 0 10px 0;
|
201 |
+
}
|
202 |
+
.ee-survey-title {
|
203 |
+
display: block;
|
204 |
+
font-size: 18px;
|
205 |
+
font-weight: 700;
|
206 |
+
text-transform: uppercase;
|
207 |
+
border-bottom: 1px solid #ddd;
|
208 |
+
padding: 0 0 15px 0;
|
209 |
+
margin: 0 0 15px 0;
|
210 |
+
}
|
211 |
+
.ee-survey-title span {
|
212 |
+
color: #999;
|
213 |
+
margin-right: 10px;
|
214 |
+
}
|
215 |
+
.ee-survey-desc {
|
216 |
+
display: block;
|
217 |
+
font-weight: 600;
|
218 |
+
margin: 0 0 15px 0;
|
219 |
+
}
|
220 |
+
.ee-survey-option {
|
221 |
+
margin: 0 0 10px 0;
|
222 |
+
}
|
223 |
+
.ee-survey-option-input {
|
224 |
+
margin-right: 10px !important;
|
225 |
+
}
|
226 |
+
.ee-survey-option-details {
|
227 |
+
display: none;
|
228 |
+
width: 90%;
|
229 |
+
margin: 10px 0 0 30px;
|
230 |
+
}
|
231 |
+
.ee-survey-footer {
|
232 |
+
margin-top: 15px;
|
233 |
+
}
|
234 |
+
.ee-survey-deactivate {
|
235 |
+
font-size: 13px;
|
236 |
+
color: #ccc;
|
237 |
+
text-decoration: none;
|
238 |
+
margin-top: 7px;
|
239 |
+
float: right;
|
240 |
+
position: relative;
|
241 |
+
display: inline-block;
|
242 |
+
}
|
243 |
+
.ee-survey-wrap .dashicons{
|
244 |
+
font-size: 24px;
|
245 |
+
color: #3C434A;
|
246 |
+
}
|
247 |
+
</style>
|
248 |
+
<?php
|
249 |
+
}
|
250 |
+
public function tvc_modal() {
|
251 |
+
|
252 |
+
if ( ! $this->is_plugin_page() ) {
|
253 |
+
return;
|
254 |
+
}
|
255 |
+
|
256 |
+
$options = array(
|
257 |
+
1 => array(
|
258 |
+
"title" => esc_html__("No longer need the plugin","enhanced-e-commerce-for-woocommerce-store"),
|
259 |
+
),
|
260 |
+
2 => array(
|
261 |
+
'title' => esc_html__("Switching to a different plugin","enhanced-e-commerce-for-woocommerce-store"),
|
262 |
+
'details' => esc_html__( 'Please share which plugin', 'google-analytics-for-wordpress' ),
|
263 |
+
),
|
264 |
+
3 => array(
|
265 |
+
'title' => esc_html__("Couldn't get the plugin to work","enhanced-e-commerce-for-woocommerce-store"),
|
266 |
+
),
|
267 |
+
4 => array(
|
268 |
+
'title' => esc_html__("It's a temporary deactivation","enhanced-e-commerce-for-woocommerce-store"),
|
269 |
+
),
|
270 |
+
5 => array(
|
271 |
+
'title' => esc_html__("Other","enhanced-e-commerce-for-woocommerce-store"),
|
272 |
+
'details' => esc_html__( 'Please share the reason', 'google-analytics-for-wordpress' ),
|
273 |
+
),
|
274 |
+
);
|
275 |
+
?>
|
276 |
+
<div class="ee-survey-modal" id="ee-survey-<?php echo $this->plugin; ?>">
|
277 |
+
<div class="ee-survey-wrap">
|
278 |
+
<form class="ee-survey" method="post">
|
279 |
+
<span class="ee-survey-title"><span class="dashicons dashicons-admin-customizer"></span><?php echo ' ' . esc_html__( 'Quick Feedback', 'google-analytics-for-wordpress' ); ?></span>
|
280 |
+
<span class="ee-survey-desc">
|
281 |
+
<?php
|
282 |
+
// Translators: Placeholder for the plugin name.
|
283 |
+
echo sprintf( esc_html__('If you have a moment, please share why you are deactivating %s:', 'google-analytics-for-wordpress' ), $this->name );
|
284 |
+
?>
|
285 |
+
</span>
|
286 |
+
<div class="ee-survey-options">
|
287 |
+
<?php foreach ( $options as $id => $option ) :
|
288 |
+
//$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $option['title']);
|
289 |
+
$slug = sanitize_title($option['title']); ?>
|
290 |
+
<div class="ee-survey-option">
|
291 |
+
<label for="ee-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="ee-survey-option-label">
|
292 |
+
<input id="ee-survey-option-<?php echo $this->plugin; ?>-<?php echo $id; ?>" class="ee-survey-option-input" type="radio" name="code" value="<?php echo $slug; ?>" />
|
293 |
+
<span class="ee-survey-option-reason"><?php echo $option['title']; ?></span>
|
294 |
+
</label>
|
295 |
+
<?php if ( ! empty( $option['details'] ) ) : ?>
|
296 |
+
<input class="ee-survey-option-details" type="text" placeholder="<?php echo $option['details']; ?>" />
|
297 |
+
<?php endif; ?>
|
298 |
+
</div>
|
299 |
+
<?php endforeach; ?>
|
300 |
+
</div>
|
301 |
+
<div class="ee-survey-footer">
|
302 |
+
<button type="submit" class="ee-survey-submit button button-primary button-large">
|
303 |
+
<?php
|
304 |
+
// Translators: Adds an ampersand.
|
305 |
+
echo sprintf( esc_html__('Submit %s Deactivate', 'google-analytics-for-wordpress' ), '&' );
|
306 |
+
?>
|
307 |
+
</button>
|
308 |
+
<a href="#" class="ee-survey-deactivate">
|
309 |
+
<?php
|
310 |
+
// Translators: Adds an ampersand.
|
311 |
+
echo sprintf( esc_html__('Skip %s Deactivate', 'google-analytics-for-wordpress' ), '&' );
|
312 |
+
?>
|
313 |
+
</a>
|
314 |
+
</div>
|
315 |
+
</form>
|
316 |
+
</div>
|
317 |
+
</div>
|
318 |
+
<?php
|
319 |
+
}
|
320 |
+
}
|
321 |
+
}
|
admin/class-tvc-admin-helper.php
CHANGED
@@ -156,6 +156,23 @@ Class TVC_Admin_Helper{
|
|
156 |
return array("error"=>false, "message"=>"Details updated successfully.");
|
157 |
}
|
158 |
/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
* import GMC products in DB
|
160 |
*/
|
161 |
public function import_gmc_products_sync_in_db($next_page_token = null){
|
@@ -355,6 +372,13 @@ Class TVC_Admin_Helper{
|
|
355 |
}
|
356 |
}
|
357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
//tvc_customer = >google_ads_id
|
359 |
public function get_currentCustomerId(){
|
360 |
if(!empty($this->currentCustomerId)){
|
@@ -383,12 +407,6 @@ Class TVC_Admin_Helper{
|
|
383 |
return $this->user_currency_symbol;
|
384 |
}
|
385 |
}
|
386 |
-
|
387 |
-
public function add_tvc_log($log_string){
|
388 |
-
$log = "User: ".date("F j, Y, g:i a").PHP_EOL." Attempt: ".$log_string;
|
389 |
-
//Save string to log, use FILE_APPEND to append.
|
390 |
-
file_put_contents('log_tvc.log', $log, FILE_APPEND);
|
391 |
-
}
|
392 |
|
393 |
public function add_spinner_html(){
|
394 |
$spinner_gif = ENHANCAD_PLUGIN_URL . '/admin/images/ajax-loader.gif';
|
@@ -995,4 +1013,22 @@ Class TVC_Admin_Helper{
|
|
995 |
return false;
|
996 |
}
|
997 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
998 |
}
|
156 |
return array("error"=>false, "message"=>"Details updated successfully.");
|
157 |
}
|
158 |
/*
|
159 |
+
* update remarketing snippets
|
160 |
+
*/
|
161 |
+
public function update_remarketing_snippets(){
|
162 |
+
$customer_id = $this->get_currentCustomerId();
|
163 |
+
if($customer_id != ""){
|
164 |
+
$rs = $this->customApiObj->get_remarketing_snippets($customer_id);
|
165 |
+
$remarketing_snippets=array();
|
166 |
+
if(property_exists($rs,"error") && $rs->error == false){
|
167 |
+
if(property_exists($rs,"data") && $rs->data != "") {
|
168 |
+
$remarketing_snippets["snippets"]=base64_encode($rs->data->snippets);
|
169 |
+
$remarketing_snippets["id"]=$rs->data->id;
|
170 |
+
}
|
171 |
+
}
|
172 |
+
update_option("ee_remarketing_snippets", serialize($remarketing_snippets));
|
173 |
+
}
|
174 |
+
}
|
175 |
+
/*
|
176 |
* import GMC products in DB
|
177 |
*/
|
178 |
public function import_gmc_products_sync_in_db($next_page_token = null){
|
372 |
}
|
373 |
}
|
374 |
|
375 |
+
public function get_api_customer_id(){
|
376 |
+
$google_detail = $this->get_ee_options_data();
|
377 |
+
if(isset($google_detail['setting'])){
|
378 |
+
$googleDetail = (array) $google_detail['setting'];
|
379 |
+
return ((isset($googleDetail['customer_id']))?$googleDetail['customer_id']:"");
|
380 |
+
}
|
381 |
+
}
|
382 |
//tvc_customer = >google_ads_id
|
383 |
public function get_currentCustomerId(){
|
384 |
if(!empty($this->currentCustomerId)){
|
407 |
return $this->user_currency_symbol;
|
408 |
}
|
409 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
|
411 |
public function add_spinner_html(){
|
412 |
$spinner_gif = ENHANCAD_PLUGIN_URL . '/admin/images/ajax-loader.gif';
|
1013 |
return false;
|
1014 |
}
|
1015 |
}
|
1016 |
+
/*
|
1017 |
+
* get user plan id
|
1018 |
+
*/
|
1019 |
+
public function get_plan_id(){
|
1020 |
+
if(!empty($this->plan_id)){
|
1021 |
+
return $this->plan_id;
|
1022 |
+
}else{
|
1023 |
+
$plan_id = 1;
|
1024 |
+
if(isset($google_detail['setting'])){
|
1025 |
+
$googleDetail = $google_detail['setting'];
|
1026 |
+
if(isset($googleDetail->plan_id) && !in_array($googleDetail->plan_id, array("1"))){
|
1027 |
+
$plan_id = $googleDetail->plan_id;
|
1028 |
+
}
|
1029 |
+
}
|
1030 |
+
return $this->plan_id = $plan_id;
|
1031 |
+
}
|
1032 |
+
}
|
1033 |
+
|
1034 |
}
|
admin/partials/general-fields.php
CHANGED
@@ -100,6 +100,7 @@ if (isset($_GET['connect']) && isset($_GET['subscription_id'])) {
|
|
100 |
Enhanced_Ecommerce_Google_Settings::add_update_settings('ee_options');
|
101 |
//save data in DB
|
102 |
$TVC_Admin_Helper->set_update_api_to_db($googleDetail, false);
|
|
|
103 |
if(isset($googleDetail->google_merchant_center_id) || isset($googleDetail->google_ads_id) ){
|
104 |
if( $googleDetail->google_merchant_center_id != "" && $googleDetail->google_ads_id != ""){
|
105 |
wp_redirect("admin.php?page=enhanced-ecommerce-google-analytics-admin-display&tab=sync_product_page&welcome_msg=true");
|
100 |
Enhanced_Ecommerce_Google_Settings::add_update_settings('ee_options');
|
101 |
//save data in DB
|
102 |
$TVC_Admin_Helper->set_update_api_to_db($googleDetail, false);
|
103 |
+
$TVC_Admin_Helper->update_remarketing_snippets();
|
104 |
if(isset($googleDetail->google_merchant_center_id) || isset($googleDetail->google_ads_id) ){
|
105 |
if( $googleDetail->google_merchant_center_id != "" && $googleDetail->google_ads_id != ""){
|
106 |
wp_redirect("admin.php?page=enhanced-ecommerce-google-analytics-admin-display&tab=sync_product_page&welcome_msg=true");
|
enhanced-ecommerce-google-analytics.php
CHANGED
@@ -16,7 +16,7 @@
|
|
16 |
* Plugin Name: Enhanced E-commerce for Woocommerce store
|
17 |
* Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
|
18 |
* Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
|
19 |
-
* Version: 3.1.
|
20 |
* Author: Tatvic
|
21 |
* Author URI: www.tatvic.com
|
22 |
* License: GPL-2.0+
|
@@ -38,7 +38,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
38 |
* Start at version 1.0.0 and use SemVer - https://semver.org
|
39 |
* Rename this for your plugin and update it as you release new versions.
|
40 |
*/
|
41 |
-
define( 'PLUGIN_TVC_VERSION', '3.1.
|
42 |
$fullName = plugin_basename( __FILE__ );
|
43 |
$dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
|
44 |
if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
|
16 |
* Plugin Name: Enhanced E-commerce for Woocommerce store
|
17 |
* Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
|
18 |
* Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
|
19 |
+
* Version: 3.1.2
|
20 |
* Author: Tatvic
|
21 |
* Author URI: www.tatvic.com
|
22 |
* License: GPL-2.0+
|
38 |
* Start at version 1.0.0 and use SemVer - https://semver.org
|
39 |
* Rename this for your plugin and update it as you release new versions.
|
40 |
*/
|
41 |
+
define( 'PLUGIN_TVC_VERSION', '3.1.2' );
|
42 |
$fullName = plugin_basename( __FILE__ );
|
43 |
$dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
|
44 |
if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
|
includes/class-enhanced-ecommerce-google-analytics.php
CHANGED
@@ -125,6 +125,7 @@ class Enhanced_Ecommerce_Google_Analytics {
|
|
125 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-enhanced-ecommerce-google-analytics-settings.php';
|
126 |
|
127 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-auto-product-sync-helper.php';
|
|
|
128 |
|
129 |
|
130 |
/**
|
@@ -132,7 +133,13 @@ class Enhanced_Ecommerce_Google_Analytics {
|
|
132 |
* side of the site.
|
133 |
*/
|
134 |
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
$this->loader = new Enhanced_Ecommerce_Google_Analytics_Loader();
|
137 |
|
138 |
}
|
@@ -166,6 +173,9 @@ class Enhanced_Ecommerce_Google_Analytics {
|
|
166 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
|
167 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
|
168 |
$this->loader->add_action( 'admin_notices', $plugin_admin, 'tvc_admin_notice' );
|
|
|
|
|
|
|
169 |
|
170 |
}
|
171 |
|
@@ -178,6 +188,7 @@ class Enhanced_Ecommerce_Google_Analytics {
|
|
178 |
*/
|
179 |
private function define_public_hooks() {
|
180 |
$plugin_public = new Enhanced_Ecommerce_Google_Analytics_Public( $this->get_plugin_name(), $this->get_version() );
|
|
|
181 |
$this->loader->add_action("wp_head", $plugin_public, "ee_settings");
|
182 |
$this->loader->add_action("wp_head", $plugin_public, "add_google_site_verification_tag",1);
|
183 |
|
125 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-enhanced-ecommerce-google-analytics-settings.php';
|
126 |
|
127 |
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-auto-product-sync-helper.php';
|
128 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-survey.php';
|
129 |
|
130 |
|
131 |
/**
|
133 |
* side of the site.
|
134 |
*/
|
135 |
|
136 |
+
$TVC_Admin_Helper = new TVC_Admin_Helper();
|
137 |
+
$plan_id = $TVC_Admin_Helper->get_plan_id();
|
138 |
+
if($plan_id == 1){
|
139 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-enhanced-ecommerce-google-analytics-public.php';
|
140 |
+
}else{
|
141 |
+
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-enhanced-ecommerce-google-analytics-public.php';
|
142 |
+
}
|
143 |
$this->loader = new Enhanced_Ecommerce_Google_Analytics_Loader();
|
144 |
|
145 |
}
|
173 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
|
174 |
$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
|
175 |
$this->loader->add_action( 'admin_notices', $plugin_admin, 'tvc_admin_notice' );
|
176 |
+
if ( is_admin() ) {
|
177 |
+
new TVC_Survey( "Enhanced ecommerce google analytics plugin for woocommerce", ENHANCAD_PLUGIN_NAME );
|
178 |
+
}
|
179 |
|
180 |
}
|
181 |
|
188 |
*/
|
189 |
private function define_public_hooks() {
|
190 |
$plugin_public = new Enhanced_Ecommerce_Google_Analytics_Public( $this->get_plugin_name(), $this->get_version() );
|
191 |
+
$this->loader->add_action("wp_head", $plugin_public, "enqueue_scripts");
|
192 |
$this->loader->add_action("wp_head", $plugin_public, "ee_settings");
|
193 |
$this->loader->add_action("wp_head", $plugin_public, "add_google_site_verification_tag",1);
|
194 |
|
includes/data/class-tvc-ajax-file.php
CHANGED
@@ -36,6 +36,19 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
36 |
add_action('wp_ajax_tvc_call_notice_dismiss', array($this, 'tvc_call_notice_dismiss'));
|
37 |
add_action('wp_ajax_tvc_call_notification_dismiss', array($this, 'tvc_call_notification_dismiss'));
|
38 |
add_action('wp_ajax_tvc_call_active_licence', array($this, 'tvc_call_active_licence'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
//active licence key
|
41 |
public function tvc_call_active_licence(){
|
@@ -704,6 +717,8 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
|
|
704 |
),
|
705 |
'body' => wp_json_encode($data)
|
706 |
);
|
|
|
|
|
707 |
|
708 |
$request = wp_remote_post($url, $args);
|
709 |
|
36 |
add_action('wp_ajax_tvc_call_notice_dismiss', array($this, 'tvc_call_notice_dismiss'));
|
37 |
add_action('wp_ajax_tvc_call_notification_dismiss', array($this, 'tvc_call_notification_dismiss'));
|
38 |
add_action('wp_ajax_tvc_call_active_licence', array($this, 'tvc_call_active_licence'));
|
39 |
+
add_action('wp_ajax_tvc_call_add_survey', array($this, 'tvc_call_add_survey'));
|
40 |
+
}
|
41 |
+
|
42 |
+
public function tvc_call_add_survey(){
|
43 |
+
if ( is_admin() ) {
|
44 |
+
if(!class_exists('CustomApi')){
|
45 |
+
include(ENHANCAD_PLUGIN_DIR . 'includes/setup/CustomApi.php');
|
46 |
+
}
|
47 |
+
$customObj = new CustomApi();
|
48 |
+
unset($_POST['action']);
|
49 |
+
echo json_encode($customObj->add_survey_of_deactivate_plugin($_POST));
|
50 |
+
exit;
|
51 |
+
}
|
52 |
}
|
53 |
//active licence key
|
54 |
public function tvc_call_active_licence(){
|
717 |
),
|
718 |
'body' => wp_json_encode($data)
|
719 |
);
|
720 |
+
|
721 |
+
|
722 |
|
723 |
$request = wp_remote_post($url, $args);
|
724 |
|
includes/setup/CustomApi.php
CHANGED
@@ -213,6 +213,38 @@ class CustomApi{
|
|
213 |
return $e->getMessage();
|
214 |
}
|
215 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
public function active_licence_Key($licence_key, $subscription_id) {
|
217 |
try {
|
218 |
$header = array(
|
@@ -263,6 +295,53 @@ class CustomApi{
|
|
263 |
return $e->getMessage();
|
264 |
}
|
265 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
public function verifyLicenceKey($licence_key, $subscription_id) {
|
267 |
try {
|
268 |
echo $url = $this->apiDomain . '/licence/verify-key';
|
213 |
return $e->getMessage();
|
214 |
}
|
215 |
}
|
216 |
+
public function add_survey_of_deactivate_plugin($data) {
|
217 |
+
try {
|
218 |
+
$header = array(
|
219 |
+
"Authorization: Bearer MTIzNA==",
|
220 |
+
"content-type: application/json"
|
221 |
+
);
|
222 |
+
$curl_url = $this->apiDomain . "/customersurvey";
|
223 |
+
$postData = json_encode($data);
|
224 |
+
$ch = curl_init();
|
225 |
+
curl_setopt_array($ch, array(
|
226 |
+
CURLOPT_URL => esc_url($curl_url),
|
227 |
+
CURLOPT_RETURNTRANSFER => true,
|
228 |
+
CURLOPT_TIMEOUT => 1000,
|
229 |
+
CURLOPT_HTTPHEADER => $header,
|
230 |
+
CURLOPT_POSTFIELDS => $postData
|
231 |
+
));
|
232 |
+
$response = curl_exec($ch);
|
233 |
+
$response = json_decode($response);
|
234 |
+
$return = new \stdClass();
|
235 |
+
if (isset($response->error) && $response->error == '') {
|
236 |
+
$return->error = false;
|
237 |
+
$return->message = $response->message;
|
238 |
+
return $return;
|
239 |
+
} else {
|
240 |
+
$return->error = false;
|
241 |
+
$return->message = $response->message;
|
242 |
+
return $return;
|
243 |
+
}
|
244 |
+
} catch (Exception $e) {
|
245 |
+
return $e->getMessage();
|
246 |
+
}
|
247 |
+
}
|
248 |
public function active_licence_Key($licence_key, $subscription_id) {
|
249 |
try {
|
250 |
$header = array(
|
295 |
return $e->getMessage();
|
296 |
}
|
297 |
}
|
298 |
+
public function get_remarketing_snippets($customer_id) {
|
299 |
+
try {
|
300 |
+
$header = array(
|
301 |
+
"Authorization: Bearer MTIzNA==",
|
302 |
+
"content-type: application/json"
|
303 |
+
);
|
304 |
+
$curl_url = $this->apiDomain . "/google-ads/remarketing-snippets";
|
305 |
+
$postData = [
|
306 |
+
'customer_id' => $customer_id
|
307 |
+
];
|
308 |
+
$postData = json_encode($postData);
|
309 |
+
$ch = curl_init();
|
310 |
+
curl_setopt_array($ch, array(
|
311 |
+
CURLOPT_URL => esc_url($curl_url),
|
312 |
+
CURLOPT_RETURNTRANSFER => true,
|
313 |
+
CURLOPT_TIMEOUT => 1000,
|
314 |
+
CURLOPT_HTTPHEADER => $header,
|
315 |
+
CURLOPT_POSTFIELDS => $postData
|
316 |
+
));
|
317 |
+
$response = curl_exec($ch);
|
318 |
+
$response = json_decode($response);
|
319 |
+
$return = new \stdClass();
|
320 |
+
if (isset($response->error) && $response->error == '') {
|
321 |
+
$return->error = false;
|
322 |
+
$return->data = $response->data;
|
323 |
+
$return->message = $response->message;
|
324 |
+
return $return;
|
325 |
+
} else {
|
326 |
+
if (isset($response->data)) {
|
327 |
+
$return->error = false;
|
328 |
+
$return->data = $response->data;
|
329 |
+
$return->message = $response->message;
|
330 |
+
} else {
|
331 |
+
$return->error = true;
|
332 |
+
$return->data = [];
|
333 |
+
if(isset($response->errors->key[0])){
|
334 |
+
$return->message = $response->errors->key[0];
|
335 |
+
}else{
|
336 |
+
$return->message = "";
|
337 |
+
}
|
338 |
+
}
|
339 |
+
return $return;
|
340 |
+
}
|
341 |
+
} catch (Exception $e) {
|
342 |
+
return $e->getMessage();
|
343 |
+
}
|
344 |
+
}
|
345 |
public function verifyLicenceKey($licence_key, $subscription_id) {
|
346 |
try {
|
347 |
echo $url = $this->apiDomain . '/licence/verify-key';
|
public/class-enhanced-ecommerce-google-analytics-public-pro.php
ADDED
@@ -0,0 +1,1736 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The public-facing functionality of the plugin.
|
5 |
+
*
|
6 |
+
* @link tatvic.com
|
7 |
+
* @since 1.0.0
|
8 |
+
*
|
9 |
+
* @package Enhanced_Ecommerce_Google_Analytics
|
10 |
+
* @subpackage Enhanced_Ecommerce_Google_Analytics/public
|
11 |
+
*/
|
12 |
+
|
13 |
+
/**
|
14 |
+
* The public-facing functionality of the plugin.
|
15 |
+
*
|
16 |
+
* Defines the plugin name, version, and two examples hooks for how to
|
17 |
+
* enqueue the public-facing stylesheet and JavaScript.
|
18 |
+
*
|
19 |
+
* @package Enhanced_Ecommerce_Google_Analytics
|
20 |
+
* @subpackage Enhanced_Ecommerce_Google_Analytics/public
|
21 |
+
* @author Chetan Rode <chetan@tatvic.com>
|
22 |
+
*/
|
23 |
+
class Enhanced_Ecommerce_Google_Analytics_Public {
|
24 |
+
/**
|
25 |
+
* Init and hook in the integration.
|
26 |
+
*
|
27 |
+
* @access public
|
28 |
+
* @return void
|
29 |
+
*/
|
30 |
+
//set plugin version
|
31 |
+
protected $plugin_name;
|
32 |
+
protected $version;
|
33 |
+
|
34 |
+
public $tvc_eeVer = PLUGIN_TVC_VERSION;
|
35 |
+
protected $ga_LC;
|
36 |
+
protected $ga_Dname;
|
37 |
+
|
38 |
+
protected $ga_id;
|
39 |
+
protected $gm_id;
|
40 |
+
protected $google_ads_id;
|
41 |
+
protected $google_merchant_id;
|
42 |
+
|
43 |
+
protected $tracking_option;
|
44 |
+
|
45 |
+
protected $ga_ST;
|
46 |
+
protected $ga_eeT;
|
47 |
+
protected $ga_gUser;
|
48 |
+
|
49 |
+
protected $ga_imTh;
|
50 |
+
|
51 |
+
protected $ga_IPA;
|
52 |
+
protected $ga_OPTOUT;
|
53 |
+
|
54 |
+
protected $ads_ert;
|
55 |
+
protected $ads_edrt;
|
56 |
+
protected $ads_tracking_id;
|
57 |
+
|
58 |
+
protected $ga_PrivacyPolicy;
|
59 |
+
|
60 |
+
protected $ga_gCkout;
|
61 |
+
protected $ga_DF;
|
62 |
+
protected $tvc_options;
|
63 |
+
protected $TVC_Admin_Helper;
|
64 |
+
/**
|
65 |
+
* Enhanced_Ecommerce_Google_Analytics_Public constructor.
|
66 |
+
* @param $plugin_name
|
67 |
+
* @param $version
|
68 |
+
*/
|
69 |
+
|
70 |
+
public function __construct($plugin_name, $version) {
|
71 |
+
$this->TVC_Admin_Helper = new TVC_Admin_Helper();
|
72 |
+
$this->plugin_name = $plugin_name;
|
73 |
+
$this->version = $version;
|
74 |
+
$this->ga_Dname = "auto";
|
75 |
+
$this->tvc_aga = $this->get_option("tvc_aga");
|
76 |
+
$this->ga_id = $this->get_option("ga_id");
|
77 |
+
$this->ga_eeT = $this->get_option("ga_eeT");
|
78 |
+
$this->enhanced_e_commerce_tracking = $this->get_option("enhanced_e_commerce_tracking");
|
79 |
+
$this->ga_ST = $this->get_option("ga_ST"); //add_gtag_snippet
|
80 |
+
$this->add_gtag_snippet = $this->get_option("add_gtag_snippet"); //add_gtag_snippet
|
81 |
+
$this->gm_id = $this->get_option("gm_id"); //measurement_id
|
82 |
+
$this->google_ads_id = $this->get_option("google_ads_id");
|
83 |
+
$this->ga_excT = $this->get_option("ga_excT"); //exception_tracking
|
84 |
+
$this->exception_tracking = $this->get_option("exception_tracking"); //exception_tracking
|
85 |
+
$this->ga_elaT = $this->get_option("ga_elaT"); //enhanced_link_attribution_tracking
|
86 |
+
$this->google_merchant_id = $this->get_option("google_merchant_id");
|
87 |
+
$this->tracking_option = $this->get_option("tracking_option");
|
88 |
+
$this->ga_gCkout = $this->get_option("ga_gCkout") == "on" ? true : false; //guest checkout
|
89 |
+
$this->ga_gUser = $this->get_option("ga_gUser") == "on" ? true : false; //guest checkout
|
90 |
+
$this->ga_DF = $this->get_option("ga_DF") == "on" ? true : false;
|
91 |
+
$this->ga_imTh = $this->get_option("ga_Impr") == "" ? 6 : $this->get_option("ga_Impr");
|
92 |
+
$this->ga_OPTOUT = $this->get_option("ga_OPTOUT") == "on" ? true : false; //Google Analytics Opt Out
|
93 |
+
$this->ga_PrivacyPolicy = $this->get_option("ga_PrivacyPolicy") == "on" ? true : false;
|
94 |
+
$this->ga_IPA = $this->get_option("ga_IPA") == "on" ? true : false; //IP Anony.
|
95 |
+
$this->ads_ert = get_option('ads_ert'); //Enable remarketing tags
|
96 |
+
$this->ads_edrt = get_option('ads_edrt'); //Enable dynamic remarketing tags
|
97 |
+
$this->ads_tracking_id = get_option('ads_tracking_id');
|
98 |
+
$this->ads_ert = get_option('ads_ert');
|
99 |
+
$this->ads_edrt = get_option('ads_edrt');
|
100 |
+
//$this->subscription_id = $this->get_option("subscription_id");
|
101 |
+
//setcookie('subscription_id', $this->subscription_id);
|
102 |
+
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
|
103 |
+
// Put your plugin code here
|
104 |
+
add_action('woocommerce_init' , function (){
|
105 |
+
$this->ga_LC = get_woocommerce_currency(); //Local Currency from Back end
|
106 |
+
$this->wc_version_compare("tvc_lc=" . json_encode($this->ga_LC) . ";");
|
107 |
+
/*
|
108 |
+
* start tvc_options
|
109 |
+
*/
|
110 |
+
$current_user = wp_get_current_user();
|
111 |
+
//$current_user ="";
|
112 |
+
$user_id = "";
|
113 |
+
$user_type = "guest_user";
|
114 |
+
if ( isset($current_user->ID) && $current_user->ID != 0 ) {
|
115 |
+
$user_id = $current_user->ID;
|
116 |
+
$current_user_type = 'register_user';
|
117 |
+
}
|
118 |
+
$this->tvc_options = array(
|
119 |
+
"feature_product_label"=>"Feature Product",
|
120 |
+
"on_sale_label"=>"On Sale",
|
121 |
+
"affiliation"=>esc_js(get_bloginfo('name')),
|
122 |
+
"local_time"=>time(),
|
123 |
+
"is_admin"=>is_admin(),
|
124 |
+
"currency"=>$this->ga_LC,
|
125 |
+
"tracking_option"=>$this->tracking_option,
|
126 |
+
"property_id"=>$this->ga_id,
|
127 |
+
"measurement_id"=>$this->gm_id,
|
128 |
+
"google_ads_id"=>$this->google_ads_id,
|
129 |
+
"google_merchant_center_id"=>$this->google_merchant_id,
|
130 |
+
"o_add_gtag_snippet"=>$this->ga_ST,
|
131 |
+
"o_enhanced_e_commerce_tracking"=>$this->ga_eeT,
|
132 |
+
"o_log_step_gest_user"=>$this->ga_gUser,
|
133 |
+
"o_impression_thresold"=>$this->ga_imTh,
|
134 |
+
"o_ip_anonymization"=>$this->ga_IPA,
|
135 |
+
"o_ga_OPTOUT"=>$this->ga_OPTOUT,
|
136 |
+
"ads_tracking_id"=>$this->ads_tracking_id,
|
137 |
+
"remarketing_tags"=>$this->ads_ert,
|
138 |
+
"dynamic_remarketing_tags"=>$this->ads_edrt,
|
139 |
+
"page_type"=>$this->add_page_type(),
|
140 |
+
"user_id"=>$user_id,
|
141 |
+
"user_type"=>$user_type,
|
142 |
+
"day_type"=>$this->add_day_type()
|
143 |
+
);
|
144 |
+
/*
|
145 |
+
* end tvc_options
|
146 |
+
*/
|
147 |
+
});
|
148 |
+
} // end if woocommerce
|
149 |
+
}
|
150 |
+
|
151 |
+
public function getAttributesVariation($product) {
|
152 |
+
//variations start
|
153 |
+
if ($product->get_type() === "variable" || $product->get_type() === "variation") {
|
154 |
+
//variant data
|
155 |
+
$prod_var_array = $product->get_variation_attributes();
|
156 |
+
} else if ($product->get_type() === 'simple') {
|
157 |
+
//for simple product it's should be blank array
|
158 |
+
$prod_var_array = array();
|
159 |
+
} else if ($product->get_type() === 'yith_bundle' || $product->get_type() === 'woosb') {
|
160 |
+
//for simple product it's should be blank array
|
161 |
+
$prod_var_array = array();
|
162 |
+
} else if ($product->get_type() === 'bundle') {
|
163 |
+
//for simple product it's should be blank array
|
164 |
+
$prod_var_array = array();
|
165 |
+
}
|
166 |
+
$attributes = array();
|
167 |
+
if($prod_var_array){
|
168 |
+
foreach ($prod_var_array as $attribute_name => $attribute) {
|
169 |
+
$attr = (is_array($attribute) ? implode('|', $attribute) : $attribute);
|
170 |
+
$attributes[] = $attribute_name . '=>' . $attr;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
return implode(',', $attributes);
|
174 |
+
}
|
175 |
+
/**
|
176 |
+
* Calculate Product discount
|
177 |
+
*
|
178 |
+
* @access private
|
179 |
+
* @param mixed $type
|
180 |
+
* @return bool
|
181 |
+
*/
|
182 |
+
private function cal_prod_discount($t_rprc, $t_sprc) { //older $product Object
|
183 |
+
$t_dis = '0';
|
184 |
+
//calculate discount
|
185 |
+
if (!empty($t_rprc) && !empty($t_sprc)) {
|
186 |
+
$t_dis = sprintf("%.2f", (($t_rprc - $t_sprc) / $t_rprc) * 100);
|
187 |
+
}
|
188 |
+
return $t_dis;
|
189 |
+
}
|
190 |
+
/**
|
191 |
+
* Google Analytics content grouping
|
192 |
+
* Pages: Home, Category, Product, Cart, Checkout, Search ,Shop, Thankyou and Others
|
193 |
+
*
|
194 |
+
* @access public
|
195 |
+
* @return void
|
196 |
+
*/
|
197 |
+
function add_page_type() {
|
198 |
+
//identify pages
|
199 |
+
//echo "tt".is_wc_endpoint_url('order-received').is_checkout();
|
200 |
+
//exit;
|
201 |
+
|
202 |
+
if (is_home() || is_front_page()) {
|
203 |
+
$t_page_name = "Home Page";
|
204 |
+
} else if (is_product_category()) {
|
205 |
+
$t_page_name = "Category Pages";
|
206 |
+
} else if (is_product()) {
|
207 |
+
$t_page_name = "Product Pages";
|
208 |
+
} else if (is_cart()) {
|
209 |
+
$t_page_name = "Cart Page";
|
210 |
+
} else if (is_order_received_page()) {
|
211 |
+
$t_page_name = "Thankyou Page";
|
212 |
+
} else if (is_checkout()) {
|
213 |
+
$t_page_name = "Checkout Page";
|
214 |
+
} else if (is_search()) {
|
215 |
+
$t_page_name = "Search Page";
|
216 |
+
} else if (is_shop()) {
|
217 |
+
$t_page_name = "Shop Page";
|
218 |
+
} else if (is_404()) {
|
219 |
+
$t_page_name = "404 Error Pages";
|
220 |
+
} else {
|
221 |
+
$t_page_name = "Others";
|
222 |
+
}
|
223 |
+
//set js parameter - page name
|
224 |
+
//$this->wc_version_compare("tvc_pt=" . json_encode($t_page_name) . ";");
|
225 |
+
return $t_page_name;
|
226 |
+
//add content grouping code
|
227 |
+
}
|
228 |
+
/**
|
229 |
+
* Google Analytics Day type
|
230 |
+
*
|
231 |
+
* @access public
|
232 |
+
* @return void
|
233 |
+
*/
|
234 |
+
function add_day_type() {
|
235 |
+
$date = date("Y-m-d");
|
236 |
+
$day = strtolower(date('l', strtotime($date)));
|
237 |
+
if (($day == "saturday" ) || ($day == "sunday")) {
|
238 |
+
$day_type = "weekend";
|
239 |
+
} else {
|
240 |
+
$day_type = "weekday";
|
241 |
+
}
|
242 |
+
return $day_type;
|
243 |
+
}
|
244 |
+
/*
|
245 |
+
* Site verification using tag method
|
246 |
+
*/
|
247 |
+
public function add_google_site_verification_tag(){
|
248 |
+
$TVC_Admin_Helper = new TVC_Admin_Helper();
|
249 |
+
$ee_additional_data = $TVC_Admin_Helper->get_ee_additional_data();
|
250 |
+
if(isset($ee_additional_data['add_site_varification_tag']) && isset($ee_additional_data['site_varification_tag_val']) && $ee_additional_data['add_site_varification_tag'] == 1 && $ee_additional_data['site_varification_tag_val'] !="" ){
|
251 |
+
echo base64_decode($ee_additional_data['site_varification_tag_val']);
|
252 |
+
}
|
253 |
+
}
|
254 |
+
public function get_option($key){
|
255 |
+
$ee_options = array();
|
256 |
+
$my_option = get_option( 'ee_options' );
|
257 |
+
|
258 |
+
if(!empty($my_option)){
|
259 |
+
$ee_options = unserialize($my_option);
|
260 |
+
}
|
261 |
+
if(isset($ee_options[$key])){
|
262 |
+
return $ee_options[$key];
|
263 |
+
}
|
264 |
+
}
|
265 |
+
/**
|
266 |
+
* Get store meta data for trouble shoot
|
267 |
+
* @access public
|
268 |
+
* @return void
|
269 |
+
*/
|
270 |
+
function tvc_store_meta_data() {
|
271 |
+
//only on home page
|
272 |
+
global $woocommerce;
|
273 |
+
$google_detail = $this->TVC_Admin_Helper->get_ee_options_data();
|
274 |
+
$sub_data = array();
|
275 |
+
if(isset($google_detail['setting'])){
|
276 |
+
$googleDetail = $google_detail['setting'];
|
277 |
+
$sub_data['sub_id'] = $googleDetail->id;
|
278 |
+
$sub_data['cu_id']=$googleDetail->customer_id;
|
279 |
+
$sub_data['pl_id']=$googleDetail->plan_id;
|
280 |
+
$sub_data['ga_tra_option']=$googleDetail->tracking_option;
|
281 |
+
$sub_data['ga_property_id']=$googleDetail->google_ads_id;
|
282 |
+
$sub_data['ga_measurement_id']=$googleDetail->measurement_id;
|
283 |
+
$sub_data['ga_ads_id']=$googleDetail->google_ads_id;
|
284 |
+
$sub_data['ga_gmc_id']=$googleDetail->google_merchant_center_id;
|
285 |
+
$sub_data['op_gtag_js']=$googleDetail->add_gtag_snippet;
|
286 |
+
$sub_data['op_en_e_t']=$googleDetail->enhanced_e_commerce_tracking;
|
287 |
+
$sub_data['op_rm_t_t']=$googleDetail->remarketing_tags;
|
288 |
+
$sub_data['op_dy_rm_t_t']=$googleDetail->dynamic_remarketing_tags;
|
289 |
+
$sub_data['op_li_ga_wi_ads']=$googleDetail->link_google_analytics_with_google_ads;
|
290 |
+
$sub_data['gmc_is_product_sync']=$googleDetail->is_product_sync;
|
291 |
+
$sub_data['gmc_is_site_verified']=$googleDetail->is_site_verified;
|
292 |
+
$sub_data['gmc_is_domain_claim']=$googleDetail->is_domain_claim;
|
293 |
+
$sub_data['gmc_product_count']=$googleDetail->product_count;
|
294 |
+
}
|
295 |
+
$tvc_sMetaData = array(
|
296 |
+
'tvc_wcv' => $woocommerce->version,
|
297 |
+
'tvc_wpv' => get_bloginfo('version'),
|
298 |
+
'tvc_eev' => $this->tvc_eeVer,
|
299 |
+
'tvc_cnf' => array(
|
300 |
+
't_ee' => $this->ga_eeT,
|
301 |
+
't_df' => $this->ga_DF,
|
302 |
+
't_gUser'=>$this->ga_gUser,
|
303 |
+
't_UAen'=>$this->ga_ST,
|
304 |
+
't_thr' => $this->ga_imTh,
|
305 |
+
't_IPA' => $this->ga_IPA,
|
306 |
+
't_OptOut' => $this->ga_OPTOUT,
|
307 |
+
't_PrivacyPolicy' => $this->ga_PrivacyPolicy
|
308 |
+
),
|
309 |
+
'tvc_sub_data'=> $sub_data
|
310 |
+
);
|
311 |
+
$this->wc_version_compare("tvc_smd=" . json_encode($tvc_sMetaData) . ";");
|
312 |
+
}
|
313 |
+
|
314 |
+
/**
|
315 |
+
* Register the JavaScript for the public-facing side of the site.
|
316 |
+
*
|
317 |
+
* @since4.0.0
|
318 |
+
*/
|
319 |
+
public function enqueue_scripts() {
|
320 |
+
wp_enqueue_script($this->plugin_name, ENHANCAD_PLUGIN_URL . '/public/js/tvc-ee-google-analytics.js', array('jquery'), $this->version, false);
|
321 |
+
}
|
322 |
+
|
323 |
+
/**
|
324 |
+
* add dev id
|
325 |
+
*
|
326 |
+
* @access public
|
327 |
+
* @return void
|
328 |
+
*/
|
329 |
+
function add_dev_id() {
|
330 |
+
echo "<script>(window.gaDevIds=window.gaDevIds||[]).push('5CDcaG');</script>";
|
331 |
+
}
|
332 |
+
|
333 |
+
/**
|
334 |
+
* display details of plugin
|
335 |
+
*
|
336 |
+
* @access public
|
337 |
+
* @return void
|
338 |
+
*/
|
339 |
+
function add_plugin_details() {
|
340 |
+
echo '<!--Enhanced Ecommerce Google Analytics Plugin for Woocommerce by Tatvic Plugin Version:'.$this->tvc_eeVer.'-->';
|
341 |
+
}
|
342 |
+
|
343 |
+
/**
|
344 |
+
* Check if tracking is disabled
|
345 |
+
*
|
346 |
+
* @access private
|
347 |
+
* @param mixed $type
|
348 |
+
* @return bool
|
349 |
+
*/
|
350 |
+
private function disable_tracking($type) {
|
351 |
+
if (is_admin() || "" == $type || current_user_can("manage_options")) {
|
352 |
+
return true;
|
353 |
+
}
|
354 |
+
}
|
355 |
+
|
356 |
+
/**
|
357 |
+
* woocommerce version compare
|
358 |
+
*
|
359 |
+
* @access public
|
360 |
+
* @return void
|
361 |
+
*/
|
362 |
+
function wc_version_compare($codeSnippet) {
|
363 |
+
global $woocommerce;
|
364 |
+
|
365 |
+
if (version_compare($woocommerce->version, "2.1", ">=")) {
|
366 |
+
wc_enqueue_js($codeSnippet);
|
367 |
+
} else {
|
368 |
+
$woocommerce->add_inline_js($codeSnippet);
|
369 |
+
}
|
370 |
+
}
|
371 |
+
/**
|
372 |
+
* Enhanced Ecommerce GA plugin Settings
|
373 |
+
*
|
374 |
+
* @access public
|
375 |
+
* @return void
|
376 |
+
*/
|
377 |
+
function ee_settings() {
|
378 |
+
global $woocommerce;
|
379 |
+
//common validation----start
|
380 |
+
if (is_admin() || $this->ga_ST == "" || current_user_can("manage_options") || !$this->ga_PrivacyPolicy) {
|
381 |
+
return;
|
382 |
+
}
|
383 |
+
// IP Anonymization
|
384 |
+
if ($this->ga_IPA) {
|
385 |
+
$ga_ip_anonymization = '"anonymize_ip":true,';
|
386 |
+
} else {
|
387 |
+
$ga_ip_anonymization ="";
|
388 |
+
}
|
389 |
+
echo '<script type="text/javascript" defer="defer">';
|
390 |
+
echo 'var adsTringId = '.json_encode($this->ads_tracking_id).';';
|
391 |
+
echo 'var ads_ert = '.json_encode($this->ads_ert).';';
|
392 |
+
echo 'var ads_edrt = '.json_encode($this->ads_edrt).';';
|
393 |
+
echo '</script>';
|
394 |
+
|
395 |
+
if($this->ga_OPTOUT) {
|
396 |
+
echo '<script>
|
397 |
+
// Set to the same value as the web property used on the site
|
398 |
+
var gaProperty = "'.$this->ga_id.'";
|
399 |
+
// Disable tracking if the opt-out cookie exists.
|
400 |
+
var disableStr = "ga-disable-" + gaProperty;
|
401 |
+
if (document.cookie.indexOf(disableStr + "=true") > -1) {
|
402 |
+
window[disableStr] = true;
|
403 |
+
}
|
404 |
+
// Opt-out function
|
405 |
+
function gaOptout() {
|
406 |
+
var expDate = new Date;
|
407 |
+
expDate.setMonth(expDate.getMonth() + 26);
|
408 |
+
document.cookie = disableStr + "=true; expires="+expDate.toGMTString()+";path=/";
|
409 |
+
window[disableStr] = true;
|
410 |
+
}</script>';
|
411 |
+
}
|
412 |
+
//add gtag js snippets
|
413 |
+
if( $this->tracking_option == "BOTH" && $this->gm_id && $this->ga_id){
|
414 |
+
echo '<script async src="https://www.googletagmanager.com/gtag/js?id='.esc_js($this->gm_id).'"></script>
|
415 |
+
<script>
|
416 |
+
window.dataLayer = window.dataLayer || [];
|
417 |
+
function gtag(){dataLayer.push(arguments);}
|
418 |
+
gtag("js", new Date());
|
419 |
+
gtag("config", "'.esc_js($this->gm_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$this->ga_Dname.'",
|
420 |
+
"custom_map": {
|
421 |
+
"dimension1": "user_id",
|
422 |
+
"dimension2": "client_id",
|
423 |
+
"dimension3": "user_type",
|
424 |
+
"dimension4": "page_type",
|
425 |
+
"dimension5": "day_type",
|
426 |
+
"dimension6": "local_time_slot_of_the_day",
|
427 |
+
"dimension7": "product_discount",
|
428 |
+
"dimension8": "stock_status",
|
429 |
+
"dimension9": "inventory",
|
430 |
+
"dimension10": "search_query_parameter",
|
431 |
+
"dimension11": "payment_method",
|
432 |
+
"dimension12": "shipping_tier",
|
433 |
+
"metric1": "number_of_product_clicks_on_home_page",
|
434 |
+
"metric2": "number_of_product_clicks_on_plp",
|
435 |
+
"metric3": "number_of_product_clicks_on_pdp",
|
436 |
+
"metric4": "number_of_product_clicks_on_cart",
|
437 |
+
"metric5": "time_taken_to_add_to_cart",
|
438 |
+
"metric6": "time_taked_to_add_to_wishlist",
|
439 |
+
"metric7": "time_taken_to_make_the_purchase"
|
440 |
+
}
|
441 |
+
});
|
442 |
+
gtag("config", "'.esc_js($this->ga_id).'");
|
443 |
+
</script>';
|
444 |
+
}else if($this->tracking_option == "GA4" && $this->gm_id){
|
445 |
+
echo '<script async src="https://www.googletagmanager.com/gtag/js?id='.esc_js($this->gm_id).'"></script>
|
446 |
+
<script>
|
447 |
+
window.dataLayer = window.dataLayer || [];
|
448 |
+
function gtag(){dataLayer.push(arguments);}
|
449 |
+
gtag("js", new Date());
|
450 |
+
gtag("config", "'.esc_js($this->gm_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$this->ga_Dname.'",
|
451 |
+
"custom_map": {
|
452 |
+
"dimension1": "user_id",
|
453 |
+
"dimension2": "client_id",
|
454 |
+
"dimension3": "user_type",
|
455 |
+
"dimension4": "page_type",
|
456 |
+
"dimension5": "day_type",
|
457 |
+
"dimension6": "local_time_slot_of_the_day",
|
458 |
+
"dimension7": "product_discount",
|
459 |
+
"dimension8": "stock_status",
|
460 |
+
"dimension9": "inventory",
|
461 |
+
"dimension10": "search_query_parameter",
|
462 |
+
"dimension11": "payment_method",
|
463 |
+
"dimension12": "shipping_tier",
|
464 |
+
"metric1": "number_of_product_clicks_on_home_page",
|
465 |
+
"metric2": "number_of_product_clicks_on_plp",
|
466 |
+
"metric3": "number_of_product_clicks_on_pdp",
|
467 |
+
"metric4": "number_of_product_clicks_on_cart",
|
468 |
+
"metric5": "time_taken_to_add_to_cart",
|
469 |
+
"metric6": "time_taked_to_add_to_wishlist",
|
470 |
+
"metric7": "time_taken_to_make_the_purchase"
|
471 |
+
}
|
472 |
+
});
|
473 |
+
</script>';
|
474 |
+
}else if($this->ga_id){
|
475 |
+
echo '<script async src="https://www.googletagmanager.com/gtag/js?id='.esc_js($this->ga_id).'"></script>
|
476 |
+
<script>
|
477 |
+
window.dataLayer = window.dataLayer || [];
|
478 |
+
function gtag(){dataLayer.push(arguments);}
|
479 |
+
gtag("js", new Date());
|
480 |
+
gtag("config", "'.esc_js($this->ga_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$this->ga_Dname.'",
|
481 |
+
"custom_map": {
|
482 |
+
"dimension1": "user_id",
|
483 |
+
"dimension2": "client_id",
|
484 |
+
"dimension3": "user_type",
|
485 |
+
"dimension4": "page_type",
|
486 |
+
"dimension5": "day_type",
|
487 |
+
"dimension6": "local_time_slot_of_the_day",
|
488 |
+
"dimension7": "product_discount",
|
489 |
+
"dimension8": "stock_status",
|
490 |
+
"dimension9": "inventory",
|
491 |
+
"dimension10": "search_query_parameter",
|
492 |
+
"dimension11": "payment_method",
|
493 |
+
"dimension12": "shipping_tier",
|
494 |
+
"metric1": "number_of_product_clicks_on_home_page",
|
495 |
+
"metric2": "number_of_product_clicks_on_plp",
|
496 |
+
"metric3": "number_of_product_clicks_on_pdp",
|
497 |
+
"metric4": "number_of_product_clicks_on_cart",
|
498 |
+
"metric5": "time_taken_to_add_to_cart",
|
499 |
+
"metric6": "time_taked_to_add_to_wishlist",
|
500 |
+
"metric7": "time_taken_to_make_the_purchase"
|
501 |
+
}
|
502 |
+
});
|
503 |
+
</script>';
|
504 |
+
}
|
505 |
+
//add remarketing snippets
|
506 |
+
if($this->ads_tracking_id && ($this->ads_ert || $this->ads_edrt)){
|
507 |
+
$remarketing = unserialize(get_option('ee_remarketing_snippets'));
|
508 |
+
if(!empty($remarketing) && isset($remarketing['snippets']) && $remarketing['snippets']){
|
509 |
+
echo base64_decode($remarketing['snippets']);
|
510 |
+
}else{
|
511 |
+
$google_detail = $this->TVC_Admin_Helper->get_ee_options_data();
|
512 |
+
if(isset($google_detail['setting'])){
|
513 |
+
$googleDetail = $google_detail['setting'];
|
514 |
+
echo $googleDetail->google_ads_snippets;
|
515 |
+
}
|
516 |
+
}
|
517 |
+
}
|
518 |
+
}
|
519 |
+
|
520 |
+
/**
|
521 |
+
* Google Analytics eCommerce tracking
|
522 |
+
*
|
523 |
+
* @access public
|
524 |
+
* @param mixed $order_id
|
525 |
+
* @return void
|
526 |
+
*/
|
527 |
+
function ecommerce_tracking_code($order_id) {
|
528 |
+
global $woocommerce;
|
529 |
+
if ($this->disable_tracking($this->ga_eeT) || current_user_can("manage_options") || get_post_meta($order_id, "_tracked", true) == 1){
|
530 |
+
// return;
|
531 |
+
}
|
532 |
+
// Doing eCommerce tracking so unhook standard tracking from the footer
|
533 |
+
remove_action("wp_footer", array($this, "ee_settings"));
|
534 |
+
/*
|
535 |
+
* Get the order and output tracking code
|
536 |
+
* var tvc_oc
|
537 |
+
*/
|
538 |
+
$orderpage_prod_Array = array();
|
539 |
+
$order = new WC_Order($order_id);
|
540 |
+
//Get Applied Coupon Codes
|
541 |
+
$coupons_list = '';
|
542 |
+
if(version_compare($woocommerce->version, "3.7", ">")){
|
543 |
+
if ($order->get_coupon_codes()) {
|
544 |
+
//$coupons_count = count($order->get_coupon_codes());
|
545 |
+
foreach ($order->get_coupon_codes() as $coupon) {
|
546 |
+
$coupons_list .= ($coupons_list =="")?$coupon:", ".$coupon;
|
547 |
+
}
|
548 |
+
}
|
549 |
+
}else{
|
550 |
+
if ($order->get_used_coupons()) {
|
551 |
+
//$coupons_count = count($order->get_used_coupons());
|
552 |
+
foreach ($order->get_used_coupons() as $coupon) {
|
553 |
+
$coupons_list .= ($coupons_list =="")?$coupon:", ".$coupon;
|
554 |
+
}
|
555 |
+
}
|
556 |
+
}
|
557 |
+
// Order items
|
558 |
+
if ($order->get_items()) {
|
559 |
+
foreach ($order->get_items() as $item) {
|
560 |
+
$_product = $item->get_product();
|
561 |
+
$categories = ""; $attributes = ""; $p_weight = '';
|
562 |
+
|
563 |
+
$categories=get_the_terms($item['product_id'] , "product_cat");
|
564 |
+
$out = array();
|
565 |
+
if ($categories) {
|
566 |
+
foreach ($categories as $category) {
|
567 |
+
$out[] = $category->name;
|
568 |
+
}
|
569 |
+
}
|
570 |
+
$categories=esc_js(join(",", $out));
|
571 |
+
if($_product->product_type === "variation"){
|
572 |
+
$attributes=esc_js(wc_get_formatted_variation($_product->get_variation_attributes(), true));
|
573 |
+
if ($_product->variation_has_weight) {
|
574 |
+
//$p_weight = $_product->get_weight().' '.esc_attr(get_option('woocommerce_weight_unit'));
|
575 |
+
}
|
576 |
+
}elseif ($_product->product_type === 'simple') {
|
577 |
+
if ($_product->has_weight()) {
|
578 |
+
//$p_weight = $_product->get_weight().' '.esc_attr(get_option('woocommerce_weight_unit'));
|
579 |
+
}
|
580 |
+
}
|
581 |
+
if (version_compare($woocommerce->version, "2.7", "<")) {
|
582 |
+
$orderpage_prod_Array[get_permalink($_product->ID)]=array(
|
583 |
+
"tvc_id" => esc_html($_product->ID),
|
584 |
+
"tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->ID),
|
585 |
+
"tvc_n" => html_entity_decode($item["name"]),
|
586 |
+
"tvc_p" => esc_js($order->get_item_total($item)),
|
587 |
+
//"tvc_rp" => $_product->regular_price,
|
588 |
+
//"tvc_sp" => $_product->sale_price,
|
589 |
+
"tvc_pd" => $this->cal_prod_discount($_product->regular_price, $_product->sale_price),
|
590 |
+
"tvc_c" => $categories,
|
591 |
+
"tvc_attr" => $attributes,
|
592 |
+
"tvc_q"=>esc_js($item["qty"]),
|
593 |
+
//"tvc_wt" => $p_weight,
|
594 |
+
"tvc_var" => $this->getAttributesVariation($_product),
|
595 |
+
/*"tvc_di" => $_product->get_dimensions(), //dimensions
|
596 |
+
"tvc_ss" => $_product->is_in_stock(),
|
597 |
+
"tvc_st" => $_product->get_stock_quantity(),
|
598 |
+
"tvc_tst" => $_product->get_total_stock(),
|
599 |
+
"tvc_rc" => $_product->get_rating_count(),
|
600 |
+
"tvc_rs" => $_product->get_average_rating()*/
|
601 |
+
);
|
602 |
+
}else{
|
603 |
+
$orderpage_prod_Array[get_permalink($_product->get_id())]=array(
|
604 |
+
"tvc_id" => esc_html($_product->get_id()),
|
605 |
+
"tvc_i" => esc_js($_product->get_sku() ? $_product->get_sku() : $_product->get_id()),
|
606 |
+
"tvc_n" => $_product->get_title(),
|
607 |
+
"tvc_p" => esc_js($order->get_item_total($item)),
|
608 |
+
// "tvc_rp" => $_product->get_regular_price(),
|
609 |
+
// "tvc_sp" => $_product->get_sale_price(),
|
610 |
+
"tvc_pd" => $this->cal_prod_discount($_product->get_regular_price(), $_product->get_sale_price()),
|
611 |
+
"tvc_c" => $categories,
|
612 |
+
"tvc_attr" => $attributes,
|
613 |
+
"tvc_q"=>esc_js($item["qty"]),
|
614 |
+
//"tvc_wt" => $p_weight,
|
615 |
+
"tvc_var" => $this->getAttributesVariation($_product),
|
616 |
+
/*"tvc_di" => $_product->get_dimensions(), //dimensions
|
617 |
+
"tvc_ss" => $_product->is_in_stock(),
|
618 |
+
"tvc_st" => $_product->get_stock_quantity(),
|
619 |
+
"tvc_tst" => $_product->get_total_stock(),
|
620 |
+
"tvc_rc" => $_product->get_rating_count(),
|
621 |
+
"tvc_rs" => $_product->get_average_rating()*/
|
622 |
+
);
|
623 |
+
}
|
624 |
+
}
|
625 |
+
//make json for prod meta data on order page
|
626 |
+
$this->wc_version_compare("tvc_oc=" . json_encode($orderpage_prod_Array) . ";");
|
627 |
+
}
|
628 |
+
|
629 |
+
/*
|
630 |
+
* Get the trans data
|
631 |
+
* Var tvc_td
|
632 |
+
*/
|
633 |
+
//get shipping cost based on version >2.1 get_total_shipping() < get_shipping
|
634 |
+
$tvc_sc = "";
|
635 |
+
if (version_compare($woocommerce->version, "2.1", ">=")) {
|
636 |
+
$tvc_sc = $order->get_total_shipping();
|
637 |
+
} else {
|
638 |
+
$tvc_sc = $order->get_shipping();
|
639 |
+
}
|
640 |
+
$user_bill_addr="";
|
641 |
+
$user_ship_addr="";
|
642 |
+
if(isset($this->tvc_options["user_id"]) && $this->tvc_options["user_id"]!="" ){
|
643 |
+
$user_bill_addr = get_user_meta($t_user_id->ID, 'shipping_city', true);
|
644 |
+
$user_ship_addr = get_user_meta($t_user_id->ID, 'billing_city', true);
|
645 |
+
}
|
646 |
+
//orderpage transcation data json
|
647 |
+
$orderpage_trans_Array=array(
|
648 |
+
"id"=> esc_js($order->get_order_number()), // Transaction ID. Required
|
649 |
+
"affiliation"=>esc_js(get_bloginfo('name')), // Affiliation or store name
|
650 |
+
"revenue"=>esc_js($order->get_total()), // Grand Total
|
651 |
+
"tax"=> esc_js($order->get_total_tax()), // Tax
|
652 |
+
"shipping"=> esc_js($tvc_sc), // Shipping
|
653 |
+
"coupon"=>$coupons_list,
|
654 |
+
"total_discount"=>esc_js($order->get_total_discount()),
|
655 |
+
"user_bill_addr"=>$user_bill_addr,
|
656 |
+
"user_ship_addr"=>$user_ship_addr,
|
657 |
+
"user_type"=>$this->tvc_options["user_type"],
|
658 |
+
"payment_method"=>$order->get_payment_method()
|
659 |
+
);
|
660 |
+
$this->wc_version_compare("tvc_td=" . json_encode($orderpage_trans_Array) . ";");
|
661 |
+
?>
|
662 |
+
<script>
|
663 |
+
window.addEventListener('load', call_thnkyou_page,true);
|
664 |
+
function call_thnkyou_page(){
|
665 |
+
tvc_js = new TVC_Enhanced(<?php echo json_encode($this->tvc_options); ?>);
|
666 |
+
tvc_js.thnkyou_page(<?php echo json_encode($orderpage_prod_Array); ?>, <?php echo json_encode($orderpage_trans_Array); ?>, "+<?php echo $order->get_status(); ?>+", <?php echo time(); ?>);
|
667 |
+
/*let script = document.createElement('script');
|
668 |
+
script.addEventListener('load', (event) => {
|
669 |
+
let tvc_js = new TVC_Enhanced(<?php echo json_encode($tvc_options); ?>);
|
670 |
+
});
|
671 |
+
script.src = "<?php echo ENHANCAD_PLUGIN_URL.'/public/js/tvc-ee-google-analytics.js'; ?>";
|
672 |
+
document.getElementsByTagName('head')[0].appendChild(script);*/
|
673 |
+
}
|
674 |
+
</script>
|
675 |
+
<?php
|
676 |
+
update_post_meta($order_id, "_tracked", 1);
|
677 |
+
}
|
678 |
+
|
679 |
+
/**
|
680 |
+
* Enhanced E-commerce tracking for single product add to cart
|
681 |
+
*
|
682 |
+
* @access public
|
683 |
+
* @return void
|
684 |
+
*/
|
685 |
+
function add_to_cart() {
|
686 |
+
if ($this->disable_tracking($this->ga_eeT))
|
687 |
+
return;
|
688 |
+
//return if not product page
|
689 |
+
if (!is_single())
|
690 |
+
return;
|
691 |
+
?>
|
692 |
+
<script>
|
693 |
+
window.addEventListener('load', call_tvc_enhanced,true);
|
694 |
+
function call_tvc_enhanced(){
|
695 |
+
tvc_js = new TVC_Enhanced(<?php echo json_encode($this->tvc_options); ?>);
|
696 |
+
tvc_js.addToCartEventBindings();
|
697 |
+
}
|
698 |
+
</script>
|
699 |
+
<?php
|
700 |
+
}
|
701 |
+
|
702 |
+
/**
|
703 |
+
* Enhanced E-commerce tracking for product detail view
|
704 |
+
*
|
705 |
+
* @access public
|
706 |
+
* @return void
|
707 |
+
*/
|
708 |
+
public function product_detail_view() {
|
709 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
710 |
+
return;
|
711 |
+
}
|
712 |
+
global $product,$woocommerce;
|
713 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
714 |
+
$category = get_the_terms($product->ID, "product_cat");
|
715 |
+
}else{
|
716 |
+
$category = get_the_terms($product->get_id(), "product_cat");
|
717 |
+
}
|
718 |
+
$categories = "";
|
719 |
+
if ($category) {
|
720 |
+
foreach ($category as $term) {
|
721 |
+
$categories.=$term->name . ",";
|
722 |
+
}
|
723 |
+
}
|
724 |
+
//remove last comma(,) if multiple categories are there
|
725 |
+
$categories = rtrim($categories, ",");
|
726 |
+
//product detail view json
|
727 |
+
$prodpage_detail_json = array();
|
728 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
729 |
+
$prodpage_detail_json = array(
|
730 |
+
"tvc_id" => esc_html($product->id),
|
731 |
+
"tvc_i" => $product->get_sku() ? $product->get_sku() : $product->id,
|
732 |
+
"tvc_n" => $product->get_title(),
|
733 |
+
"tvc_c" => $categories,
|
734 |
+
"tvc_p" => $product->get_price(),
|
735 |
+
"tvc_pd" => $this->cal_prod_discount($product->regular_price, $product->sale_price),
|
736 |
+
"tvc_ps" => $product->get_stock_status(),
|
737 |
+
"tvc_tst" => $product->get_total_stock(),
|
738 |
+
"tvc_q" => esc_html($product->get_stock_quantity()),
|
739 |
+
"tvc_var" => $this->getAttributesVariation($product),
|
740 |
+
"is_featured" => $product->is_featured(),
|
741 |
+
"is_onSale" => $product->is_on_sale()
|
742 |
+
);
|
743 |
+
}else{
|
744 |
+
$prodpage_detail_json = array(
|
745 |
+
"tvc_id" => esc_html($product->get_id()),
|
746 |
+
"tvc_i" => $product->get_sku() ? $product->get_sku() : $product->get_id(),
|
747 |
+
"tvc_n" => $product->get_title(),
|
748 |
+
"tvc_c" => $categories,
|
749 |
+
"tvc_p" => $product->get_price(),
|
750 |
+
"tvc_pd" => $this->cal_prod_discount($product->regular_price, $product->sale_price),
|
751 |
+
"tvc_ps" => $product->get_stock_status(),
|
752 |
+
"tvc_tst" => $product->get_total_stock(),
|
753 |
+
"tvc_q" => esc_html($product->get_stock_quantity()),
|
754 |
+
"tvc_var" => $this->getAttributesVariation($product),
|
755 |
+
"is_featured" => $product->is_featured(),
|
756 |
+
"is_onSale" => $product->is_on_sale()
|
757 |
+
);
|
758 |
+
}
|
759 |
+
//prod page detail view json
|
760 |
+
$this->wc_version_compare("tvc_po=" . json_encode($prodpage_detail_json) . ";");
|
761 |
+
?>
|
762 |
+
<script>
|
763 |
+
window.addEventListener('load', call_view_item_pdp,true);
|
764 |
+
function call_view_item_pdp(){
|
765 |
+
tvc_js = new TVC_Enhanced(<?php echo json_encode($this->tvc_options); ?>);
|
766 |
+
tvc_js.view_item_pdp();
|
767 |
+
}
|
768 |
+
</script>
|
769 |
+
<?php
|
770 |
+
/*if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
|
771 |
+
$code = '
|
772 |
+
gtag("event", "view_item", {
|
773 |
+
"event_category":"Enhanced-Ecommerce",
|
774 |
+
"event_label":"product_impression_pp",
|
775 |
+
"items": [
|
776 |
+
{
|
777 |
+
"id": tvc_po.tvc_i,// Product details are provided in an impressionFieldObject.
|
778 |
+
"name": tvc_po.tvc_n,
|
779 |
+
"category":tvc_po.tvc_c,
|
780 |
+
}
|
781 |
+
],
|
782 |
+
"non_interaction": true
|
783 |
+
})
|
784 |
+
//add remarketing and dynamicremarketing tags
|
785 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
786 |
+
gtag("event","view_item", {
|
787 |
+
"value": tvc_po.tvc_p,
|
788 |
+
"items": [
|
789 |
+
{
|
790 |
+
"id": tvc_po.tvc_id,
|
791 |
+
"google_business_vertical": "retail"
|
792 |
+
}
|
793 |
+
]
|
794 |
+
});
|
795 |
+
}
|
796 |
+
';
|
797 |
+
//check woocommerce version
|
798 |
+
if(is_product()){
|
799 |
+
$this->wc_version_compare($code);
|
800 |
+
}
|
801 |
+
}
|
802 |
+
|
803 |
+
if( $this->gm_id && $this->tracking_option == "GA4") {
|
804 |
+
$code = '
|
805 |
+
gtag("event", "view_item", {
|
806 |
+
"event_category":"Enhanced-Ecommerce",
|
807 |
+
"event_label":"product_impression_pp",
|
808 |
+
"currency": tvc_lc,
|
809 |
+
"items": [
|
810 |
+
{
|
811 |
+
"item_id": tvc_po.tvc_i,
|
812 |
+
"item_name": tvc_po.tvc_n,
|
813 |
+
"item_category":tvc_po.tvc_c,
|
814 |
+
}
|
815 |
+
],
|
816 |
+
"non_interaction": true
|
817 |
+
})
|
818 |
+
//add remarketing and dynamicremarketing tags
|
819 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
820 |
+
gtag("event","view_item", {
|
821 |
+
"value": tvc_po.tvc_p,
|
822 |
+
"items": [
|
823 |
+
{
|
824 |
+
"id": tvc_po.tvc_id,
|
825 |
+
"google_business_vertical": "retail"
|
826 |
+
}
|
827 |
+
]
|
828 |
+
});
|
829 |
+
}
|
830 |
+
';
|
831 |
+
//check woocommerce version
|
832 |
+
if (is_product()) {
|
833 |
+
$this->wc_version_compare($code);
|
834 |
+
}
|
835 |
+
}*/
|
836 |
+
}
|
837 |
+
|
838 |
+
/**
|
839 |
+
* Enhanced E-commerce tracking for product impressions on category pages (hidden fields) , product page (related section)
|
840 |
+
* home page (featured section and recent section)
|
841 |
+
*
|
842 |
+
* @access public
|
843 |
+
* @return void
|
844 |
+
*/
|
845 |
+
public function bind_product_metadata() {
|
846 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
847 |
+
return;
|
848 |
+
}
|
849 |
+
|
850 |
+
global $product,$woocommerce;
|
851 |
+
if (version_compare($woocommerce->version, "2.7", "<")) {
|
852 |
+
$category = get_the_terms($product->Id, "product_cat");
|
853 |
+
} else {
|
854 |
+
$category = get_the_terms($product->get_id(), "product_cat");
|
855 |
+
}
|
856 |
+
|
857 |
+
$categories = "";
|
858 |
+
|
859 |
+
if ($category) {
|
860 |
+
foreach ($category as $term) {
|
861 |
+
$categories.=$term->name . ",";
|
862 |
+
}
|
863 |
+
}
|
864 |
+
//remove last comma(,) if multiple categories are there
|
865 |
+
$categories = rtrim($categories, ",");
|
866 |
+
//declare all variable as a global which will used for make json
|
867 |
+
global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
|
868 |
+
//is home page then make all necessory json
|
869 |
+
if (is_home() || is_front_page()) {
|
870 |
+
if (!is_array($homepage_json_fp) && !is_array($homepage_json_rp) && !is_array($homepage_json_ATC_link)) {
|
871 |
+
$homepage_json_fp = array();
|
872 |
+
$homepage_json_rp = array();
|
873 |
+
$homepage_json_ATC_link=array();
|
874 |
+
}
|
875 |
+
|
876 |
+
// ATC link Array
|
877 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
878 |
+
$homepage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
879 |
+
}else{
|
880 |
+
$homepage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->get_id()));
|
881 |
+
}
|
882 |
+
//check if product is featured product or not
|
883 |
+
if ($product->is_featured()) {
|
884 |
+
//check if product is already exists in homepage featured json
|
885 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
886 |
+
if(!array_key_exists(get_permalink($product->id),$homepage_json_fp)){
|
887 |
+
$homepage_json_fp[get_permalink($product->id)] = array(
|
888 |
+
"tvc_id" => esc_html($product->id),
|
889 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
890 |
+
"tvc_n" => esc_html($product->get_title()),
|
891 |
+
"tvc_p" => esc_html($product->get_price()),
|
892 |
+
"tvc_c" => esc_html($categories),
|
893 |
+
"ATC-link"=>$product->add_to_cart_url()
|
894 |
+
);
|
895 |
+
//else add product in homepage recent product json
|
896 |
+
}else {
|
897 |
+
$homepage_json_rp[get_permalink($product->id)] =array(
|
898 |
+
"tvc_id" => esc_html($product->id),
|
899 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
900 |
+
"tvc_n" => esc_html($product->get_title()),
|
901 |
+
"tvc_p" => esc_html($product->get_price()),
|
902 |
+
"tvc_c" => esc_html($categories)
|
903 |
+
);
|
904 |
+
}
|
905 |
+
}else{
|
906 |
+
if(!array_key_exists(get_permalink($product->get_id()),$homepage_json_fp)){
|
907 |
+
$homepage_json_fp[get_permalink($product->get_id())] = array(
|
908 |
+
"tvc_id" => esc_html($product->get_id()),
|
909 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
910 |
+
"tvc_n" => esc_html($product->get_title()),
|
911 |
+
"tvc_p" => esc_html($product->get_price()),
|
912 |
+
"tvc_c" => esc_html($categories),
|
913 |
+
"ATC-link"=>$product->add_to_cart_url()
|
914 |
+
);
|
915 |
+
//else add product in homepage recent product json
|
916 |
+
}else {
|
917 |
+
$homepage_json_rp[get_permalink($product->get_id())] =array(
|
918 |
+
"tvc_id" => esc_html($product->get_id()),
|
919 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
920 |
+
"tvc_n" => esc_html($product->get_title()),
|
921 |
+
"tvc_p" => esc_html($product->get_price()),
|
922 |
+
"tvc_c" => esc_html($categories)
|
923 |
+
);
|
924 |
+
}
|
925 |
+
}
|
926 |
+
|
927 |
+
} else {
|
928 |
+
//else prod add in homepage recent json
|
929 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
930 |
+
$homepage_json_rp[get_permalink($product->id)] =array(
|
931 |
+
"tvc_id" => esc_html($product->id),
|
932 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
933 |
+
"tvc_n" => esc_html($product->get_title()),
|
934 |
+
"tvc_p" => esc_html($product->get_price()),
|
935 |
+
"tvc_c" => esc_html($categories)
|
936 |
+
);
|
937 |
+
}else{
|
938 |
+
$homepage_json_rp[get_permalink($product->get_id())] =array(
|
939 |
+
"tvc_id" => esc_html($product->get_id()),
|
940 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
941 |
+
"tvc_n" => esc_html($product->get_title()),
|
942 |
+
"tvc_p" => esc_html($product->get_price()),
|
943 |
+
"tvc_c" => esc_html($categories)
|
944 |
+
);
|
945 |
+
}
|
946 |
+
|
947 |
+
}
|
948 |
+
}
|
949 |
+
//if product page then related product page array
|
950 |
+
else if(is_product()){
|
951 |
+
if(!is_array($prodpage_json_relProd) && !is_array($prodpage_json_ATC_link)){
|
952 |
+
$prodpage_json_relProd = array();
|
953 |
+
$prodpage_json_ATC_link = array();
|
954 |
+
}
|
955 |
+
// ATC link Array
|
956 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
957 |
+
$prodpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
958 |
+
|
959 |
+
$prodpage_json_relProd[get_permalink($product->id)] = array(
|
960 |
+
"tvc_id" => esc_html($product->id),
|
961 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
962 |
+
"tvc_n" => esc_html($product->get_title()),
|
963 |
+
"tvc_p" => esc_html($product->get_price()),
|
964 |
+
"tvc_c" => esc_html($categories),
|
965 |
+
);
|
966 |
+
}else{
|
967 |
+
$prodpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->get_id()));
|
968 |
+
|
969 |
+
$prodpage_json_relProd[get_permalink($product->get_id())] = array(
|
970 |
+
"tvc_id" => esc_html($product->get_id()),
|
971 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
972 |
+
"tvc_n" => esc_html($product->get_title()),
|
973 |
+
"tvc_p" => esc_html($product->get_price()),
|
974 |
+
"tvc_c" => esc_html($categories)
|
975 |
+
|
976 |
+
);
|
977 |
+
}
|
978 |
+
}
|
979 |
+
//category page, search page and shop page json
|
980 |
+
else if (is_product_category() || is_search() || is_shop()) {
|
981 |
+
if (!is_array($catpage_json) && !is_array($catpage_json_ATC_link)){
|
982 |
+
$catpage_json=array();
|
983 |
+
$catpage_json_ATC_link=array();
|
984 |
+
}
|
985 |
+
//cat page ATC array
|
986 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
987 |
+
$catpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->id));
|
988 |
+
|
989 |
+
$catpage_json[get_permalink($product->id)] =array(
|
990 |
+
"tvc_id" => esc_html($product->id),
|
991 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->id),
|
992 |
+
"tvc_n" => esc_html($product->get_title()),
|
993 |
+
"tvc_p" => esc_html($product->get_price()),
|
994 |
+
"tvc_c" => esc_html($categories),
|
995 |
+
);
|
996 |
+
}else{
|
997 |
+
$catpage_json_ATC_link[$product->add_to_cart_url()]=array("ATC-link"=>get_permalink($product->get_id()));
|
998 |
+
|
999 |
+
$catpage_json[get_permalink($product->get_id())] =array(
|
1000 |
+
"tvc_id" => esc_html($product->get_id()),
|
1001 |
+
"tvc_i" => esc_html($product->get_sku() ? $product->get_sku() : $product->get_id()),
|
1002 |
+
"tvc_n" => esc_html($product->get_title()),
|
1003 |
+
"tvc_p" => esc_html($product->get_price()),
|
1004 |
+
"tvc_c" => esc_html($categories)
|
1005 |
+
|
1006 |
+
);
|
1007 |
+
}
|
1008 |
+
}
|
1009 |
+
}
|
1010 |
+
|
1011 |
+
/**
|
1012 |
+
* Enhanced E-commerce tracking for product impressions,clicks on Home pages
|
1013 |
+
*
|
1014 |
+
* @access public
|
1015 |
+
* @return void
|
1016 |
+
*/
|
1017 |
+
function t_products_impre_clicks() {
|
1018 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
1019 |
+
return;
|
1020 |
+
}
|
1021 |
+
|
1022 |
+
//get impression threshold
|
1023 |
+
$impression_threshold = $this->ga_imTh;
|
1024 |
+
|
1025 |
+
//Product impression on Home Page
|
1026 |
+
global $homepage_json_fp,$homepage_json_ATC_link, $homepage_json_rp,$prodpage_json_relProd,$catpage_json,$prodpage_json_ATC_link,$catpage_json_ATC_link;
|
1027 |
+
//home page json for featured products and recent product sections
|
1028 |
+
//check if php array is empty
|
1029 |
+
if(empty($homepage_json_ATC_link)){
|
1030 |
+
$homepage_json_ATC_link=array(); //define empty array so if empty then in json will be []
|
1031 |
+
}
|
1032 |
+
if(empty($homepage_json_fp)){
|
1033 |
+
$homepage_json_fp=array(); //define empty array so if empty then in json will be []
|
1034 |
+
}
|
1035 |
+
if(empty($homepage_json_rp)){ //home page recent product array
|
1036 |
+
$homepage_json_rp=array();
|
1037 |
+
}
|
1038 |
+
if(empty($prodpage_json_relProd)){ //prod page related section array
|
1039 |
+
$prodpage_json_relProd=array();
|
1040 |
+
}
|
1041 |
+
if(empty($prodpage_json_ATC_link)){
|
1042 |
+
$prodpage_json_ATC_link=array(); //prod page ATC link json
|
1043 |
+
}
|
1044 |
+
if(empty($catpage_json)){ //category page array
|
1045 |
+
$catpage_json=array();
|
1046 |
+
}
|
1047 |
+
if(empty($catpage_json_ATC_link)){ //category page array
|
1048 |
+
$catpage_json_ATC_link=array();
|
1049 |
+
}
|
1050 |
+
//home page json
|
1051 |
+
$this->wc_version_compare("homepage_json_ATC_link=" . json_encode($homepage_json_ATC_link) . ";");
|
1052 |
+
$this->wc_version_compare("tvc_fp=" . json_encode($homepage_json_fp) . ";");
|
1053 |
+
$this->wc_version_compare("tvc_rcp=" . json_encode($homepage_json_rp) . ";");
|
1054 |
+
//product page json
|
1055 |
+
$this->wc_version_compare("tvc_rdp=" . json_encode($prodpage_json_relProd) . ";");
|
1056 |
+
$this->wc_version_compare("prodpage_json_ATC_link=" . json_encode($prodpage_json_ATC_link) . ";");
|
1057 |
+
//category page json
|
1058 |
+
$this->wc_version_compare("tvc_pgc=" . json_encode($catpage_json) . ";");
|
1059 |
+
$this->wc_version_compare("catpage_json_ATC_link=" . json_encode($catpage_json_ATC_link) . ";");
|
1060 |
+
if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
|
1061 |
+
$hmpg_impressions_jQ = '
|
1062 |
+
var items = [];
|
1063 |
+
//set local currencies
|
1064 |
+
gtag("set", {"currency": tvc_lc});
|
1065 |
+
function t_products_impre_clicks(t_json_name,t_action){
|
1066 |
+
t_send_threshold=0;
|
1067 |
+
t_prod_pos=0;
|
1068 |
+
t_json_length=Object.keys(t_json_name).length;
|
1069 |
+
|
1070 |
+
for(var t_item in t_json_name) {
|
1071 |
+
t_send_threshold++;
|
1072 |
+
t_prod_pos++;
|
1073 |
+
items.push({
|
1074 |
+
"id": t_json_name[t_item].tvc_i,
|
1075 |
+
"name": t_json_name[t_item].tvc_n,
|
1076 |
+
"category": t_json_name[t_item].tvc_c,
|
1077 |
+
"price": t_json_name[t_item].tvc_p,
|
1078 |
+
});
|
1079 |
+
|
1080 |
+
if(t_json_length > ' . esc_js($impression_threshold) .' ){
|
1081 |
+
|
1082 |
+
if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
|
1083 |
+
t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
|
1084 |
+
gtag("event", "view_item_list", { "event_category":"Enhanced-Ecommerce",
|
1085 |
+
"event_label":"product_impression_"+t_action, "items":items,"non_interaction": true});
|
1086 |
+
items = [];
|
1087 |
+
}
|
1088 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
1089 |
+
gtag("event","view_item_list", {
|
1090 |
+
"value": t_json_name[t_item].tvc_p,
|
1091 |
+
"items": [
|
1092 |
+
{
|
1093 |
+
"id": t_json_name[t_item].tvc_id,
|
1094 |
+
"google_business_vertical": "retail"
|
1095 |
+
}
|
1096 |
+
]
|
1097 |
+
});
|
1098 |
+
}
|
1099 |
+
}else{
|
1100 |
+
|
1101 |
+
t_json_length--;
|
1102 |
+
if(t_json_length==0){
|
1103 |
+
gtag("event", "view_item_list", { "event_category":"Enhanced-Ecommerce",
|
1104 |
+
"event_label":"product_impression_"+t_action, "items":items,"non_interaction": true});
|
1105 |
+
items = [];
|
1106 |
+
}
|
1107 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
1108 |
+
gtag("event","view_item_list", {
|
1109 |
+
"value": t_json_name[t_item].tvc_p,
|
1110 |
+
"items": [
|
1111 |
+
{
|
1112 |
+
"id": t_json_name[t_item].tvc_id,
|
1113 |
+
"google_business_vertical": "retail"
|
1114 |
+
}
|
1115 |
+
]
|
1116 |
+
});
|
1117 |
+
}
|
1118 |
+
}
|
1119 |
+
}
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
//function for comparing urls in json object
|
1123 |
+
function prod_exists_in_JSON(t_url,t_json_name,t_action){
|
1124 |
+
if(t_json_name.hasOwnProperty(t_url)){
|
1125 |
+
t_call_fired=true;
|
1126 |
+
gtag("event", "select_content", {
|
1127 |
+
"event_category":"Enhanced-Ecommerce",
|
1128 |
+
"event_label":"product_click_"+t_action,
|
1129 |
+
"content_type": "product",
|
1130 |
+
"items": [
|
1131 |
+
{
|
1132 |
+
"id":t_json_name[t_url].tvc_i,
|
1133 |
+
"name": t_json_name[t_url].tvc_n,
|
1134 |
+
"category":t_json_name[t_url].tvc_c,
|
1135 |
+
"price": t_json_name[t_url].tvc_p,
|
1136 |
+
}
|
1137 |
+
],
|
1138 |
+
"non_interaction": true
|
1139 |
+
});
|
1140 |
+
}else{
|
1141 |
+
t_call_fired=false;
|
1142 |
+
}
|
1143 |
+
return t_call_fired;
|
1144 |
+
}
|
1145 |
+
function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
|
1146 |
+
t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
|
1147 |
+
|
1148 |
+
if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
|
1149 |
+
t_call_fired=true;
|
1150 |
+
// Enhanced E-commerce Add to cart clicks
|
1151 |
+
gtag("event", "add_to_cart", {
|
1152 |
+
"event_category":"Enhanced-Ecommerce",
|
1153 |
+
"event_label":"add_to_cart_click",
|
1154 |
+
"non_interaction": true,
|
1155 |
+
"items": [{
|
1156 |
+
"id" : t_prod_data_json[t_prod_url_key].tvc_i,
|
1157 |
+
"name":t_prod_data_json[t_prod_url_key].tvc_n,
|
1158 |
+
"category" : t_prod_data_json[t_prod_url_key].tvc_c,
|
1159 |
+
"price": t_prod_data_json[t_prod_url_key].tvc_p,
|
1160 |
+
"quantity" :t_qty
|
1161 |
+
}]
|
1162 |
+
});
|
1163 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
1164 |
+
gtag("event","add_to_cart", {
|
1165 |
+
"value": t_prod_data_json[t_prod_url_key].tvc_p,
|
1166 |
+
"items": [
|
1167 |
+
{
|
1168 |
+
"id": t_prod_data_json[t_prod_url_key].tvc_id,
|
1169 |
+
"google_business_vertical": "retail"
|
1170 |
+
}
|
1171 |
+
]
|
1172 |
+
});
|
1173 |
+
}
|
1174 |
+
|
1175 |
+
}else{
|
1176 |
+
t_call_fired=false;
|
1177 |
+
}
|
1178 |
+
return t_call_fired;
|
1179 |
+
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
';
|
1183 |
+
}
|
1184 |
+
if($this->gm_id && $this->tracking_option == "GA4") {
|
1185 |
+
$hmpg_impressions_jQ = '
|
1186 |
+
var items = [];
|
1187 |
+
function t_products_impre_clicks(t_json_name,t_action){
|
1188 |
+
t_send_threshold=0;
|
1189 |
+
t_prod_pos=0;
|
1190 |
+
t_json_length=Object.keys(t_json_name).length;
|
1191 |
+
for(var t_item in t_json_name) {
|
1192 |
+
t_send_threshold++;
|
1193 |
+
t_prod_pos++;
|
1194 |
+
items.push({
|
1195 |
+
"item_id": t_json_name[t_item].tvc_i,
|
1196 |
+
"item_name": t_json_name[t_item].tvc_n,
|
1197 |
+
"item_category": t_json_name[t_item].tvc_c,
|
1198 |
+
"price": t_json_name[t_item].tvc_p,
|
1199 |
+
"currency": tvc_lc
|
1200 |
+
});
|
1201 |
+
if(t_json_length > ' . esc_js($impression_threshold) . ' ){
|
1202 |
+
if((t_send_threshold%' . esc_js($impression_threshold) . ')==0){
|
1203 |
+
t_json_length=t_json_length-' . esc_js($impression_threshold) . ';
|
1204 |
+
gtag("event", "view_item_list", {
|
1205 |
+
"event_category":"Enhanced-Ecommerce",
|
1206 |
+
"event_label":"product_impression_"+t_action,
|
1207 |
+
"items":items,
|
1208 |
+
"non_interaction": true
|
1209 |
+
});
|
1210 |
+
items = [];
|
1211 |
+
}
|
1212 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
1213 |
+
gtag("event","view_item_list", {
|
1214 |
+
"value": t_json_name[t_item].tvc_p,
|
1215 |
+
"items": [
|
1216 |
+
{
|
1217 |
+
"id": t_json_name[t_item].tvc_id,
|
1218 |
+
"google_business_vertical": "retail"
|
1219 |
+
}
|
1220 |
+
]
|
1221 |
+
});
|
1222 |
+
}
|
1223 |
+
}else{
|
1224 |
+
t_json_length--;
|
1225 |
+
if(t_json_length==0){
|
1226 |
+
gtag("event", "view_item_list", {
|
1227 |
+
"event_category":"Enhanced-Ecommerce",
|
1228 |
+
"event_label":"product_impression_"+t_action,
|
1229 |
+
"items":items,
|
1230 |
+
"non_interaction": true
|
1231 |
+
});
|
1232 |
+
items = [];
|
1233 |
+
}
|
1234 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
1235 |
+
gtag("event","view_item_list", {
|
1236 |
+
"value": t_json_name[t_item].tvc_p,
|
1237 |
+
"items": [
|
1238 |
+
{
|
1239 |
+
"id": t_json_name[t_item].tvc_id,
|
1240 |
+
"google_business_vertical": "retail"
|
1241 |
+
}
|
1242 |
+
]
|
1243 |
+
});
|
1244 |
+
}
|
1245 |
+
}
|
1246 |
+
}
|
1247 |
+
}
|
1248 |
+
|
1249 |
+
//function for comparing urls in json object
|
1250 |
+
function prod_exists_in_JSON(t_url,t_json_name,t_action){
|
1251 |
+
if(t_json_name.hasOwnProperty(t_url)){
|
1252 |
+
t_call_fired=true;
|
1253 |
+
gtag("event", "select_item", {
|
1254 |
+
"event_category":"Enhanced-Ecommerce",
|
1255 |
+
"event_label":"product_click_"+t_action,
|
1256 |
+
"items": [
|
1257 |
+
{
|
1258 |
+
"item_id":t_json_name[t_url].tvc_i,
|
1259 |
+
"item_name": t_json_name[t_url].tvc_n,
|
1260 |
+
"item_category":t_json_name[t_url].tvc_c,
|
1261 |
+
"price": t_json_name[t_url].tvc_p,
|
1262 |
+
"currency": tvc_lc
|
1263 |
+
}
|
1264 |
+
],
|
1265 |
+
"non_interaction": true
|
1266 |
+
});
|
1267 |
+
|
1268 |
+
}else{
|
1269 |
+
t_call_fired=false;
|
1270 |
+
}
|
1271 |
+
return t_call_fired;
|
1272 |
+
}
|
1273 |
+
function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
|
1274 |
+
t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
|
1275 |
+
if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
|
1276 |
+
t_call_fired=true;
|
1277 |
+
// Enhanced E-commerce Add to cart clicks
|
1278 |
+
gtag("event", "add_to_cart", {
|
1279 |
+
"event_category":"Enhanced-Ecommerce",
|
1280 |
+
"event_label":"add_to_cart_click",
|
1281 |
+
"non_interaction": true,
|
1282 |
+
"items": [{
|
1283 |
+
"item_id" : t_prod_data_json[t_prod_url_key].tvc_i,
|
1284 |
+
"item_name":t_prod_data_json[t_prod_url_key].tvc_n,
|
1285 |
+
"item_category" : t_prod_data_json[t_prod_url_key].tvc_c,
|
1286 |
+
"price": t_prod_data_json[t_prod_url_key].tvc_p,
|
1287 |
+
"currency": tvc_lc,
|
1288 |
+
"quantity" :t_qty
|
1289 |
+
}]
|
1290 |
+
});
|
1291 |
+
|
1292 |
+
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
1293 |
+
gtag("event","add_to_cart", {
|
1294 |
+
"value": t_prod_data_json[t_prod_url_key].tvc_p,
|
1295 |
+
"items": [
|
1296 |
+
{
|
1297 |
+
"id": t_prod_data_json[t_prod_url_key].tvc_id,
|
1298 |
+
"google_business_vertical": "retail"
|
1299 |
+
}
|
1300 |
+
]
|
1301 |
+
});
|
1302 |
+
}
|
1303 |
+
}else{
|
1304 |
+
t_call_fired=false;
|
1305 |
+
}
|
1306 |
+
return t_call_fired;
|
1307 |
+
}
|
1308 |
+
';
|
1309 |
+
}
|
1310 |
+
if(is_home() || is_front_page()){
|
1311 |
+
$hmpg_impressions_jQ .='
|
1312 |
+
if(tvc_fp.length !== 0){
|
1313 |
+
t_products_impre_clicks(tvc_fp,"fp");
|
1314 |
+
}
|
1315 |
+
if(tvc_rcp.length !== 0){
|
1316 |
+
t_products_impre_clicks(tvc_rcp,"rp");
|
1317 |
+
}
|
1318 |
+
jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
|
1319 |
+
t_url=jQuery(this).attr("href");
|
1320 |
+
//home page call for click
|
1321 |
+
t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"fp");
|
1322 |
+
if(!t_call_fired){
|
1323 |
+
prod_exists_in_JSON(t_url,tvc_rcp,"rp");
|
1324 |
+
}
|
1325 |
+
});
|
1326 |
+
//ATC click
|
1327 |
+
jQuery("a[href*=add-to-cart]").on("click",function(){
|
1328 |
+
t_url=jQuery(this).attr("href");
|
1329 |
+
t_qty=$(this).parent().find("input[name=quantity]").val();
|
1330 |
+
//default quantity 1 if quantity box is not there
|
1331 |
+
if(t_qty=="" || t_qty===undefined){
|
1332 |
+
t_qty="1";
|
1333 |
+
}
|
1334 |
+
t_call_fired=prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_fp,t_qty);
|
1335 |
+
if(!t_call_fired){
|
1336 |
+
prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_rcp,t_qty);
|
1337 |
+
}
|
1338 |
+
});
|
1339 |
+
|
1340 |
+
';
|
1341 |
+
}else if(is_search()){
|
1342 |
+
$hmpg_impressions_jQ .='
|
1343 |
+
//search page json
|
1344 |
+
if(tvc_pgc.length !== 0){
|
1345 |
+
t_products_impre_clicks(tvc_pgc,"srch");
|
1346 |
+
}
|
1347 |
+
//search page prod click
|
1348 |
+
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
1349 |
+
t_url=jQuery(this).attr("href");
|
1350 |
+
//cat page prod call for click
|
1351 |
+
prod_exists_in_JSON(t_url,tvc_pgc,"srch");
|
1352 |
+
});
|
1353 |
+
|
1354 |
+
';
|
1355 |
+
}else if (is_product()) {
|
1356 |
+
//product page releted products
|
1357 |
+
$hmpg_impressions_jQ .='
|
1358 |
+
if(tvc_rdp.length !== 0){
|
1359 |
+
t_products_impre_clicks(tvc_rdp,"rdp");
|
1360 |
+
}
|
1361 |
+
//product click - image and product name
|
1362 |
+
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
1363 |
+
t_url=jQuery(this).attr("href");
|
1364 |
+
//prod page related call for click
|
1365 |
+
prod_exists_in_JSON(t_url,tvc_rdp,"rdp");
|
1366 |
+
});
|
1367 |
+
//Prod ATC link click in related product section
|
1368 |
+
jQuery("a[href*=add-to-cart]").on("click",function(){
|
1369 |
+
t_url=jQuery(this).attr("href");
|
1370 |
+
t_qty=$(this).parent().find("input[name=quantity]").val();
|
1371 |
+
//default quantity 1 if quantity box is not there
|
1372 |
+
if(t_qty=="" || t_qty===undefined){
|
1373 |
+
t_qty="1";
|
1374 |
+
}
|
1375 |
+
prod_ATC_link_exists(t_url,prodpage_json_ATC_link,tvc_rdp,t_qty);
|
1376 |
+
});
|
1377 |
+
';
|
1378 |
+
}else if (is_product_category()) {
|
1379 |
+
$hmpg_impressions_jQ .='
|
1380 |
+
//category page json
|
1381 |
+
if(tvc_pgc.length !== 0){
|
1382 |
+
t_products_impre_clicks(tvc_pgc,"cp");
|
1383 |
+
}
|
1384 |
+
//Prod category ATC link click in related product section
|
1385 |
+
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
1386 |
+
t_url=jQuery(this).attr("href");
|
1387 |
+
//cat page prod call for click
|
1388 |
+
prod_exists_in_JSON(t_url,tvc_pgc,"cp");
|
1389 |
+
});
|
1390 |
+
|
1391 |
+
';
|
1392 |
+
}else if(is_shop()){
|
1393 |
+
$hmpg_impressions_jQ .='
|
1394 |
+
//shop page json
|
1395 |
+
if(tvc_pgc.length !== 0){
|
1396 |
+
t_products_impre_clicks(tvc_pgc,"sp");
|
1397 |
+
}
|
1398 |
+
//shop page prod click
|
1399 |
+
jQuery("a:not(.product_type_variable, .product_type_grouped)").on("click",function(){
|
1400 |
+
t_url=jQuery(this).attr("href");
|
1401 |
+
//cat page prod call for click
|
1402 |
+
prod_exists_in_JSON(t_url,tvc_pgc,"sp");
|
1403 |
+
});
|
1404 |
+
|
1405 |
+
|
1406 |
+
';
|
1407 |
+
}
|
1408 |
+
//common ATC link for Category page , Shop Page and Search Page
|
1409 |
+
if(is_product_category() || is_shop() || is_search()){
|
1410 |
+
$hmpg_impressions_jQ .='
|
1411 |
+
//ATC link click
|
1412 |
+
jQuery("a[href*=add-to-cart]").on("click",function(){
|
1413 |
+
t_url=jQuery(this).attr("href");
|
1414 |
+
t_qty=$(this).parent().find("input[name=quantity]").val();
|
1415 |
+
//default quantity 1 if quantity box is not there
|
1416 |
+
if(t_qty=="" || t_qty===undefined){
|
1417 |
+
t_qty="1";
|
1418 |
+
}
|
1419 |
+
prod_ATC_link_exists(t_url,catpage_json_ATC_link,tvc_pgc,t_qty);
|
1420 |
+
});
|
1421 |
+
';
|
1422 |
+
}
|
1423 |
+
//on home page, product page , category page
|
1424 |
+
if (is_home() || is_front_page() || is_product() || is_product_category() || is_search() || is_shop()){
|
1425 |
+
$this->wc_version_compare($hmpg_impressions_jQ);
|
1426 |
+
}
|
1427 |
+
}
|
1428 |
+
|
1429 |
+
/**
|
1430 |
+
* Enhanced E-commerce tracking for remove from cart
|
1431 |
+
*
|
1432 |
+
* @access public
|
1433 |
+
* @return void
|
1434 |
+
*/
|
1435 |
+
public function remove_cart_tracking() {
|
1436 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
1437 |
+
return;
|
1438 |
+
}
|
1439 |
+
global $woocommerce;
|
1440 |
+
$cartpage_prod_array_main = array();
|
1441 |
+
foreach ($woocommerce->cart->cart_contents as $key => $item) {
|
1442 |
+
//Version compare
|
1443 |
+
if (version_compare($woocommerce->version, "2.7", "<")) {
|
1444 |
+
$prod_meta = get_product($item["product_id"]);
|
1445 |
+
} else {
|
1446 |
+
$prod_meta = wc_get_product($item["product_id"]);
|
1447 |
+
}
|
1448 |
+
if (version_compare($woocommerce->version, "3.3", "<")) {
|
1449 |
+
$cart_remove_link=html_entity_decode($woocommerce->cart->get_remove_url($key));
|
1450 |
+
} else {
|
1451 |
+
$cart_remove_link=html_entity_decode(wc_get_cart_remove_url($key));
|
1452 |
+
}
|
1453 |
+
$category = get_the_terms($item["product_id"], "product_cat");
|
1454 |
+
$categories = "";
|
1455 |
+
if ($category) {
|
1456 |
+
foreach ($category as $term) {
|
1457 |
+
$categories.=$term->name . ",";
|
1458 |
+
}
|
1459 |
+
}
|
1460 |
+
//remove last comma(,) if multiple categories are there
|
1461 |
+
$categories = rtrim($categories, ",");
|
1462 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
1463 |
+
$cartpage_prod_array_main[$cart_remove_link] =array(
|
1464 |
+
"tvc_id" => esc_html($prod_meta->ID),
|
1465 |
+
"tvc_i" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->ID),
|
1466 |
+
"tvc_n" => html_entity_decode($prod_meta->get_title()),
|
1467 |
+
"tvc_p" => esc_html($prod_meta->get_price()),
|
1468 |
+
"tvc_c" => esc_html($categories),
|
1469 |
+
"tvc_q"=>$woocommerce->cart->cart_contents[$key]["quantity"]
|
1470 |
+
);
|
1471 |
+
}else{
|
1472 |
+
$cartpage_prod_array_main[$cart_remove_link] =array(
|
1473 |
+
"tvc_id" => esc_html($prod_meta->get_id()),
|
1474 |
+
"tvc_i" => esc_html($prod_meta->get_sku() ? $prod_meta->get_sku() : $prod_meta->get_id()),
|
1475 |
+
"tvc_n" => html_entity_decode($prod_meta->get_title()),
|
1476 |
+
"tvc_p" => esc_html($prod_meta->get_price()),
|
1477 |
+
"tvc_c" => esc_html($categories),
|
1478 |
+
"tvc_q"=>$woocommerce->cart->cart_contents[$key]["quantity"]
|
1479 |
+
);
|
1480 |
+
}
|
1481 |
+
}
|
1482 |
+
|
1483 |
+
//Cart Page item Array to Json
|
1484 |
+
$this->wc_version_compare("tvc_cc=" . json_encode($cartpage_prod_array_main) . ";");
|
1485 |
+
if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
|
1486 |
+
$code = '
|
1487 |
+
//set local currencies
|
1488 |
+
gtag("set", {"currency": tvc_lc});
|
1489 |
+
$("a[href*=\"?remove_item\"]").click(function(){
|
1490 |
+
t_url=jQuery(this).attr("href");
|
1491 |
+
gtag("event", "remove_from_cart", {
|
1492 |
+
"event_category":"Enhanced-Ecommerce",
|
1493 |
+
"event_label":"remove_from_cart_click",
|
1494 |
+
"items": [{
|
1495 |
+
"id":tvc_cc[t_url].tvc_i,
|
1496 |
+
"name": tvc_cc[t_url].tvc_n,
|
1497 |
+
"category":tvc_cc[t_url].tvc_c,
|
1498 |
+
"price": tvc_cc[t_url].tvc_p,
|
1499 |
+
"quantity": tvc_cc[t_url].tvc_q
|
1500 |
+
}],
|
1501 |
+
"non_interaction": true
|
1502 |
+
});
|
1503 |
+
});
|
1504 |
+
|
1505 |
+
';
|
1506 |
+
//check woocommerce version
|
1507 |
+
$this->wc_version_compare($code);
|
1508 |
+
}
|
1509 |
+
|
1510 |
+
if($this->gm_id && $this->tracking_option == "GA4") {
|
1511 |
+
$code = '
|
1512 |
+
$("a[href*=\"?remove_item\"]").click(function(){
|
1513 |
+
t_url=jQuery(this).attr("href");
|
1514 |
+
gtag("event", "remove_from_cart", {
|
1515 |
+
"event_category":"Enhanced-Ecommerce",
|
1516 |
+
"event_label":"remove_from_cart_click",
|
1517 |
+
"currency": tvc_lc,
|
1518 |
+
"items": [{
|
1519 |
+
"item_id":tvc_cc[t_url].tvc_i,
|
1520 |
+
"item_name": tvc_cc[t_url].tvc_n,
|
1521 |
+
"item_category":tvc_cc[t_url].tvc_c,
|
1522 |
+
"price": tvc_cc[t_url].tvc_p,
|
1523 |
+
"currency": tvc_lc,
|
1524 |
+
"quantity": tvc_cc[t_url].tvc_q
|
1525 |
+
}],
|
1526 |
+
"non_interaction": true
|
1527 |
+
});
|
1528 |
+
});
|
1529 |
+
|
1530 |
+
';
|
1531 |
+
//check woocommerce version
|
1532 |
+
$this->wc_version_compare($code);
|
1533 |
+
}
|
1534 |
+
}
|
1535 |
+
|
1536 |
+
/**
|
1537 |
+
* Enhanced E-commerce tracking checkout step 1
|
1538 |
+
*
|
1539 |
+
* @access public
|
1540 |
+
* @return void
|
1541 |
+
*/
|
1542 |
+
public function checkout_step_1_tracking() {
|
1543 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
1544 |
+
return;
|
1545 |
+
}
|
1546 |
+
//call fn to make json
|
1547 |
+
$this->get_ordered_items();
|
1548 |
+
if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH") {
|
1549 |
+
$code= '
|
1550 |
+
var items = [];
|
1551 |
+
gtag("set", {"currency": tvc_lc});
|
1552 |
+
for(var t_item in tvc_ch){
|
1553 |
+
items.push({
|
1554 |
+
"id": tvc_ch[t_item].tvc_i,
|
1555 |
+
"name": tvc_ch[t_item].tvc_n,
|
1556 |
+
"category": tvc_ch[t_item].tvc_c,
|
1557 |
+
"attributes": tvc_ch[t_item].tvc_attr,
|
1558 |
+
"price": tvc_ch[t_item].tvc_p,
|
1559 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1560 |
+
});
|
1561 |
+
}';
|
1562 |
+
|
1563 |
+
$code_step_1 = $code . 'gtag("event", "begin_checkout", {"event_category":"Enhanced-Ecommerce",
|
1564 |
+
"event_label":"checkout_step_1","items":items,"non_interaction": true });';
|
1565 |
+
|
1566 |
+
//check woocommerce version and add code
|
1567 |
+
$this->wc_version_compare($code_step_1);
|
1568 |
+
}
|
1569 |
+
|
1570 |
+
if( $this->gm_id && $this->tracking_option == "GA4") {
|
1571 |
+
$code = '
|
1572 |
+
var items = [];
|
1573 |
+
for(var t_item in tvc_ch){
|
1574 |
+
items.push({
|
1575 |
+
"item_id": tvc_ch[t_item].tvc_i,
|
1576 |
+
"item_name": tvc_ch[t_item].tvc_n,
|
1577 |
+
"item_category": tvc_ch[t_item].tvc_c,
|
1578 |
+
"item_variant": tvc_ch[t_item].tvc_attr,
|
1579 |
+
"price": tvc_ch[t_item].tvc_p,
|
1580 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1581 |
+
});
|
1582 |
+
}';
|
1583 |
+
|
1584 |
+
$code_step_1 = $code . 'gtag("event", "begin_checkout", {
|
1585 |
+
"event_category":"Enhanced-Ecommerce",
|
1586 |
+
"event_label":"checkout_step_1",
|
1587 |
+
"items":items,
|
1588 |
+
"non_interaction": true
|
1589 |
+
});';
|
1590 |
+
|
1591 |
+
//check woocommerce version and add code
|
1592 |
+
$this->wc_version_compare($code_step_1);
|
1593 |
+
}
|
1594 |
+
}
|
1595 |
+
|
1596 |
+
/**
|
1597 |
+
* Enhanced E-commerce tracking checkout step 2
|
1598 |
+
*
|
1599 |
+
* @access public
|
1600 |
+
* @return void
|
1601 |
+
*/
|
1602 |
+
public function checkout_step_2_tracking() {
|
1603 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
1604 |
+
return;
|
1605 |
+
}
|
1606 |
+
if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
|
1607 |
+
$code= '
|
1608 |
+
var items = [];
|
1609 |
+
gtag("set", {"currency": tvc_lc});
|
1610 |
+
for(var t_item in tvc_ch){
|
1611 |
+
items.push({
|
1612 |
+
"id": tvc_ch[t_item].tvc_i,
|
1613 |
+
"name": tvc_ch[t_item].tvc_n,
|
1614 |
+
"category": tvc_ch[t_item].tvc_c,
|
1615 |
+
"attributes": tvc_ch[t_item].tvc_attr,
|
1616 |
+
"price": tvc_ch[t_item].tvc_p,
|
1617 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1618 |
+
});
|
1619 |
+
}';
|
1620 |
+
|
1621 |
+
$code_step_2 = $code . 'gtag("event", "checkout_progress", {"checkout_step": 2,"event_category":"Enhanced-Ecommerce",
|
1622 |
+
"event_label":"checkout_step_2","items":items,"non_interaction": true });';
|
1623 |
+
|
1624 |
+
//if logged in and first name is filled - Guest Check out
|
1625 |
+
if (is_user_logged_in()) {
|
1626 |
+
$step2_onFocus = 't_tracked_focus=0; if(t_tracked_focus===0){' . $code_step_2 . ' t_tracked_focus++;}';
|
1627 |
+
} else {
|
1628 |
+
//first name on focus call fire
|
1629 |
+
$step2_onFocus = 't_tracked_focus=0; jQuery("input[name=billing_first_name]").on("focus",function(){ if(t_tracked_focus===0){' . $code_step_2 . ' t_tracked_focus++;}});';
|
1630 |
+
}
|
1631 |
+
//check woocommerce version and add code
|
1632 |
+
$this->wc_version_compare($step2_onFocus);
|
1633 |
+
}
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
/**
|
1637 |
+
* Enhanced E-commerce tracking checkout step 3
|
1638 |
+
*
|
1639 |
+
* @access public
|
1640 |
+
* @return void
|
1641 |
+
*/
|
1642 |
+
public function checkout_step_3_tracking() {
|
1643 |
+
|
1644 |
+
if ($this->disable_tracking($this->ga_eeT)) {
|
1645 |
+
return;
|
1646 |
+
}
|
1647 |
+
if($this->ga_id || $this->tracking_option == "UA" || $this->tracking_option == "BOTH" || $this->gm_id) {
|
1648 |
+
$code= '
|
1649 |
+
var items = [];
|
1650 |
+
for(var t_item in tvc_ch){
|
1651 |
+
items.push({
|
1652 |
+
"id": tvc_ch[t_item].tvc_i,
|
1653 |
+
"name": tvc_ch[t_item].tvc_n,
|
1654 |
+
"category": tvc_ch[t_item].tvc_c,
|
1655 |
+
"attributes": tvc_ch[t_item].tvc_attr,
|
1656 |
+
"price": tvc_ch[t_item].tvc_p,
|
1657 |
+
"quantity": tvc_ch[t_item].tvc_q
|
1658 |
+
});
|
1659 |
+
}';
|
1660 |
+
|
1661 |
+
//check if guest check out is enabled or not
|
1662 |
+
$step_2_on_proceed_to_pay = (!is_user_logged_in() && !$this->ga_gCkout ) || (!is_user_logged_in() && $this->ga_gCkout && $this->ga_gUser);
|
1663 |
+
|
1664 |
+
$code_step_3 = $code . 'gtag("event", "checkout_progress", {"checkout_step": 3,"event_category":"Enhanced-Ecommerce",
|
1665 |
+
"event_label":"checkout_step_3","items":items,"non_interaction": true });';
|
1666 |
+
|
1667 |
+
$inline_js = 't_track_clk=0; jQuery(document).on("click","#place_order",function(e){ if(t_track_clk===0){';
|
1668 |
+
if ($step_2_on_proceed_to_pay) {
|
1669 |
+
if (isset($code_step_2))
|
1670 |
+
$inline_js .= $code_step_2;
|
1671 |
+
}
|
1672 |
+
$inline_js .= $code_step_3;
|
1673 |
+
$inline_js .= "t_track_clk++; }});";
|
1674 |
+
|
1675 |
+
//check woocommerce version and add code
|
1676 |
+
$this->wc_version_compare($inline_js);
|
1677 |
+
}
|
1678 |
+
}
|
1679 |
+
|
1680 |
+
/**
|
1681 |
+
* Get oredered Items for check out page.
|
1682 |
+
*
|
1683 |
+
* @access public
|
1684 |
+
* @return void
|
1685 |
+
*/
|
1686 |
+
public function get_ordered_items() {
|
1687 |
+
global $woocommerce;
|
1688 |
+
$code = "";
|
1689 |
+
//get all items added into the cart
|
1690 |
+
foreach ($woocommerce->cart->cart_contents as $item) {
|
1691 |
+
//Version Compare
|
1692 |
+
if ( version_compare($woocommerce->version, "2.7", "<")) {
|
1693 |
+
$p = get_product($item["product_id"]);
|
1694 |
+
} else {
|
1695 |
+
$p = wc_get_product($item["product_id"]);
|
1696 |
+
}
|
1697 |
+
|
1698 |
+
$category = get_the_terms($item["product_id"], "product_cat");
|
1699 |
+
$categories = "";
|
1700 |
+
if ($category) {
|
1701 |
+
foreach ($category as $term) {
|
1702 |
+
$categories.=$term->name . ",";
|
1703 |
+
}
|
1704 |
+
}
|
1705 |
+
//remove last comma(,) if multiple categories are there
|
1706 |
+
$categories = rtrim($categories, ",");
|
1707 |
+
if(version_compare($woocommerce->version, "2.7", "<")){
|
1708 |
+
$chkout_json[get_permalink($p->ID)] = array(
|
1709 |
+
"tvc_id" => esc_html($p->ID),
|
1710 |
+
"tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->ID),
|
1711 |
+
"tvc_n" => html_entity_decode($p->get_title()),
|
1712 |
+
"tvc_p" => esc_js($p->get_price()),
|
1713 |
+
"tvc_c" => $categories,
|
1714 |
+
"tvc_q" => esc_js($item["quantity"]),
|
1715 |
+
"isfeatured"=>$p->is_featured()
|
1716 |
+
);
|
1717 |
+
}else{
|
1718 |
+
$chkout_json[get_permalink($p->get_id())] = array(
|
1719 |
+
"tvc_id" => esc_html($p->get_id()),
|
1720 |
+
"tvc_i" => esc_js($p->get_sku() ? $p->get_sku() : $p->get_id()),
|
1721 |
+
"tvc_n" => html_entity_decode($p->get_title()),
|
1722 |
+
"tvc_p" => esc_js($p->get_price()),
|
1723 |
+
"tvc_c" => $categories,
|
1724 |
+
"tvc_q" => esc_js($item["quantity"]),
|
1725 |
+
"isfeatured"=>$p->is_featured()
|
1726 |
+
);
|
1727 |
+
}
|
1728 |
+
}
|
1729 |
+
//return $code;
|
1730 |
+
//make product data json on check out page
|
1731 |
+
$this->wc_version_compare("tvc_ch=" . json_encode($chkout_json) . ";");
|
1732 |
+
}
|
1733 |
+
|
1734 |
+
|
1735 |
+
|
1736 |
+
}
|
public/class-enhanced-ecommerce-google-analytics-public.php
CHANGED
@@ -103,7 +103,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
103 |
protected $ads_ert;
|
104 |
protected $ads_edrt;
|
105 |
protected $ads_tracking_id;
|
106 |
-
|
107 |
/**
|
108 |
* Enhanced_Ecommerce_Google_Analytics_Public constructor.
|
109 |
* @param $plugin_name
|
@@ -111,7 +111,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
111 |
*/
|
112 |
|
113 |
public function __construct($plugin_name, $version) {
|
114 |
-
|
115 |
$this->plugin_name = $plugin_name;
|
116 |
$this->version = $version;
|
117 |
$this->tvc_aga = $this->get_option("tvc_aga");
|
@@ -177,8 +177,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
177 |
function tvc_store_meta_data() {
|
178 |
//only on home page
|
179 |
global $woocommerce;
|
180 |
-
$
|
181 |
-
$google_detail = $TVC_Admin_Helper->get_ee_options_data();
|
182 |
$sub_data = array();
|
183 |
if(isset($google_detail['setting'])){
|
184 |
$googleDetail = $google_detail['setting'];
|
@@ -218,6 +217,14 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
218 |
);
|
219 |
$this->wc_version_compare("tvc_smd=" . json_encode($tvc_sMetaData) . ";");
|
220 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
/**
|
223 |
* add dev id
|
@@ -338,9 +345,6 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
338 |
function gtag(){dataLayer.push(arguments);}
|
339 |
gtag("js", new Date());
|
340 |
gtag("config", "'.esc_js($tracking_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$set_domain_name.'"});
|
341 |
-
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
342 |
-
gtag("config", "AW-' . esc_js($this->ads_tracking_id) . '");
|
343 |
-
}
|
344 |
</script>
|
345 |
';
|
346 |
//echo $code;
|
@@ -353,9 +357,6 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
353 |
function gtag(){dataLayer.push(arguments);}
|
354 |
gtag("js", new Date());
|
355 |
gtag("config", "'.esc_js($measurment_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$set_domain_name.'"});
|
356 |
-
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
357 |
-
gtag("config", "AW-' . esc_js($this->ads_tracking_id) . '");
|
358 |
-
}
|
359 |
</script>
|
360 |
';
|
361 |
|
@@ -368,12 +369,21 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
368 |
gtag("js", new Date());
|
369 |
gtag("config", "'.esc_js($measurment_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$set_domain_name.'"});
|
370 |
gtag("config", "'.esc_js($tracking_id).'");
|
371 |
-
if(adsTringId != "" && ( ads_ert == 1 || ads_edrt == 1)){
|
372 |
-
gtag("config", "AW-' . esc_js($this->ads_tracking_id) . '");
|
373 |
-
}
|
374 |
</script>
|
375 |
';
|
376 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
}
|
378 |
|
379 |
/**
|
@@ -546,7 +556,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
546 |
for(var t_item in tvc_oc){
|
547 |
ads_value=ads_value + parseFloat(tvc_oc[t_item].tvc_p);
|
548 |
ads_items.push({
|
549 |
-
item_id: tvc_oc[t_item].
|
550 |
google_business_vertical: "retail"
|
551 |
});
|
552 |
}
|
@@ -599,7 +609,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
599 |
for(var t_item in tvc_oc){
|
600 |
ads_value=ads_value + parseFloat(tvc_oc[t_item].tvc_p);
|
601 |
ads_items.push({
|
602 |
-
item_id: tvc_oc[t_item].
|
603 |
google_business_vertical: "retail"
|
604 |
});
|
605 |
}
|
@@ -668,7 +678,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
668 |
"value": tvc_po.tvc_p,
|
669 |
"items": [
|
670 |
{
|
671 |
-
"id": tvc_po.
|
672 |
"google_business_vertical": "retail"
|
673 |
}
|
674 |
]
|
@@ -704,7 +714,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
704 |
"value": tvc_po.tvc_p,
|
705 |
"items": [
|
706 |
{
|
707 |
-
"id": tvc_po.
|
708 |
"google_business_vertical": "retail"
|
709 |
}
|
710 |
]
|
@@ -787,7 +797,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
787 |
"value": tvc_po.tvc_p,
|
788 |
"items": [
|
789 |
{
|
790 |
-
"id": tvc_po.
|
791 |
"google_business_vertical": "retail"
|
792 |
}
|
793 |
]
|
@@ -821,7 +831,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
821 |
"value": tvc_po.tvc_p,
|
822 |
"items": [
|
823 |
{
|
824 |
-
"id": tvc_po.
|
825 |
"google_business_vertical": "retail"
|
826 |
}
|
827 |
]
|
@@ -1090,7 +1100,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
1090 |
"value": t_json_name[t_item].tvc_p,
|
1091 |
"items": [
|
1092 |
{
|
1093 |
-
"id": t_json_name[t_item].
|
1094 |
"google_business_vertical": "retail"
|
1095 |
}
|
1096 |
]
|
@@ -1109,7 +1119,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
1109 |
"value": t_json_name[t_item].tvc_p,
|
1110 |
"items": [
|
1111 |
{
|
1112 |
-
"id": t_json_name[t_item].
|
1113 |
"google_business_vertical": "retail"
|
1114 |
}
|
1115 |
]
|
@@ -1165,7 +1175,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
1165 |
"value": t_prod_data_json[t_prod_url_key].tvc_p,
|
1166 |
"items": [
|
1167 |
{
|
1168 |
-
"id": t_prod_data_json[t_prod_url_key].
|
1169 |
"google_business_vertical": "retail"
|
1170 |
}
|
1171 |
]
|
@@ -1214,7 +1224,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
1214 |
"value": t_json_name[t_item].tvc_p,
|
1215 |
"items": [
|
1216 |
{
|
1217 |
-
"id": t_json_name[t_item].
|
1218 |
"google_business_vertical": "retail"
|
1219 |
}
|
1220 |
]
|
@@ -1236,7 +1246,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
1236 |
"value": t_json_name[t_item].tvc_p,
|
1237 |
"items": [
|
1238 |
{
|
1239 |
-
"id": t_json_name[t_item].
|
1240 |
"google_business_vertical": "retail"
|
1241 |
}
|
1242 |
]
|
@@ -1294,7 +1304,7 @@ class Enhanced_Ecommerce_Google_Analytics_Public {
|
|
1294 |
"value": t_prod_data_json[t_prod_url_key].tvc_p,
|
1295 |
"items": [
|
1296 |
{
|
1297 |
-
"id": t_prod_data_json[t_prod_url_key].
|
1298 |
"google_business_vertical": "retail"
|
1299 |
}
|
1300 |
]
|
103 |
protected $ads_ert;
|
104 |
protected $ads_edrt;
|
105 |
protected $ads_tracking_id;
|
106 |
+
protected $TVC_Admin_Helper;
|
107 |
/**
|
108 |
* Enhanced_Ecommerce_Google_Analytics_Public constructor.
|
109 |
* @param $plugin_name
|
111 |
*/
|
112 |
|
113 |
public function __construct($plugin_name, $version) {
|
114 |
+
$this->TVC_Admin_Helper = new TVC_Admin_Helper();
|
115 |
$this->plugin_name = $plugin_name;
|
116 |
$this->version = $version;
|
117 |
$this->tvc_aga = $this->get_option("tvc_aga");
|
177 |
function tvc_store_meta_data() {
|
178 |
//only on home page
|
179 |
global $woocommerce;
|
180 |
+
$google_detail = $this->TVC_Admin_Helper->get_ee_options_data();
|
|
|
181 |
$sub_data = array();
|
182 |
if(isset($google_detail['setting'])){
|
183 |
$googleDetail = $google_detail['setting'];
|
217 |
);
|
218 |
$this->wc_version_compare("tvc_smd=" . json_encode($tvc_sMetaData) . ";");
|
219 |
}
|
220 |
+
/**
|
221 |
+
* Register the JavaScript for the public-facing side of the site.
|
222 |
+
*
|
223 |
+
* @since4.0.0
|
224 |
+
*/
|
225 |
+
public function enqueue_scripts() {
|
226 |
+
//wp_enqueue_script($this->plugin_name, ENHANCAD_PLUGIN_URL . '/public/js/tvc-ee-google-analytics.js', array('jquery'), $this->version, false);
|
227 |
+
}
|
228 |
|
229 |
/**
|
230 |
* add dev id
|
345 |
function gtag(){dataLayer.push(arguments);}
|
346 |
gtag("js", new Date());
|
347 |
gtag("config", "'.esc_js($tracking_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$set_domain_name.'"});
|
|
|
|
|
|
|
348 |
</script>
|
349 |
';
|
350 |
//echo $code;
|
357 |
function gtag(){dataLayer.push(arguments);}
|
358 |
gtag("js", new Date());
|
359 |
gtag("config", "'.esc_js($measurment_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$set_domain_name.'"});
|
|
|
|
|
|
|
360 |
</script>
|
361 |
';
|
362 |
|
369 |
gtag("js", new Date());
|
370 |
gtag("config", "'.esc_js($measurment_id).'",{'.$ga_ip_anonymization.' "cookie_domain":"'.$set_domain_name.'"});
|
371 |
gtag("config", "'.esc_js($tracking_id).'");
|
|
|
|
|
|
|
372 |
</script>
|
373 |
';
|
374 |
}
|
375 |
+
if($this->ads_ert || $this->ads_edrt){
|
376 |
+
$remarketing = unserialize(get_option('ee_remarketing_snippets'));
|
377 |
+
if(!empty($remarketing) && isset($remarketing['snippets']) && $remarketing['snippets']){
|
378 |
+
echo base64_decode($remarketing['snippets']);
|
379 |
+
}else{
|
380 |
+
$google_detail = $this->TVC_Admin_Helper->get_ee_options_data();
|
381 |
+
if(isset($google_detail['setting'])){
|
382 |
+
$googleDetail = $google_detail['setting'];
|
383 |
+
echo $googleDetail->google_ads_snippets;
|
384 |
+
}
|
385 |
+
}
|
386 |
+
}
|
387 |
}
|
388 |
|
389 |
/**
|
556 |
for(var t_item in tvc_oc){
|
557 |
ads_value=ads_value + parseFloat(tvc_oc[t_item].tvc_p);
|
558 |
ads_items.push({
|
559 |
+
item_id: tvc_oc[t_item].tvc_id,
|
560 |
google_business_vertical: "retail"
|
561 |
});
|
562 |
}
|
609 |
for(var t_item in tvc_oc){
|
610 |
ads_value=ads_value + parseFloat(tvc_oc[t_item].tvc_p);
|
611 |
ads_items.push({
|
612 |
+
item_id: tvc_oc[t_item].tvc_id,
|
613 |
google_business_vertical: "retail"
|
614 |
});
|
615 |
}
|
678 |
"value": tvc_po.tvc_p,
|
679 |
"items": [
|
680 |
{
|
681 |
+
"id": tvc_po.tvc_id,
|
682 |
"google_business_vertical": "retail"
|
683 |
}
|
684 |
]
|
714 |
"value": tvc_po.tvc_p,
|
715 |
"items": [
|
716 |
{
|
717 |
+
"id": tvc_po.tvc_id,
|
718 |
"google_business_vertical": "retail"
|
719 |
}
|
720 |
]
|
797 |
"value": tvc_po.tvc_p,
|
798 |
"items": [
|
799 |
{
|
800 |
+
"id": tvc_po.tvc_id,
|
801 |
"google_business_vertical": "retail"
|
802 |
}
|
803 |
]
|
831 |
"value": tvc_po.tvc_p,
|
832 |
"items": [
|
833 |
{
|
834 |
+
"id": tvc_po.tvc_id,
|
835 |
"google_business_vertical": "retail"
|
836 |
}
|
837 |
]
|
1100 |
"value": t_json_name[t_item].tvc_p,
|
1101 |
"items": [
|
1102 |
{
|
1103 |
+
"id": t_json_name[t_item].tvc_id,
|
1104 |
"google_business_vertical": "retail"
|
1105 |
}
|
1106 |
]
|
1119 |
"value": t_json_name[t_item].tvc_p,
|
1120 |
"items": [
|
1121 |
{
|
1122 |
+
"id": t_json_name[t_item].tvc_id,
|
1123 |
"google_business_vertical": "retail"
|
1124 |
}
|
1125 |
]
|
1175 |
"value": t_prod_data_json[t_prod_url_key].tvc_p,
|
1176 |
"items": [
|
1177 |
{
|
1178 |
+
"id": t_prod_data_json[t_prod_url_key].tvc_id,
|
1179 |
"google_business_vertical": "retail"
|
1180 |
}
|
1181 |
]
|
1224 |
"value": t_json_name[t_item].tvc_p,
|
1225 |
"items": [
|
1226 |
{
|
1227 |
+
"id": t_json_name[t_item].tvc_id,
|
1228 |
"google_business_vertical": "retail"
|
1229 |
}
|
1230 |
]
|
1246 |
"value": t_json_name[t_item].tvc_p,
|
1247 |
"items": [
|
1248 |
{
|
1249 |
+
"id": t_json_name[t_item].tvc_id,
|
1250 |
"google_business_vertical": "retail"
|
1251 |
}
|
1252 |
]
|
1304 |
"value": t_prod_data_json[t_prod_url_key].tvc_p,
|
1305 |
"items": [
|
1306 |
{
|
1307 |
+
"id": t_prod_data_json[t_prod_url_key].tvc_id,
|
1308 |
"google_business_vertical": "retail"
|
1309 |
}
|
1310 |
]
|
public/js/tvc-ee-google-analytics.js
ADDED
@@ -0,0 +1,512 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function( $ ) {
|
2 |
+
'use strict';
|
3 |
+
/**
|
4 |
+
* This enables you to define handlers, for when the DOM is ready:
|
5 |
+
* $(function() { });
|
6 |
+
* When the window is loaded:
|
7 |
+
* $( window ).load(function() { });
|
8 |
+
*/
|
9 |
+
})( jQuery );
|
10 |
+
class TVC_Enhanced {
|
11 |
+
constructor(options = {}){
|
12 |
+
/*"is_admin"=>is_admin(),
|
13 |
+
"tracking_option"=>$this->tracking_option,
|
14 |
+
"property_id"=>$this->ga_id,
|
15 |
+
"measurement_id"=>$this->gm_id,
|
16 |
+
"google_ads_id"=>$this->google_ads_id,
|
17 |
+
"google_merchant_center_id"=>$this->google_merchant_id,
|
18 |
+
"o_add_gtag_snippet"=>$this->ga_ST,
|
19 |
+
"o_enhanced_e_commerce_tracking"=>$this->ga_eeT,
|
20 |
+
"o_log_step_gest_user"=>$this->ga_gUser,
|
21 |
+
"o_impression_thresold"=>$this->ga_imTh,
|
22 |
+
"o_ip_anonymization"=>$this->ga_IPA,
|
23 |
+
"o_ga_OPTOUT"=>$this->ga_OPTOUT,
|
24 |
+
"ads_tracking_id"=>$this->ads_tracking_id,
|
25 |
+
"remarketing_tags"=>$this->ads_ert,
|
26 |
+
"dynamic_remarketing_tags"=>$this->ads_edrt*/
|
27 |
+
this.options = {
|
28 |
+
tracking_option: 'UA'
|
29 |
+
};
|
30 |
+
if(options){
|
31 |
+
Object.assign(this.options, options);
|
32 |
+
}
|
33 |
+
console.log(this.options);
|
34 |
+
//this.addEventBindings();
|
35 |
+
}
|
36 |
+
addToCartEventBindings(){
|
37 |
+
// alert("call first");
|
38 |
+
var single_btn = document.getElementsByClassName("single_add_to_cart_button");
|
39 |
+
if(single_btn.length > 0){
|
40 |
+
single_btn[0].addEventListener("click", () => this.add_to_cart_click());
|
41 |
+
}
|
42 |
+
}
|
43 |
+
/*
|
44 |
+
* check remarketing option
|
45 |
+
*/
|
46 |
+
is_add_remarketing_tags(){
|
47 |
+
if(this.options.is_admin == false && this.options.ads_tracking_id != "" && ( this.options.remarketing_tags == 1 || this.options.dynamic_remarketing_tags == 1)){
|
48 |
+
return true;
|
49 |
+
}else{
|
50 |
+
return false;
|
51 |
+
}
|
52 |
+
}
|
53 |
+
/*
|
54 |
+
* check remarketing option
|
55 |
+
*/
|
56 |
+
view_item_pdp(){
|
57 |
+
if(this.options.is_admin == true){
|
58 |
+
return;
|
59 |
+
}
|
60 |
+
//this.options.page_type="Product Page";
|
61 |
+
/*
|
62 |
+
* Start UA or GA4
|
63 |
+
*/
|
64 |
+
if((this.options.tracking_option =="UA" || this.options.tracking_option == "BOTH") && this.options.property_id ){
|
65 |
+
try {
|
66 |
+
gtag("event", "view_item", {
|
67 |
+
"event_category":"Enhanced-Ecommerce",
|
68 |
+
"event_label":"view_item_"+tvc_po.tvc_n,
|
69 |
+
"items": [{
|
70 |
+
"id": tvc_po.tvc_i,// Product details are provided in an impressionFieldObject.
|
71 |
+
"name": tvc_po.tvc_n,
|
72 |
+
"category":tvc_po.tvc_c,
|
73 |
+
"variant": tvc_po.tvc_var,
|
74 |
+
"list_name": this.options.page_type,
|
75 |
+
"list_position": 1,
|
76 |
+
"quantity": tvc_po.tvc_q,
|
77 |
+
"price": tvc_po.tvc_p
|
78 |
+
}],
|
79 |
+
"non_interaction": true,
|
80 |
+
"page_type": this.options.page_type,
|
81 |
+
"user_type": this.options.user_type,
|
82 |
+
"user_id": this.options.user_id,
|
83 |
+
"client_id":this.getClientId(),
|
84 |
+
"day_type": this.options.day_type,
|
85 |
+
"local_time_slot_of_the_day": this.options.local_time
|
86 |
+
});
|
87 |
+
|
88 |
+
}catch(err){
|
89 |
+
gtag("event", "exception", {
|
90 |
+
"description": err,
|
91 |
+
"fatal": false
|
92 |
+
});
|
93 |
+
}
|
94 |
+
/*
|
95 |
+
* Start GA4
|
96 |
+
*/
|
97 |
+
}else if( this.options.tracking_option == "GA4" && this.options.measurement_id ){
|
98 |
+
try {
|
99 |
+
gtag("event", "view_item", {
|
100 |
+
"event_category":"Enhanced-Ecommerce",
|
101 |
+
"event_label":"view_item_"+tvc_po.tvc_n,
|
102 |
+
"currency": tvc_lc,
|
103 |
+
"items": [{
|
104 |
+
"item_id": tvc_po.tvc_i,
|
105 |
+
"item_name": tvc_po.tvc_n,
|
106 |
+
"item_category":tvc_po.tvc_c,
|
107 |
+
"discount": tvc_po.tvc_pd,
|
108 |
+
"affiliation":this.options.affiliation,
|
109 |
+
"item_variant": tvc_po.tvc_var,
|
110 |
+
"price": tvc_po.tvc_p,
|
111 |
+
"currency": tvc_lc,
|
112 |
+
"quantity": tvc_po.tvc_q
|
113 |
+
}],
|
114 |
+
"non_interaction": true,
|
115 |
+
"value": tvc_po.tvc_p * tvc_po.tvc_q,
|
116 |
+
"page_type": this.options.page_type,
|
117 |
+
"user_type": this.options.user_type,
|
118 |
+
"user_id": this.options.user_id,
|
119 |
+
"client_id":this.getClientId(),
|
120 |
+
"day_type": this.options.day_type,
|
121 |
+
"local_time_slot_of_the_day": this.options.local_time
|
122 |
+
});
|
123 |
+
}catch(err){
|
124 |
+
gtag("event", "exception", {
|
125 |
+
"description": err,
|
126 |
+
"fatal": false
|
127 |
+
});
|
128 |
+
}
|
129 |
+
}
|
130 |
+
|
131 |
+
//add remarketing and dynamicremarketing tags
|
132 |
+
if(this.is_add_remarketing_tags()){
|
133 |
+
gtag("event","view_item", {
|
134 |
+
"value": tvc_po.tvc_p,
|
135 |
+
"items": [{
|
136 |
+
"id": tvc_po.tvc_id,
|
137 |
+
"google_business_vertical": "retail"
|
138 |
+
}]
|
139 |
+
});
|
140 |
+
}
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
}
|
145 |
+
add_to_cart_click( ){
|
146 |
+
if(this.options.is_admin == true){
|
147 |
+
return;
|
148 |
+
}
|
149 |
+
var varPrice = tvc_po.tvc_p;
|
150 |
+
var event_label="add_to_cart_";
|
151 |
+
var selected_variants = "";
|
152 |
+
//var var_s = document.getElementsByClassName("variations").getElementsByTagName("select");
|
153 |
+
/*var selected_variants = $.map($(".variations select :selected"), function(a){
|
154 |
+
return a.value;
|
155 |
+
}).join(" | ");*/
|
156 |
+
if(selected_variants != ""){
|
157 |
+
event_label="add_to_cart_"+this.options.page_type+" | "+tvc_po.tvc_n+" | "+selected_variants;
|
158 |
+
varPrice = jQuery("div.woocommerce-variation-price > span.price > ins >span.woocommerce-Price-amount").text().replace("$","");
|
159 |
+
if (varPrice == "") {
|
160 |
+
varPrice = jQuery("div.woocommerce-variation-price > span.price > .woocommerce-Price-amount").text().replace("$","");
|
161 |
+
}
|
162 |
+
console.log("variants");
|
163 |
+
}else if (tvc_po.is_featured == true){
|
164 |
+
event_label="add_to_cart_"+this.options.page_type+" | " + this.options.feature_product_label + " | "+tvc_po.tvc_n;
|
165 |
+
console.log("is_featured");
|
166 |
+
}else if (tvc_po.is_onSale == true){
|
167 |
+
event_label="add_to_cart_"+this.options.page_type+" | " + this.options.on_sale_label + " | "+tvc_po.tvc_n;
|
168 |
+
console.log("is_onSale");
|
169 |
+
}else{
|
170 |
+
event_label="add_to_cart_"+this.options.page_type+" | "+tvc_po.tvc_n;
|
171 |
+
console.log(" - - ");
|
172 |
+
}
|
173 |
+
var lastCartTime = this.getCookie("time_add_to_cart");
|
174 |
+
var curCartTime = this.getCurrentTime();
|
175 |
+
var timeToCart = curCartTime - lastCartTime;
|
176 |
+
this.eraseCookie("time_add_to_cart");
|
177 |
+
this.setCookie("time_add_to_cart",curCartTime,7);
|
178 |
+
/*
|
179 |
+
* Start UA or GA4
|
180 |
+
*/
|
181 |
+
if((this.options.tracking_option =="UA" || this.options.tracking_option == "BOTH") && this.options.property_id ){
|
182 |
+
try {
|
183 |
+
gtag("event", "add_to_cart", {
|
184 |
+
"event_category":"Enhanced-Ecommerce",
|
185 |
+
"event_label":"add_to_cart_click",
|
186 |
+
"non_interaction": true,
|
187 |
+
"items": [{
|
188 |
+
"id" : tvc_po.tvc_i,
|
189 |
+
"name": tvc_po.tvc_n,
|
190 |
+
"category" :tvc_po.tvc_c,
|
191 |
+
"price": varPrice,
|
192 |
+
"quantity" :jQuery(this).parent().find("input[name=quantity]").val(),
|
193 |
+
"list_name":this.options.page_type,
|
194 |
+
"list_position": 1,
|
195 |
+
"variant": tvc_po.tvc_var
|
196 |
+
}],
|
197 |
+
"page_type": this.options.page_type,
|
198 |
+
"user_type": this.options.user_type,
|
199 |
+
"user_id": this.options.user_id,
|
200 |
+
"client_id":this.getClientId(),
|
201 |
+
"day_type": this.options.day_type,
|
202 |
+
"local_time_slot_of_the_day": this.options.local_time,
|
203 |
+
"product_discount": tvc_po.tvc_pd,
|
204 |
+
"stock_status": tvc_po.tvc_ps,
|
205 |
+
"inventory": tvc_po.tvc_tst,
|
206 |
+
"time_taken_to_add_to_cart": timeToCart
|
207 |
+
});
|
208 |
+
}catch(err){
|
209 |
+
gtag("event", "exception", {
|
210 |
+
"description": err,
|
211 |
+
"fatal": false
|
212 |
+
});
|
213 |
+
}
|
214 |
+
/*
|
215 |
+
* Start GA4
|
216 |
+
*/
|
217 |
+
}else if( this.options.tracking_option == "GA4" && this.options.measurement_id ){
|
218 |
+
try {
|
219 |
+
gtag("event", "add_to_cart", {
|
220 |
+
"event_category":"Enhanced-Ecommerce",
|
221 |
+
"event_label":"add_to_cart_click",
|
222 |
+
"currency": tvc_lc,
|
223 |
+
"non_interaction": true,
|
224 |
+
"items": [{
|
225 |
+
"item_id" : tvc_po.tvc_i,
|
226 |
+
"item_name": tvc_po.tvc_n,
|
227 |
+
"item_category" :tvc_po.tvc_c,
|
228 |
+
"price":varPrice,
|
229 |
+
"currency": tvc_lc,
|
230 |
+
"quantity": jQuery(this).parent().find("input[name=quantity]").val(),
|
231 |
+
"item_variant": tvc_po.tvc_var,
|
232 |
+
"discount": tvc_po.tvc_pd,
|
233 |
+
"affiliation":this.options.affiliation
|
234 |
+
}],
|
235 |
+
"page_type": this.options.page_type,
|
236 |
+
"user_type": this.options.user_type,
|
237 |
+
"user_id": this.options.user_id,
|
238 |
+
"client_id":this.getClientId(),
|
239 |
+
"day_type": this.options.day_type,
|
240 |
+
"local_time_slot_of_the_day": this.options.local_time,
|
241 |
+
"product_discount": tvc_po.tvc_pd,
|
242 |
+
"stock_status": tvc_po.tvc_ps,
|
243 |
+
"inventory": tvc_po.tvc_tst,
|
244 |
+
"time_taken_to_add_to_cart": timeToCart
|
245 |
+
});
|
246 |
+
}catch(err){
|
247 |
+
gtag("event", "exception", {
|
248 |
+
"description": err,
|
249 |
+
"fatal": false
|
250 |
+
});
|
251 |
+
}
|
252 |
+
}
|
253 |
+
//add remarketing and dynamicremarketing tags
|
254 |
+
if(this.is_add_remarketing_tags()){
|
255 |
+
gtag("event","add_to_cart", {
|
256 |
+
"value": tvc_po.tvc_p,
|
257 |
+
"items": [{
|
258 |
+
"id": tvc_po.tvc_id,
|
259 |
+
"google_business_vertical": "retail"
|
260 |
+
}]
|
261 |
+
});
|
262 |
+
}
|
263 |
+
}
|
264 |
+
|
265 |
+
/*
|
266 |
+
* below code run on thenk you page.
|
267 |
+
* ( Event=> purchase )
|
268 |
+
*/
|
269 |
+
thnkyou_page(tvc_oc, tvc_td, order_status, purchase_time){
|
270 |
+
if(this.options.is_admin == true){
|
271 |
+
return;
|
272 |
+
}
|
273 |
+
this.options.page_type="Thankyou Page";
|
274 |
+
//console.log("call =>0"+this.options.tracking_option+"--"+this.options.property_id);
|
275 |
+
if(this.is_add_remarketing_tags()){
|
276 |
+
var ads_items = [];
|
277 |
+
var ads_value=0;
|
278 |
+
for(var t_item in tvc_oc){
|
279 |
+
ads_value=ads_value + parseFloat(tvc_oc[t_item].tvc_p);
|
280 |
+
ads_items.push({
|
281 |
+
item_id: tvc_oc[t_item].tvc_i,
|
282 |
+
google_business_vertical: "retail"
|
283 |
+
});
|
284 |
+
}
|
285 |
+
gtag("event","purchase", {
|
286 |
+
"value": ads_value,
|
287 |
+
"items": ads_items
|
288 |
+
});
|
289 |
+
}
|
290 |
+
var last_purchase_time = this.getCookie("time_to_purchase");
|
291 |
+
var time_to_purchase = purchase_time - last_purchase_time;
|
292 |
+
this.eraseCookie("time_to_purchase");
|
293 |
+
this.setCookie("time_to_purchase",purchase_time,7);
|
294 |
+
/*
|
295 |
+
* Start UA or GA4
|
296 |
+
*/
|
297 |
+
if((this.options.tracking_option =="UA" || this.options.tracking_option == "BOTH") && this.options.property_id ){
|
298 |
+
try {
|
299 |
+
var items = [];
|
300 |
+
//set local currencies
|
301 |
+
gtag("set", {"currency": this.options.currency});
|
302 |
+
var item_position=1;
|
303 |
+
for(var t_item in tvc_oc){
|
304 |
+
items.push({
|
305 |
+
"id": tvc_oc[t_item].tvc_i,
|
306 |
+
"name": tvc_oc[t_item].tvc_n,
|
307 |
+
"list_name": this.options.page_type,
|
308 |
+
"category": tvc_oc[t_item].tvc_c,
|
309 |
+
"variant": tvc_oc[t_item].tvc_var,
|
310 |
+
"price": tvc_oc[t_item].tvc_p,
|
311 |
+
"quantity": tvc_oc[t_item].tvc_q,
|
312 |
+
"list_position": item_position
|
313 |
+
//"attributes": tvc_oc[t_item].tvc_attr,
|
314 |
+
});
|
315 |
+
item_position++;
|
316 |
+
}
|
317 |
+
|
318 |
+
if( order_status == "failed" ){
|
319 |
+
gtag("event", "purchase_failure", {
|
320 |
+
"event_category":"Custom",
|
321 |
+
"event_label":"purchase_failure_error",
|
322 |
+
"transaction_id":tvc_td.id,
|
323 |
+
"affiliation": tvc_td.affiliation,
|
324 |
+
"value":tvc_td.revenue,
|
325 |
+
"currency": tvc_lc,
|
326 |
+
"tax": tvc_td.tax,
|
327 |
+
"shipping": tvc_td.shipping,
|
328 |
+
"coupon": tvc_td.coupon,
|
329 |
+
"event_value": tvc_td.revenue,
|
330 |
+
"items":items,
|
331 |
+
"non_interaction": true,
|
332 |
+
"shipping_tier": tvc_td.shipping,
|
333 |
+
"page_type": this.options.page_type,
|
334 |
+
"user_type": this.options.user_type,
|
335 |
+
"user_id": this.options.user_id,
|
336 |
+
"client_id":this.getClientId(),
|
337 |
+
"day_type": this.options.day_type,
|
338 |
+
"local_time_slot_of_the_day": purchase_time
|
339 |
+
});
|
340 |
+
}else{
|
341 |
+
gtag("event", "purchase", {
|
342 |
+
"event_category": "Enhanced-Ecommerce",
|
343 |
+
"transaction_id":tvc_td.id,
|
344 |
+
"affiliation": tvc_td.affiliation,
|
345 |
+
"value":tvc_td.revenue,
|
346 |
+
"currency": tvc_lc,
|
347 |
+
"tax": tvc_td.tax,
|
348 |
+
"shipping": tvc_td.shipping,
|
349 |
+
"coupon": tvc_td.coupon,
|
350 |
+
"event_label":"order_confirmation",
|
351 |
+
"items":items,
|
352 |
+
"non_interaction": true,
|
353 |
+
"shipping_tier": tvc_td.shipping,
|
354 |
+
"page_type": this.options.page_type,
|
355 |
+
"user_type": this.options.user_type,
|
356 |
+
"user_id": this.options.user_id,
|
357 |
+
"client_id":this.getClientId(),
|
358 |
+
"day_type": this.options.day_type,
|
359 |
+
"local_time_slot_of_the_day": purchase_time,
|
360 |
+
"time_taken_to_make_the_purchase": time_to_purchase
|
361 |
+
});
|
362 |
+
}
|
363 |
+
}catch(err){
|
364 |
+
gtag("event", "exception", {
|
365 |
+
"description": err,
|
366 |
+
"fatal": false
|
367 |
+
});
|
368 |
+
}
|
369 |
+
/*
|
370 |
+
* Start GA4
|
371 |
+
*/
|
372 |
+
}else if( this.options.tracking_option == "GA4" && this.options.measurement_id ){
|
373 |
+
try {
|
374 |
+
var items = [];
|
375 |
+
for(var t_item in tvc_oc){
|
376 |
+
items.push({
|
377 |
+
"item_id": tvc_oc[t_item].tvc_i,
|
378 |
+
"item_name": tvc_oc[t_item].tvc_n,
|
379 |
+
"coupon": tvc_td.coupon,
|
380 |
+
"affiliation": tvc_td.affiliation,
|
381 |
+
"discount":tvc_oc[t_item].tvc_pd,
|
382 |
+
"item_category": tvc_oc[t_item].tvc_c,
|
383 |
+
"item_variant": tvc_oc[t_item].tvc_attr,
|
384 |
+
"price": tvc_oc[t_item].tvc_p,
|
385 |
+
"currency": tvc_lc,
|
386 |
+
"quantity": tvc_oc[t_item].tvc_q
|
387 |
+
});
|
388 |
+
}
|
389 |
+
|
390 |
+
if( order_status == "failed" ){
|
391 |
+
gtag("event", "purchase_failure", {
|
392 |
+
"event_category":"Custom",
|
393 |
+
"event_label":"purchase_failure_error",
|
394 |
+
"transaction_id":tvc_td.id,
|
395 |
+
"affiliation": tvc_td.affiliation,
|
396 |
+
"value":tvc_td.revenue,
|
397 |
+
"currency": tvc_lc,
|
398 |
+
"tax": tvc_td.tax,
|
399 |
+
"shipping": tvc_td.shipping,
|
400 |
+
"coupon": tvc_td.coupon,
|
401 |
+
"event_value": tvc_td.revenue,
|
402 |
+
"items":items,
|
403 |
+
"non_interaction": true,
|
404 |
+
"shipping_tier": tvc_td.shipping,
|
405 |
+
"page_type": this.options.page_type,
|
406 |
+
"user_type": this.options.user_type,
|
407 |
+
"user_id": this.options.user_id,
|
408 |
+
"client_id":this.getClientId(),
|
409 |
+
"day_type": this.options.day_type,
|
410 |
+
"local_time_slot_of_the_day": purchase_time
|
411 |
+
});
|
412 |
+
}else{
|
413 |
+
gtag("event", "purchase", {
|
414 |
+
"event_category": "Enhanced-Ecommerce",
|
415 |
+
"transaction_id":tvc_td.id,
|
416 |
+
"affiliation": tvc_td.affiliation,
|
417 |
+
"value":tvc_td.revenue,
|
418 |
+
"currency": tvc_lc,
|
419 |
+
"tax": tvc_td.tax,
|
420 |
+
"shipping": tvc_td.shipping,
|
421 |
+
"coupon": tvc_td.coupon,
|
422 |
+
"event_label":"order_confirmation",
|
423 |
+
"items":items,
|
424 |
+
"non_interaction": true,
|
425 |
+
"shipping_tier": tvc_td.shipping,
|
426 |
+
"page_type": this.options.page_type,
|
427 |
+
"user_type": this.options.user_type,
|
428 |
+
"user_id": this.options.user_id,
|
429 |
+
"client_id":this.getClientId(),
|
430 |
+
"day_type": this.options.day_type,
|
431 |
+
"local_time_slot_of_the_day": purchase_time,
|
432 |
+
"time_taken_to_make_the_purchase": time_to_purchase
|
433 |
+
});
|
434 |
+
}
|
435 |
+
}catch(err){
|
436 |
+
gtag("event", "exception", {
|
437 |
+
"description": err,
|
438 |
+
"fatal": false
|
439 |
+
});
|
440 |
+
}
|
441 |
+
}
|
442 |
+
}
|
443 |
+
getCurrentTime(){
|
444 |
+
if (!Date.now) {
|
445 |
+
return new Date().getTime();
|
446 |
+
}else{
|
447 |
+
//Math.floor(Date.now() / 1000)
|
448 |
+
return Date.now();
|
449 |
+
}
|
450 |
+
}
|
451 |
+
getClientId() {
|
452 |
+
let client_id = this.getCookie("_ga");
|
453 |
+
if(client_id != null && client_id != ""){
|
454 |
+
return client_id;
|
455 |
+
}else{
|
456 |
+
return ;
|
457 |
+
}
|
458 |
+
|
459 |
+
|
460 |
+
}
|
461 |
+
setCookie(name,value,days) {
|
462 |
+
var expires = "";
|
463 |
+
if (days) {
|
464 |
+
var date = new Date();
|
465 |
+
date.setTime(date.getTime() + (days*24*60*60*1000));
|
466 |
+
expires = "; expires=" + date.toUTCString();
|
467 |
+
}
|
468 |
+
document.cookie = name + "=" + (value || "") + expires + "; path=/";
|
469 |
+
}
|
470 |
+
getCookie(name) {
|
471 |
+
var nameEQ = name + "=";
|
472 |
+
var ca = document.cookie.split(";");
|
473 |
+
for(var i=0;i < ca.length;i++) {
|
474 |
+
var c = ca[i];
|
475 |
+
while (c.charAt(0)==" ") c = c.substring(1,c.length);
|
476 |
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
|
477 |
+
}
|
478 |
+
return null;
|
479 |
+
}
|
480 |
+
eraseCookie(name) {
|
481 |
+
document.cookie = name +"=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;";
|
482 |
+
}
|
483 |
+
static test(){
|
484 |
+
//console.log(this.options);
|
485 |
+
if(this.options.is_admin == true){
|
486 |
+
return;
|
487 |
+
}
|
488 |
+
/*
|
489 |
+
* Start UA or GA4
|
490 |
+
*/
|
491 |
+
if((this.options.tracking_option =="UA" || this.options.tracking_option == "BOTH") && this.options.property_id ){
|
492 |
+
try {
|
493 |
+
}catch(err){
|
494 |
+
gtag("event", "exception", {
|
495 |
+
"description": err,
|
496 |
+
"fatal": false
|
497 |
+
});
|
498 |
+
}
|
499 |
+
/*
|
500 |
+
* Start GA4
|
501 |
+
*/
|
502 |
+
}else if( this.options.tracking_option == "GA4" && this.options.measurement_id ){
|
503 |
+
try {
|
504 |
+
}catch(err){
|
505 |
+
gtag("event", "exception", {
|
506 |
+
"description": err,
|
507 |
+
"fatal": false
|
508 |
+
});
|
509 |
+
}
|
510 |
+
}
|
511 |
+
}
|
512 |
+
}
|
readme.txt
CHANGED
@@ -8,8 +8,8 @@ Author: Tatvic
|
|
8 |
Requires at least: 1.4.1
|
9 |
Tested up to: 5.7
|
10 |
Requires PHP: 5.6 or Higher
|
11 |
-
Stable tag: 3.1.
|
12 |
-
Version: 3.1.
|
13 |
License: GPLv3
|
14 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
15 |
|
@@ -383,6 +383,9 @@ You can resolve the duplication of data by removing the manually implemented GA
|
|
383 |
|
384 |
== Changelog ==
|
385 |
|
|
|
|
|
|
|
386 |
= 3.1.1 - 15/06/2021 =
|
387 |
* DB related bug fixed
|
388 |
|
8 |
Requires at least: 1.4.1
|
9 |
Tested up to: 5.7
|
10 |
Requires PHP: 5.6 or Higher
|
11 |
+
Stable tag: 3.1.2
|
12 |
+
Version: 3.1.2
|
13 |
License: GPLv3
|
14 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
15 |
|
383 |
|
384 |
== Changelog ==
|
385 |
|
386 |
+
= 3.1.2 - 29/06/2021 =
|
387 |
+
* Fixed remarketing code bug
|
388 |
+
|
389 |
= 3.1.1 - 15/06/2021 =
|
390 |
* DB related bug fixed
|
391 |
|