DuracellTomi's Google Tag Manager for WordPress - Version 1.12

Version Description

WARNING! If you are using the blacklist/whitelist feature of the plugin, review these options after upgrade as they could break because of a fundamental rework of this feature.

  • Added: support for Google Analytics 4 version of ecommerce data layer
  • Fixed: safer IP address validation in geo and weather data features
  • Updated: removed deprecated events: download links, email links, social links -> such can be now tracked with native Google Tag Manager triggers
  • Updated: removed support for WooCommerce versions before v3.2
  • Updated: 'Blacklist tags' tab renamed to 'Security'
  • Updated: complete rework of blacklist/whitelist feature to use the latest tag/trigger/variable list of Google
  • Deprecated: classic ecommerce tracking will be removed later this year, please upgrade to enhanced ecommerce tracking
  • Deprecated: standard Google Ads remarketing variable will be removed soon as the Google Ads remarketing tag template can easily use any of your Google Tag Manager variables
  • Deprecated: the old fashioned way of using Google Ads remarketing with the ecomm_ prefixed data layer variables will be removed soon. Instructions for upgrade will be published on gtm4wp.com once this feature gets updated in an upcoming plugin version
Download this release

Release Info

Developer duracelltomi
Plugin Icon 128x128 DuracellTomi's Google Tag Manager for WordPress
Version 1.12
Comparing to
See all releases

Code changes from version 1.11.6 to 1.12

admin/admin.php CHANGED
@@ -27,7 +27,6 @@ $GLOBALS['gtm4wp_def_user_notices_dismisses'] = array(
27
  'wc-ga-plugin-warning' => false,
28
  'wc-gayoast-plugin-warning' => false,
29
  'php56-warning' => false,
30
- 'woo2x-warning' => false,
31
  'deprecated-warning' => false,
32
  );
33
 
@@ -130,22 +129,19 @@ $GLOBALS['gtm4wp_includefieldtexts'] = array(
130
  GTM4WP_OPTION_INCLUDE_REMARKETING => array(
131
  'label' => __( 'Remarketing variable', 'duracelltomi-google-tag-manager' ),
132
  'description' => __( 'Check this option to include a dataLayer variable where all dataLayer values are stored to be included in your Google Ads remarketing tag as a custom variable field', 'duracelltomi-google-tag-manager' ),
133
- 'phase' => GTM4WP_PHASE_STABLE,
134
  ),
135
  GTM4WP_OPTION_INCLUDE_BROWSERDATA => array(
136
  'label' => __( 'Browser data *', 'duracelltomi-google-tag-manager' ),
137
- 'description' => __( 'Check this option to include the name, version and engine data of the browser the visitor uses.', 'duracelltomi-google-tag-manager' ),
138
- 'phase' => GTM4WP_PHASE_BETA,
139
  ),
140
  GTM4WP_OPTION_INCLUDE_OSDATA => array(
141
  'label' => __( 'OS data *', 'duracelltomi-google-tag-manager' ),
142
- 'description' => __( 'Check this option to include the name and version of the operating system the visitor uses.', 'duracelltomi-google-tag-manager' ),
143
- 'phase' => GTM4WP_PHASE_BETA,
144
  ),
145
  GTM4WP_OPTION_INCLUDE_DEVICEDATA => array(
146
  'label' => __( 'Device data *', 'duracelltomi-google-tag-manager' ),
147
- 'description' => __( 'Check this option to include the type of device the user is currently using (desktop, tablet or mobile) including manufacturer and model data.', 'duracelltomi-google-tag-manager' ),
148
- 'phase' => GTM4WP_PHASE_BETA,
149
  ),
150
  GTM4WP_OPTION_INCLUDE_MISCGEO => array(
151
  'label' => __( 'Geo data', 'duracelltomi-google-tag-manager' ),
@@ -232,32 +228,7 @@ $GLOBALS['gtm4wp_eventfieldtexts'] = array(
232
  'label' => __( 'Soundcloud events', 'duracelltomi-google-tag-manager' ),
233
  'description' => __( 'Check this option to include a Tag Manager event when a visitor interacts with a Soundcloud media embeded on your site.', 'duracelltomi-google-tag-manager' ),
234
  'phase' => GTM4WP_PHASE_EXPERIMENTAL,
235
- ),
236
- GTM4WP_OPTION_EVENTS_SOCIAL => array(
237
- 'label' => __( 'Social actions (gtm4wp.socialAction)', 'duracelltomi-google-tag-manager' ),
238
- 'description' => __( 'Check this option to include a Tag Manager event when a visitor uses a social button to share/like content on a social network.', 'duracelltomi-google-tag-manager' ),
239
- 'phase' => GTM4WP_PHASE_DEPRECATED,
240
- ),
241
- GTM4WP_OPTION_EVENTS_OUTBOUND => array(
242
- 'label' => __( 'Outbound link click events (gtm4wp.outboundClick)', 'duracelltomi-google-tag-manager' ),
243
- 'description' => __( 'Check this option to include a Tag Manager event when a visitor clicks on a link directing the visitor out of your website.', 'duracelltomi-google-tag-manager' ),
244
- 'phase' => GTM4WP_PHASE_DEPRECATED,
245
- ),
246
- GTM4WP_OPTION_EVENTS_DOWNLOADS => array(
247
- 'label' => __( 'Download click events (gtm4wp.downloadClick)', 'duracelltomi-google-tag-manager' ),
248
- 'description' => __( 'Check this option to include a Tag Manager event when a visitors clicks on a link that leads to a downloadable file on your website.', 'duracelltomi-google-tag-manager' ),
249
- 'phase' => GTM4WP_PHASE_DEPRECATED,
250
- ),
251
- GTM4WP_OPTION_EVENTS_DWLEXT => array(
252
- 'label' => __( 'Extensions to track', 'duracelltomi-google-tag-manager' ),
253
- 'description' => __( "Enter a comma separated list of extensions to track when 'Include download click events' option is set.", 'duracelltomi-google-tag-manager' ),
254
- 'phase' => GTM4WP_PHASE_DEPRECATED,
255
- ),
256
- GTM4WP_OPTION_EVENTS_EMAILCLICKS => array(
257
- 'label' => __( 'Email click events (gtm4wp.emailClick)', 'duracelltomi-google-tag-manager' ),
258
- 'description' => __( 'Check this option to include a Tag Manager event when a visitor clicks on an email link.', 'duracelltomi-google-tag-manager' ),
259
- 'phase' => GTM4WP_PHASE_DEPRECATED,
260
- ),
261
  );
262
 
263
  $GLOBALS['gtm4wp_scrollerfieldtexts'] = array(
@@ -293,167 +264,6 @@ $GLOBALS['gtm4wp_scrollerfieldtexts'] = array(
293
  ),
294
  );
295
 
296
- $GLOBALS['gtm4wp_blacklistfieldtexts'] = array(
297
- GTM4WP_OPTION_BLACKLIST_ENABLE => array(
298
- 'label' => __( 'Enable blacklist/whitelist', 'duracelltomi-google-tag-manager' ),
299
- 'description' => __( 'Disable feature or select whether you want to whitelist or blacklist tags', 'duracelltomi-google-tag-manager' ),
300
- 'phase' => GTM4WP_PHASE_STABLE,
301
- ),
302
- GTM4WP_OPTION_BLACKLIST_AWCONV => array(
303
- 'label' => __( 'Google Ads Conversion Tracking Tag', 'duracelltomi-google-tag-manager' ),
304
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
305
- 'phase' => GTM4WP_PHASE_STABLE,
306
- ),
307
- GTM4WP_OPTION_BLACKLIST_AWREMARKET => array(
308
- 'label' => __( 'Google Ads Remarketing Tag', 'duracelltomi-google-tag-manager' ),
309
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
310
- 'phase' => GTM4WP_PHASE_STABLE,
311
- ),
312
- GTM4WP_OPTION_BLACKLIST_GACLASSIC => array(
313
- 'label' => __( 'Google Analytics Tag', 'duracelltomi-google-tag-manager' ),
314
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
315
- 'phase' => GTM4WP_PHASE_STABLE,
316
- ),
317
- GTM4WP_OPTION_BLACKLIST_UA => array(
318
- 'label' => __( 'Universal Analytics Tag', 'duracelltomi-google-tag-manager' ),
319
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
320
- 'phase' => GTM4WP_PHASE_STABLE,
321
- ),
322
- GTM4WP_OPTION_BLACKLIST_ADADVISOR => array(
323
- 'label' => __( 'AdAdvisor Tag', 'duracelltomi-google-tag-manager' ),
324
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
325
- 'phase' => GTM4WP_PHASE_STABLE,
326
- ),
327
- GTM4WP_OPTION_BLACKLIST_ADROLL => array(
328
- 'label' => __( 'AdRoll Smart Pixel Tag', 'duracelltomi-google-tag-manager' ),
329
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
330
- 'phase' => GTM4WP_PHASE_STABLE,
331
- ),
332
- GTM4WP_OPTION_BLACKLIST_BIZO => array(
333
- 'label' => __( 'Bizo Insight Tag', 'duracelltomi-google-tag-manager' ),
334
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
335
- 'phase' => GTM4WP_PHASE_STABLE,
336
- ),
337
- GTM4WP_OPTION_BLACKLIST_CLICKTALE => array(
338
- 'label' => __( 'ClickTale Standard Tracking Tag', 'duracelltomi-google-tag-manager' ),
339
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
340
- 'phase' => GTM4WP_PHASE_STABLE,
341
- ),
342
- GTM4WP_OPTION_BLACKLIST_COMSCORE => array(
343
- 'label' => __( 'comScore Unified Digital Measurement Tag', 'duracelltomi-google-tag-manager' ),
344
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
345
- 'phase' => GTM4WP_PHASE_STABLE,
346
- ),
347
- GTM4WP_OPTION_BLACKLIST_CUSTOMHTML => array(
348
- 'label' => __( 'Custom HTML Tag', 'duracelltomi-google-tag-manager' ),
349
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
350
- 'phase' => GTM4WP_PHASE_STABLE,
351
- ),
352
- GTM4WP_OPTION_BLACKLIST_CUSTOMIMG => array(
353
- 'label' => __( 'Custom Image Tag', 'duracelltomi-google-tag-manager' ),
354
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
355
- 'phase' => GTM4WP_PHASE_STABLE,
356
- ),
357
- GTM4WP_OPTION_BLACKLIST_DBLCLKCOUNT => array(
358
- 'label' => __( 'DoubleClick Floodlight Counter Tag', 'duracelltomi-google-tag-manager' ),
359
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
360
- 'phase' => GTM4WP_PHASE_STABLE,
361
- ),
362
- GTM4WP_OPTION_BLACKLIST_DBLCLKSALES => array(
363
- 'label' => __( 'DoubleClick Floodlight Sales Tag', 'duracelltomi-google-tag-manager' ),
364
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
365
- 'phase' => GTM4WP_PHASE_STABLE,
366
- ),
367
- GTM4WP_OPTION_BLACKLIST_MARIN => array(
368
- 'label' => __( 'Marin Software Tag', 'duracelltomi-google-tag-manager' ),
369
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
370
- 'phase' => GTM4WP_PHASE_STABLE,
371
- ),
372
- GTM4WP_OPTION_BLACKLIST_MPLEXIFRAME => array(
373
- 'label' => __( 'Mediaplex - IFRAME MCT Tag', 'duracelltomi-google-tag-manager' ),
374
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
375
- 'phase' => GTM4WP_PHASE_STABLE,
376
- ),
377
- GTM4WP_OPTION_BLACKLIST_MPLEXROI => array(
378
- 'label' => __( 'Mediaplex - Standard IMG ROI Tag', 'duracelltomi-google-tag-manager' ),
379
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
380
- 'phase' => GTM4WP_PHASE_STABLE,
381
- ),
382
- GTM4WP_OPTION_BLACKLIST_MEDIA6DEG => array(
383
- 'label' => __( 'Media6Degrees Universal Pixel Tag', 'duracelltomi-google-tag-manager' ),
384
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
385
- 'phase' => GTM4WP_PHASE_STABLE,
386
- ),
387
- GTM4WP_OPTION_BLACKLIST_TURNCONV => array(
388
- 'label' => __( 'Turn Conversion Tracking Tag', 'duracelltomi-google-tag-manager' ),
389
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
390
- 'phase' => GTM4WP_PHASE_STABLE,
391
- ),
392
- GTM4WP_OPTION_BLACKLIST_TURNDATA => array(
393
- 'label' => __( 'Turn Data Collection Tag', 'duracelltomi-google-tag-manager' ),
394
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
395
- 'phase' => GTM4WP_PHASE_STABLE,
396
- ),
397
- );
398
-
399
- $GLOBALS['gtm4wp_blacklistmfieldtexts'] = array(
400
- GTM4WP_OPTION_BLACKLIST_MACRO_DOMELEMENT => array(
401
- 'label' => __( 'DOM element Macro', 'duracelltomi-google-tag-manager' ),
402
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
403
- 'phase' => GTM4WP_PHASE_STABLE,
404
- ),
405
- GTM4WP_OPTION_BLACKLIST_MACRO_CUSTOMJS => array(
406
- 'label' => __( 'Custom JavaScript Macro', 'duracelltomi-google-tag-manager' ),
407
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
408
- 'phase' => GTM4WP_PHASE_STABLE,
409
- ),
410
- GTM4WP_OPTION_BLACKLIST_MACRO_CONSTANT => array(
411
- 'label' => __( 'Constant Macro', 'duracelltomi-google-tag-manager' ),
412
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
413
- 'phase' => GTM4WP_PHASE_STABLE,
414
- ),
415
- GTM4WP_OPTION_BLACKLIST_MACRO_1STCOOKIE => array(
416
- 'label' => __( 'First Party Cookie Macro', 'duracelltomi-google-tag-manager' ),
417
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
418
- 'phase' => GTM4WP_PHASE_STABLE,
419
- ),
420
- GTM4WP_OPTION_BLACKLIST_MACRO_EVENTNAME => array(
421
- 'label' => __( 'Event Name Macro', 'duracelltomi-google-tag-manager' ),
422
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
423
- 'phase' => GTM4WP_PHASE_STABLE,
424
- ),
425
- GTM4WP_OPTION_BLACKLIST_MACRO_JSVAR => array(
426
- 'label' => __( 'JavaScript Variable Macro', 'duracelltomi-google-tag-manager' ),
427
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
428
- 'phase' => GTM4WP_PHASE_STABLE,
429
- ),
430
- GTM4WP_OPTION_BLACKLIST_MACRO_DLAYERVAR => array(
431
- 'label' => __( 'DataLayer Variable Macro', 'duracelltomi-google-tag-manager' ),
432
- 'description' => __( 'It is not recommended to blacklist this type of macro since most features of this plugin depend on dataLayer macros.', 'duracelltomi-google-tag-manager' ),
433
- 'phase' => GTM4WP_PHASE_STABLE,
434
- ),
435
- GTM4WP_OPTION_BLACKLIST_MACRO_RANDOMNUM => array(
436
- 'label' => __( 'Random Number Macro', 'duracelltomi-google-tag-manager' ),
437
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
438
- 'phase' => GTM4WP_PHASE_STABLE,
439
- ),
440
- GTM4WP_OPTION_BLACKLIST_MACRO_REFERRER => array(
441
- 'label' => __( 'Referrer Macro', 'duracelltomi-google-tag-manager' ),
442
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
443
- 'phase' => GTM4WP_PHASE_STABLE,
444
- ),
445
- GTM4WP_OPTION_BLACKLIST_MACRO_URL => array(
446
- 'label' => __( 'URL Macro', 'duracelltomi-google-tag-manager' ),
447
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
448
- 'phase' => GTM4WP_PHASE_STABLE,
449
- ),
450
- GTM4WP_OPTION_BLACKLIST_MACRO_AUTOEVENT => array(
451
- 'label' => __( 'Auto-Event Variable Macro', 'duracelltomi-google-tag-manager' ),
452
- 'description' => __( '', 'duracelltomi-google-tag-manager' ),
453
- 'phase' => GTM4WP_PHASE_STABLE,
454
- ),
455
- );
456
-
457
  $GLOBALS['gtm4wp_integratefieldtexts'] = array(
458
  GTM4WP_OPTION_INTEGRATE_WPCF7 => array(
459
  'label' => __( 'Contact Form 7', 'duracelltomi-google-tag-manager' ),
@@ -464,13 +274,13 @@ $GLOBALS['gtm4wp_integratefieldtexts'] = array(
464
  GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => array(
465
  'label' => __( 'Track classic e-commerce', 'duracelltomi-google-tag-manager' ),
466
  'description' => sprintf( __( 'Choose this option if you would like to track e-commerce data using <a href="%s" target="_blank">classic transaction data</a>.', 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce' ),
467
- 'phase' => GTM4WP_PHASE_STABLE,
468
  'plugintocheck' => 'woocommerce/woocommerce.php',
469
  ),
470
  GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => array(
471
  'label' => __( 'Track enhanced e-commerce', 'duracelltomi-google-tag-manager' ),
472
  'description' => sprintf( __( 'Choose this option if you would like to track e-commerce data using <a href="%s" target="_blank">enhanced ecommerce tracking</a>.', 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce' ),
473
- 'phase' => GTM4WP_PHASE_BETA,
474
  'plugintocheck' => 'woocommerce/woocommerce.php',
475
  ),
476
  GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION => array(
@@ -482,74 +292,62 @@ $GLOBALS['gtm4wp_integratefieldtexts'] = array(
482
  "tag's trigger.<br /><br />Leave this value 0 to include product impression data in your pageview hit.",
483
  'duracelltomi-google-tag-manager'
484
  ),
485
- 'phase' => GTM4WP_PHASE_BETA,
486
- 'plugintocheck' => 'woocommerce/woocommerce.php',
487
  ),
488
  GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP => array(
489
  'label' => __( 'Cart as 1st checkout step', 'duracelltomi-google-tag-manager' ),
490
  'description' => __( 'Enable this to track the cart page as the first checkout step in enhanced ecommerce instead of the checkout page itself', 'duracelltomi-google-tag-manager' ),
491
- 'phase' => GTM4WP_PHASE_BETA,
492
- 'plugintocheck' => 'woocommerce/woocommerce.php',
493
  ),
494
  GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL => array(
495
  "label" => __( "Cart content in data layer", 'duracelltomi-google-tag-manager' ),
496
  "description" => __( "Enable this option to include the content of the cart in the data layer on each page. Needs WooCommerce v3.2 or newer. Especially useful for site personalization with Google Optimize.", 'duracelltomi-google-tag-manager' ),
497
- "phase" => GTM4WP_PHASE_BETA,
498
- "plugintocheck" => "woocommerce/woocommerce.php"
499
  ),
500
  GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH => array(
501
  'label' => __( 'Include full category path.', 'duracelltomi-google-tag-manager' ),
502
  'description' => __( 'Check this to inclulde the full category path of each product in enhanced ecommerce tracking. WARNING! This can lead to performance issues on large sites with lots of traffic!', 'duracelltomi-google-tag-manager' ),
503
- 'phase' => GTM4WP_PHASE_BETA,
504
- 'plugintocheck' => 'woocommerce/woocommerce.php',
505
  ),
506
  GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY => array(
507
  "label" => __( "Taxonomy to be used for product brands", 'duracelltomi-google-tag-manager' ),
508
  "description" => __( "Select which custom taxonomy is being used to add the brand of products", 'duracelltomi-google-tag-manager' ),
509
- "phase" => GTM4WP_PHASE_BETA,
510
- "plugintocheck" => "woocommerce/woocommerce.php"
511
  ),
512
  GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA => array(
513
  'label' => __( 'Customer data in data layer', 'duracelltomi-google-tag-manager' ),
514
  'description' => __( 'Enable this to add all customer data (billing and shipping data, total number of orders and order value) into the data layer (WooCommerce 3.x required)', 'duracelltomi-google-tag-manager' ),
515
- 'phase' => GTM4WP_PHASE_BETA,
516
- 'plugintocheck' => 'woocommerce/woocommerce.php',
517
  ),
518
  GTM4WP_OPTION_INTEGRATE_WCORDERDATA => array(
519
  'label' => __( 'Order data in data layer', 'duracelltomi-google-tag-manager' ),
520
  'description' => __( 'Enable this to add all order attribute into the data layer on the order received page regardless and independently from classic and enhanced ecommerce tracking (WooCommerce 3.x required)', 'duracelltomi-google-tag-manager' ),
521
- 'phase' => GTM4WP_PHASE_BETA,
522
- 'plugintocheck' => 'woocommerce/woocommerce.php',
523
  ),
524
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => array(
525
  'label' => __( 'Exclude tax from revenue', 'duracelltomi-google-tag-manager' ),
526
  'description' => __( 'Enable this to exclude tax from the revenue variable while generating the purchase data', 'duracelltomi-google-tag-manager' ),
527
- 'phase' => GTM4WP_PHASE_BETA,
528
- 'plugintocheck' => 'woocommerce/woocommerce.php',
529
  ),
530
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING => array(
531
  'label' => __( 'Exclude shipping from revenue', 'duracelltomi-google-tag-manager' ),
532
  'description' => __( 'Enable this to exclude shipping costs from the revenue variable while generating the purchase data', 'duracelltomi-google-tag-manager' ),
533
- 'phase' => GTM4WP_PHASE_BETA,
534
- 'plugintocheck' => 'woocommerce/woocommerce.php',
535
  ),
536
  GTM4WP_OPTION_INTEGRATE_WCREMARKETING => array(
537
  'label' => __( 'Google Ads Remarketing', 'duracelltomi-google-tag-manager' ),
538
  'description' => __( 'Enable this to add Google Ads dynamic remarketing variables to the dataLayer', 'duracelltomi-google-tag-manager' ),
539
- 'phase' => GTM4WP_PHASE_BETA,
540
- 'plugintocheck' => 'woocommerce/woocommerce.php',
541
  ),
542
  GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => array(
543
  'label' => __( 'Product ID prefix', 'duracelltomi-google-tag-manager' ),
544
  'description' => __( "Some product feed generator plugins prefix product IDs with a fixed text like 'woocommerce_gpf'. You can enter this prefix here so that tags in your website include this prefix as well.", 'duracelltomi-google-tag-manager' ),
545
- 'phase' => GTM4WP_PHASE_BETA,
546
- 'plugintocheck' => 'woocommerce/woocommerce.php',
547
  ),
548
  GTM4WP_OPTION_INTEGRATE_WCUSESKU => array(
549
  'label' => __( 'Use SKU instead of ID', 'duracelltomi-google-tag-manager' ),
550
  'description' => __( 'Check this to use product SKU instead of the ID of the products for remarketing and ecommerce tracking. Will fallback to ID if no SKU is set.', 'duracelltomi-google-tag-manager' ),
551
- 'phase' => GTM4WP_PHASE_BETA,
552
- 'plugintocheck' => 'woocommerce/woocommerce.php',
553
  ),
554
  GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG => array(
555
  'label' => __( 'Do not flag orders as being tracked', 'duracelltomi-google-tag-manager' ),
@@ -558,8 +356,7 @@ $GLOBALS['gtm4wp_integratefieldtexts'] = array(
558
  'multiple times in any ad or measurement system so please only enable this feature if you really need it (with iDeal you might need this)!',
559
  'duracelltomi-google-tag-manager'
560
  ),
561
- 'phase' => GTM4WP_PHASE_BETA,
562
- 'plugintocheck' => 'woocommerce/woocommerce.php',
563
  ),
564
 
565
  GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => array(
@@ -567,7 +364,7 @@ $GLOBALS['gtm4wp_integratefieldtexts'] = array(
567
  'description' => sprintf(
568
  __(
569
  'Enter a comma separated list of Google Optimize container IDs that you would like to use on your site.<br />' .
570
- 'This plugin will add the <a href="%s">page-hiding snippet</a> to your pages.<br /><br />',
571
  'duracelltomi-google-tag-manager'
572
  ),
573
  'https://developers.google.com/optimize/#the_page-hiding_snippet_code'
@@ -580,6 +377,7 @@ $GLOBALS['gtm4wp_integratefieldtexts'] = array(
580
  'description' => __( 'Enter here the amount of time in milliseconds that the page-hiding snippet should wait before page content gets visible even if Google Optimize has not been completely loaded yet.', 'duracelltomi-google-tag-manager' ),
581
  'phase' => GTM4WP_PHASE_EXPERIMENTAL,
582
  ),
 
583
  GTM4WP_OPTION_INTEGRATE_AMPID => array(
584
  'label' => __( "Google Tag Manager 'AMP' Container ID", 'duracelltomi-google-tag-manager' ),
585
  'description' => sprintf( __( 'Enter a comma separated list of Google Tag Manager container IDs that you would like to use on your site. This plugin will add the <a href="%s">AMP GTM snippet</a> to your AMP pages.', 'duracelltomi-google-tag-manager' ), 'https://support.google.com/tagmanager/answer/6103696?hl=en' ) .
@@ -631,19 +429,12 @@ function gtm4wp_admin_output_section( $args ) {
631
  _e( 'Here you can check what data is needed to be included in the dataLayer to be able to access them in Google Tag Manager', 'duracelltomi-google-tag-manager' );
632
  echo '<br />';
633
  printf( __( '* Browser, OS and Device data is provided using <a href="%s">WhichBrowser</a> library.', 'duracelltomi-google-tag-manager' ), 'http://whichbrowser.net/' );
634
- if ( version_compare( PHP_VERSION, '5.4.0' ) < 0 ) {
635
- echo '<br />';
636
- _e( 'You are using an <strong>outdated</strong> version of PHP (v' . PHP_VERSION . '). You <strong>should not turn on</strong> browser/device/os tracking as this can hurt your site. Please talk to your hosting and upgrade to PHP 5.4 or newer.', 'duracelltomi-google-tag-manager' );
637
- }
638
 
639
  break;
640
  }
641
 
642
  case GTM4WP_ADMIN_GROUP_EVENTS: {
643
  _e( 'Fire tags in Google Tag Manager on special events on your website', 'duracelltomi-google-tag-manager' );
644
- echo '<p style="font-weight: bold;">';
645
- _e( 'In October 2013 Google released a new feature called <a href="https://support.google.com/tagmanager/answer/3415369?hl=en" target="_blank">auto event tracking</a>. It is up to you how you use click events either using Google\'s solution or the settings below.', 'duracelltomi-google-tag-manager' );
646
- echo '</p>';
647
 
648
  break;
649
  }
@@ -657,13 +448,11 @@ function gtm4wp_admin_output_section( $args ) {
657
  }
658
 
659
  case GTM4WP_ADMIN_GROUP_BLACKLIST: {
660
- _e( 'Here you can control which types of tags and macros can be executed on your site regardless of what tags are included in your container on the Google Tag Manager site. Use this to increase security!', 'duracelltomi-google-tag-manager' );
661
- echo '<br />';
662
- _e( 'Do not modify if you do not know what to do since it can cause issues in your tag deployment!', 'duracelltomi-google-tag-manager' );
663
  echo '<br />';
664
- _e( 'Blacklisting of macros only work if you enable blacklist or whilelist of tags on the previous tab.', 'duracelltomi-google-tag-manager' );
665
  echo '<br />';
666
- _e( 'Uncheck a row to blacklist a macro type.', 'duracelltomi-google-tag-manager' );
667
 
668
  break;
669
  }
@@ -766,8 +555,8 @@ function gtm4wp_admin_output_field( $args ) {
766
 
767
  case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']': {
768
  echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_0" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="0" ' . ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 0 ? 'checked="checked"' : '' ) . '/> ' . __( 'Disable feature: control everything on Google Tag Manager interface', 'duracelltomi-google-tag-manager' ) . '<br />';
769
- echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_1" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="1" ' . ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 1 ? 'checked="checked"' : '' ) . '/> ' . __( 'Allow all, except the checked items below (blacklist)', 'duracelltomi-google-tag-manager' ) . '<br />';
770
- echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_2" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="2" ' . ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 2 ? 'checked="checked"' : '' ) . '/> ' . __( 'Block all, except the checked items below (whitelist)', 'duracelltomi-google-tag-manager' ) . '<br />';
771
  echo $args['description'];
772
 
773
  break;
@@ -807,60 +596,63 @@ function gtm4wp_admin_output_field( $args ) {
807
  }
808
 
809
  default: {
810
- $optval = $gtm4wp_options[ $args['optionfieldid'] ];
811
-
812
- // fix wrong data type saved in v0.4
813
- if ( GTM4WP_OPTION_EVENTS_SOCIAL == $args['optionfieldid'] ) {
814
- $optval = (bool) ( $optval );
815
- }
816
-
817
- switch ( gettype( $optval ) ) {
818
- case 'boolean': {
819
- echo '<input type="checkbox" id="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" name="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" value="1" ' . checked( 1, $optval, false ) . ' /><br />' . $args['description'];
820
-
821
- if ( isset( $args['plugintocheck'] ) && ( $args['plugintocheck'] != '' ) ) {
822
- if ( is_plugin_active( $args['plugintocheck'] ) ) {
823
- echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recommended to enable this integration!', 'duracelltomi-google-tag-manager' );
824
- } else {
825
- sprintf( __( "This plugin (%s) is <strong class='gtm4wp-plugin-not-active'>not active</strong>, enabling this integration could cause issues on frontend!", "duracelltomi-google-tag-manager" ), $args['plugintocheck'] );
 
 
 
826
  }
827
- }
828
 
829
- break;
830
- }
831
 
832
- case 'integer': {
833
- echo '<input type="number" step="1" min="0" class="small-text" id="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" name="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" value="' . esc_attr( $optval ) . '" /><br />' . $args['description'];
834
 
835
- if ( isset( $args['plugintocheck'] ) && ( $args['plugintocheck'] != '' ) ) {
836
- if ( is_plugin_active( $args['plugintocheck'] ) ) {
837
- echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recommended to enable this integration!', 'duracelltomi-google-tag-manager' );
838
- } else {
839
- echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-not-active">not active</strong>, enabling this integration could cause issues on frontend!', 'duracelltomi-google-tag-manager' );
 
840
  }
841
- }
842
 
843
- break;
844
- }
845
 
846
- default : {
847
- echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" name="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" value="' . esc_attr( $optval ) . '" size="80" /><br />' . $args['description'];
848
 
849
- if ( isset( $args['plugintocheck'] ) && ( $args['plugintocheck'] != '' ) ) {
850
- if ( is_plugin_active( $args['plugintocheck'] ) ) {
851
- echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recommended to enable this integration!', 'duracelltomi-google-tag-manager' );
852
- } else {
853
- echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-not-active">not active</strong>, enabling this integration could cause issues on frontend!', 'duracelltomi-google-tag-manager' );
 
854
  }
855
  }
856
- }
857
- } // end switch gettype optval
858
  }
859
  } // end switch
860
  }
861
 
862
  function gtm4wp_sanitize_options( $options ) {
863
- global $wpdb;
864
 
865
  $output = gtm4wp_reload_options();
866
 
@@ -875,11 +667,7 @@ function gtm4wp_sanitize_options( $options ) {
875
  if ( substr( $optionname, 0, 8 ) == 'include-' ) {
876
  $output[ $optionname ] = (bool) $newoptionvalue;
877
 
878
- // tracked download extensions
879
- } elseif ( $optionname == GTM4WP_OPTION_EVENTS_DWLEXT ) {
880
- $output[ $optionname ] = str_replace( ' ', '', trim( $newoptionvalue ) );
881
-
882
- // dataLayer events
883
  } elseif ( substr( $optionname, 0, 6 ) == 'event-' ) {
884
  $output[ $optionname ] = (bool) $newoptionvalue;
885
 
@@ -894,7 +682,28 @@ function gtm4wp_sanitize_options( $options ) {
894
  }
895
  }
896
 
897
- // Google Optimize settings
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
898
  } elseif ( $optionname == GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ) {
899
  $_goid_val = trim( $newoptionvalue );
900
  if ( '' == $_goid_val ) {
@@ -913,7 +722,6 @@ function gtm4wp_sanitize_options( $options ) {
913
  } else {
914
  $output[ $optionname ] = $newoptionvalue;
915
  }
916
-
917
  } elseif ( $optionname == GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT ) {
918
  $output[ $optionname ] = (int) $newoptionvalue;
919
 
@@ -926,7 +734,7 @@ function gtm4wp_sanitize_options( $options ) {
926
  } else if ( $optionname == GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ) {
927
  $output[$optionname] = trim( (string) $newoptionvalue );
928
 
929
- // Accelerated Mobile Pages settings
930
  } elseif ( $optionname == GTM4WP_OPTION_INTEGRATE_AMPID ) {
931
  $_ampid_val = trim( $newoptionvalue );
932
  if ( '' == $_ampid_val ) {
@@ -946,11 +754,11 @@ function gtm4wp_sanitize_options( $options ) {
946
  $output[ $optionname ] = $newoptionvalue;
947
  }
948
 
949
- // integrations
950
  } elseif ( substr( $optionname, 0, 10 ) == 'integrate-' ) {
951
  $output[ $optionname ] = (bool) $newoptionvalue;
952
 
953
- // GTM code or dataLayer variable name
954
  } elseif ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) || ( $optionname == GTM4WP_OPTION_DATALAYER_NAME ) || ( $optionname == GTM4WP_OPTION_ENV_GTM_AUTH ) || ( $optionname == GTM4WP_OPTION_ENV_GTM_PREVIEW ) ) {
955
  $newoptionvalue = trim( $newoptionvalue );
956
 
@@ -980,18 +788,18 @@ function gtm4wp_sanitize_options( $options ) {
980
  $output[ $optionname ] = $newoptionvalue;
981
  }
982
 
983
- // GTM container code placement
984
  } elseif ( $optionname == GTM4WP_OPTION_GTM_PLACEMENT ) {
985
  $output[ $optionname ] = (int) $newoptionvalue;
986
  if ( ( $output[ $optionname ] < 0 ) || ( $output[ $optionname ] > 3 ) ) {
987
  $output[ $optionname ] = 0;
988
  }
989
 
990
- // scroll tracking content ID
991
  } elseif ( $optionname == GTM4WP_OPTION_SCROLLER_CONTENTID ) {
992
  $output[ $optionname ] = trim( str_replace( '#', '', $newoptionvalue ) );
993
 
994
- // anything else
995
  } else {
996
  switch ( gettype( $optionvalue ) ) {
997
  case 'boolean': {
@@ -1018,7 +826,7 @@ function gtm4wp_sanitize_options( $options ) {
1018
 
1019
  function gtm4wp_admin_init() {
1020
  global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts, $gtm4wp_scrollerfieldtexts,
1021
- $gtm4wp_blacklistfieldtexts, $gtm4wp_blacklistmfieldtexts, $gtm4wp_advancedfieldtexts;
1022
 
1023
  register_setting( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS, 'gtm4wp_sanitize_options' );
1024
 
@@ -1043,14 +851,13 @@ function gtm4wp_admin_init() {
1043
 
1044
  add_settings_field(
1045
  GTM4WP_ADMIN_GROUP_PLACEMENT,
1046
- __( 'Container code placement', 'duracelltomi-google-tag-manager' ),
1047
  'gtm4wp_admin_output_field',
1048
  GTM4WP_ADMINSLUG,
1049
  GTM4WP_ADMIN_GROUP_GENERAL,
1050
  array(
1051
  'label_for' => GTM4WP_ADMIN_GROUP_PLACEMENT,
1052
- // "description" => __( "Select how your container code should be included in your website.<br />If you select 'Custom' you need to edit your template file and add the following line just after the opening &lt;body&gt; tag:<br /><code>&lt;?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?&gt;</code>", 'duracelltomi-google-tag-manager' )
1053
- 'description' => __( "Code placement decides where to put the second, so called noscript part of the GTM container code.<br />This code is usually only executed if your visitor has for some reason disabled JavaScript.<br/>The main GTM container code will be placed into the <code>&lt;head&gt;</code> section of your webpages anyway (where it belongs to).<br />If you select 'Custom' you need to edit your template file and add the following line just after the opening <code>&lt;body&gt;</code> tag:<br /><code>&lt;?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?&gt;</code>", 'duracelltomi-google-tag-manager' ),
1054
  )
1055
  );
1056
 
@@ -1062,9 +869,11 @@ function gtm4wp_admin_init() {
1062
  );
1063
 
1064
  foreach ( $gtm4wp_includefieldtexts as $fieldid => $fielddata ) {
 
 
1065
  add_settings_field(
1066
  'gtm4wp-admin-' . $fieldid . '-id',
1067
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1068
  'gtm4wp_admin_output_field',
1069
  GTM4WP_ADMINSLUG,
1070
  GTM4WP_ADMIN_GROUP_INCLUDES,
@@ -1084,9 +893,11 @@ function gtm4wp_admin_init() {
1084
  );
1085
 
1086
  foreach ( $gtm4wp_eventfieldtexts as $fieldid => $fielddata ) {
 
 
1087
  add_settings_field(
1088
  'gtm4wp-admin-' . $fieldid . '-id',
1089
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1090
  'gtm4wp_admin_output_field',
1091
  GTM4WP_ADMINSLUG,
1092
  GTM4WP_ADMIN_GROUP_EVENTS,
@@ -1106,9 +917,11 @@ function gtm4wp_admin_init() {
1106
  );
1107
 
1108
  foreach ( $gtm4wp_scrollerfieldtexts as $fieldid => $fielddata ) {
 
 
1109
  add_settings_field(
1110
  'gtm4wp-admin-' . $fieldid . '-id',
1111
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1112
  'gtm4wp_admin_output_field',
1113
  GTM4WP_ADMINSLUG,
1114
  GTM4WP_ADMIN_GROUP_SCROLLER,
@@ -1122,39 +935,52 @@ function gtm4wp_admin_init() {
1122
 
1123
  add_settings_section(
1124
  GTM4WP_ADMIN_GROUP_BLACKLIST,
1125
- __( 'Blacklist tags', 'duracelltomi-google-tag-manager' ),
1126
  'gtm4wp_admin_output_section',
1127
  GTM4WP_ADMINSLUG
1128
  );
1129
 
1130
- foreach ( $gtm4wp_blacklistfieldtexts as $fieldid => $fielddata ) {
1131
- add_settings_field(
1132
- 'gtm4wp-admin-' . $fieldid . '-id',
1133
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1134
- 'gtm4wp_admin_output_field',
1135
- GTM4WP_ADMINSLUG,
1136
- GTM4WP_ADMIN_GROUP_BLACKLIST,
1137
- array(
1138
- 'label_for' => 'gtm4wp-options[' . $fieldid . ']',
1139
- 'description' => $fielddata['description'],
1140
- 'optionfieldid' => $fieldid,
1141
- )
1142
- );
1143
- }
1144
 
1145
- foreach ( $gtm4wp_blacklistmfieldtexts as $fieldid => $fielddata ) {
1146
- add_settings_field(
1147
- 'gtm4wp-admin-' . $fieldid . '-id',
1148
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1149
- 'gtm4wp_admin_output_field',
1150
- GTM4WP_ADMINSLUG,
1151
- GTM4WP_ADMIN_GROUP_BLACKLIST,
1152
- array(
1153
- 'label_for' => 'gtm4wp-options[' . $fieldid . ']',
1154
- 'description' => $fielddata['description'],
1155
- 'optionfieldid' => $fieldid,
1156
- )
1157
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1158
  }
1159
 
1160
  add_settings_section(
@@ -1165,9 +991,11 @@ function gtm4wp_admin_init() {
1165
  );
1166
 
1167
  foreach ( $gtm4wp_integratefieldtexts as $fieldid => $fielddata ) {
 
 
1168
  add_settings_field(
1169
  'gtm4wp-admin-' . $fieldid . '-id',
1170
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1171
  'gtm4wp_admin_output_field',
1172
  GTM4WP_ADMINSLUG,
1173
  GTM4WP_ADMIN_GROUP_INTEGRATION,
@@ -1188,9 +1016,11 @@ function gtm4wp_admin_init() {
1188
  );
1189
 
1190
  foreach ( $gtm4wp_advancedfieldtexts as $fieldid => $fielddata ) {
 
 
1191
  add_settings_field(
1192
  'gtm4wp-admin-' . $fieldid . '-id',
1193
- $fielddata['label'] . '<span class="' . $fielddata['phase'] . '"></span>',
1194
  'gtm4wp_admin_output_field',
1195
  GTM4WP_ADMINSLUG,
1196
  GTM4WP_ADMIN_GROUP_ADVANCED,
@@ -1271,7 +1101,8 @@ function gtm4wp_add_admin_js( $hook ) {
1271
  'adwordstabtitle' => __( 'Google Ads', 'duracelltomi-google-tag-manager' ),
1272
  'browsertabtitle' => __( 'Browser/OS/Device', 'duracelltomi-google-tag-manager' ),
1273
  'blocktagstabtitle' => __( 'Blacklist tags', 'duracelltomi-google-tag-manager' ),
1274
- 'blockmacrostabtitle' => __( 'Blacklist macros', 'duracelltomi-google-tag-manager' ),
 
1275
  'wpcf7tabtitle' => __( 'Contact Form 7', 'duracelltomi-google-tag-manager' ),
1276
  'wctabtitle' => __( 'WooCommerce', 'duracelltomi-google-tag-manager' ),
1277
  'gotabtitle' => __( 'Google Optimize', 'duracelltomi-google-tag-manager' ),
@@ -1514,15 +1345,6 @@ function gtm4wp_show_warning() {
1514
  $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ||
1515
  $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ];
1516
 
1517
- if ( ( false === $gtm4wp_user_notices_dismisses['wc-ga-plugin-warning'] ) && $is_wc_active && $woo && ( version_compare( $woo->version, '2.1' ) < 0 ) ) {
1518
- $woo_ga_options = get_option( 'woocommerce_google_analytics_settings' );
1519
- if ( $woo_ga_options ) {
1520
- if ( '' != $woo_ga_options['ga_id'] ) {
1521
- echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-ga-plugin-warning"><p><strong>' . __( 'Notice: you should disable Google Analytics tracking <a href="admin.php?page=wc-settings&tab=integration&section=google_analytics">in WooCommerce settings</a> by leaving Google Analytics ID field empty if you are using Google Analytics tags inside Google Tag Manager!', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1522
- }
1523
- }
1524
- }
1525
-
1526
  if ( ( false === $gtm4wp_user_notices_dismisses['wc-ga-plugin-warning'] ) && $is_wc_active && is_plugin_active( 'woocommerce-google-analytics-integration/woocommerce-google-analytics-integration.php' ) ) {
1527
  echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-ga-plugin-warning"><p><strong>' . __( 'Notice: you should deactivate the plugin "WooCommerce Google Analytics Integration" if you are using Google Analytics tags inside Google Tag Manager!', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1528
  }
@@ -1535,25 +1357,6 @@ function gtm4wp_show_warning() {
1535
  if ( ( false === $gtm4wp_user_notices_dismisses['php56-warning'] ) && ( version_compare( PHP_VERSION, '5.6.0' ) < 0 ) ) {
1536
  echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?php56-warning"><p><strong>' . __( 'Warning: You are using an outdated version of PHP (v' . PHP_VERSION . ') that can cause issues with the plugin Google Tag Manager for WordPress. Please consider to upgrade your PHP.', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1537
  }
1538
-
1539
- if ( ( false === $gtm4wp_user_notices_dismisses['woo2x-warning'] ) && ( $woo ) && ( version_compare( $woo->version, '3.0', '<' ) ) ) {
1540
- echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?woo2x-warning"><p><strong>' . __( 'Warning: You are using an outdated version of WooCommerce (v' . $woo->version . '). Google Tag Manager for WordPress will drop support for this version in the near future. Please consider to upgrade.', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1541
- }
1542
-
1543
- if ( ( false === $gtm4wp_user_notices_dismisses['deprecated-warning'] ) && (
1544
- ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_SOCIAL ] ) ||
1545
- ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_OUTBOUND ] ) ||
1546
- ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_OUTBOUND ] ) ||
1547
- ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_OUTBOUND ] )
1548
- ) ) {
1549
- $deprecated_list = array(
1550
- 'Social actions',
1551
- 'Outbound link click events',
1552
- 'Download click events',
1553
- 'Email click events',
1554
- );
1555
- echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?deprecated-warning"><p><strong>' . __( 'Warning: Some features of Google Tag Manager for WordPress are deprecated and will be removed in the next version: <ul><li>' . implode( '</li><li>', $deprecated_list ) . '</li></ul>', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1556
- }
1557
  }
1558
 
1559
  function gtm4wp_dismiss_notice() {
27
  'wc-ga-plugin-warning' => false,
28
  'wc-gayoast-plugin-warning' => false,
29
  'php56-warning' => false,
 
30
  'deprecated-warning' => false,
31
  );
32
 
129
  GTM4WP_OPTION_INCLUDE_REMARKETING => array(
130
  'label' => __( 'Remarketing variable', 'duracelltomi-google-tag-manager' ),
131
  'description' => __( 'Check this option to include a dataLayer variable where all dataLayer values are stored to be included in your Google Ads remarketing tag as a custom variable field', 'duracelltomi-google-tag-manager' ),
132
+ 'phase' => GTM4WP_PHASE_DEPRECATED,
133
  ),
134
  GTM4WP_OPTION_INCLUDE_BROWSERDATA => array(
135
  'label' => __( 'Browser data *', 'duracelltomi-google-tag-manager' ),
136
+ 'description' => __( 'Check this option to include the name, version and engine data of the browser the visitor uses.', 'duracelltomi-google-tag-manager' )
 
137
  ),
138
  GTM4WP_OPTION_INCLUDE_OSDATA => array(
139
  'label' => __( 'OS data *', 'duracelltomi-google-tag-manager' ),
140
+ 'description' => __( 'Check this option to include the name and version of the operating system the visitor uses.', 'duracelltomi-google-tag-manager' )
 
141
  ),
142
  GTM4WP_OPTION_INCLUDE_DEVICEDATA => array(
143
  'label' => __( 'Device data *', 'duracelltomi-google-tag-manager' ),
144
+ 'description' => __( 'Check this option to include the type of device the user is currently using (desktop, tablet or mobile) including manufacturer and model data.', 'duracelltomi-google-tag-manager' )
 
145
  ),
146
  GTM4WP_OPTION_INCLUDE_MISCGEO => array(
147
  'label' => __( 'Geo data', 'duracelltomi-google-tag-manager' ),
228
  'label' => __( 'Soundcloud events', 'duracelltomi-google-tag-manager' ),
229
  'description' => __( 'Check this option to include a Tag Manager event when a visitor interacts with a Soundcloud media embeded on your site.', 'duracelltomi-google-tag-manager' ),
230
  'phase' => GTM4WP_PHASE_EXPERIMENTAL,
231
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
232
  );
233
 
234
  $GLOBALS['gtm4wp_scrollerfieldtexts'] = array(
264
  ),
265
  );
266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
  $GLOBALS['gtm4wp_integratefieldtexts'] = array(
268
  GTM4WP_OPTION_INTEGRATE_WPCF7 => array(
269
  'label' => __( 'Contact Form 7', 'duracelltomi-google-tag-manager' ),
274
  GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => array(
275
  'label' => __( 'Track classic e-commerce', 'duracelltomi-google-tag-manager' ),
276
  'description' => sprintf( __( 'Choose this option if you would like to track e-commerce data using <a href="%s" target="_blank">classic transaction data</a>.', 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce' ),
277
+ 'phase' => GTM4WP_PHASE_DEPRECATED,
278
  'plugintocheck' => 'woocommerce/woocommerce.php',
279
  ),
280
  GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => array(
281
  'label' => __( 'Track enhanced e-commerce', 'duracelltomi-google-tag-manager' ),
282
  'description' => sprintf( __( 'Choose this option if you would like to track e-commerce data using <a href="%s" target="_blank">enhanced ecommerce tracking</a>.', 'duracelltomi-google-tag-manager' ), 'https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce' ),
283
+ 'phase' => GTM4WP_PHASE_STABLE,
284
  'plugintocheck' => 'woocommerce/woocommerce.php',
285
  ),
286
  GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION => array(
292
  "tag's trigger.<br /><br />Leave this value 0 to include product impression data in your pageview hit.",
293
  'duracelltomi-google-tag-manager'
294
  ),
295
+ 'phase' => GTM4WP_PHASE_STABLE
 
296
  ),
297
  GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP => array(
298
  'label' => __( 'Cart as 1st checkout step', 'duracelltomi-google-tag-manager' ),
299
  'description' => __( 'Enable this to track the cart page as the first checkout step in enhanced ecommerce instead of the checkout page itself', 'duracelltomi-google-tag-manager' ),
300
+ 'phase' => GTM4WP_PHASE_STABLE
 
301
  ),
302
  GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL => array(
303
  "label" => __( "Cart content in data layer", 'duracelltomi-google-tag-manager' ),
304
  "description" => __( "Enable this option to include the content of the cart in the data layer on each page. Needs WooCommerce v3.2 or newer. Especially useful for site personalization with Google Optimize.", 'duracelltomi-google-tag-manager' ),
305
+ "phase" => GTM4WP_PHASE_STABLE
 
306
  ),
307
  GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH => array(
308
  'label' => __( 'Include full category path.', 'duracelltomi-google-tag-manager' ),
309
  'description' => __( 'Check this to inclulde the full category path of each product in enhanced ecommerce tracking. WARNING! This can lead to performance issues on large sites with lots of traffic!', 'duracelltomi-google-tag-manager' ),
310
+ 'phase' => GTM4WP_PHASE_STABLE
 
311
  ),
312
  GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY => array(
313
  "label" => __( "Taxonomy to be used for product brands", 'duracelltomi-google-tag-manager' ),
314
  "description" => __( "Select which custom taxonomy is being used to add the brand of products", 'duracelltomi-google-tag-manager' ),
315
+ "phase" => GTM4WP_PHASE_STABLE
 
316
  ),
317
  GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA => array(
318
  'label' => __( 'Customer data in data layer', 'duracelltomi-google-tag-manager' ),
319
  'description' => __( 'Enable this to add all customer data (billing and shipping data, total number of orders and order value) into the data layer (WooCommerce 3.x required)', 'duracelltomi-google-tag-manager' ),
320
+ 'phase' => GTM4WP_PHASE_STABLE
 
321
  ),
322
  GTM4WP_OPTION_INTEGRATE_WCORDERDATA => array(
323
  'label' => __( 'Order data in data layer', 'duracelltomi-google-tag-manager' ),
324
  'description' => __( 'Enable this to add all order attribute into the data layer on the order received page regardless and independently from classic and enhanced ecommerce tracking (WooCommerce 3.x required)', 'duracelltomi-google-tag-manager' ),
325
+ 'phase' => GTM4WP_PHASE_STABLE
 
326
  ),
327
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => array(
328
  'label' => __( 'Exclude tax from revenue', 'duracelltomi-google-tag-manager' ),
329
  'description' => __( 'Enable this to exclude tax from the revenue variable while generating the purchase data', 'duracelltomi-google-tag-manager' ),
330
+ 'phase' => GTM4WP_PHASE_STABLE
 
331
  ),
332
  GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING => array(
333
  'label' => __( 'Exclude shipping from revenue', 'duracelltomi-google-tag-manager' ),
334
  'description' => __( 'Enable this to exclude shipping costs from the revenue variable while generating the purchase data', 'duracelltomi-google-tag-manager' ),
335
+ 'phase' => GTM4WP_PHASE_STABLE
 
336
  ),
337
  GTM4WP_OPTION_INTEGRATE_WCREMARKETING => array(
338
  'label' => __( 'Google Ads Remarketing', 'duracelltomi-google-tag-manager' ),
339
  'description' => __( 'Enable this to add Google Ads dynamic remarketing variables to the dataLayer', 'duracelltomi-google-tag-manager' ),
340
+ 'phase' => GTM4WP_PHASE_DEPRECATED
 
341
  ),
342
  GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => array(
343
  'label' => __( 'Product ID prefix', 'duracelltomi-google-tag-manager' ),
344
  'description' => __( "Some product feed generator plugins prefix product IDs with a fixed text like 'woocommerce_gpf'. You can enter this prefix here so that tags in your website include this prefix as well.", 'duracelltomi-google-tag-manager' ),
345
+ 'phase' => GTM4WP_PHASE_STABLE
 
346
  ),
347
  GTM4WP_OPTION_INTEGRATE_WCUSESKU => array(
348
  'label' => __( 'Use SKU instead of ID', 'duracelltomi-google-tag-manager' ),
349
  'description' => __( 'Check this to use product SKU instead of the ID of the products for remarketing and ecommerce tracking. Will fallback to ID if no SKU is set.', 'duracelltomi-google-tag-manager' ),
350
+ 'phase' => GTM4WP_PHASE_STABLE
 
351
  ),
352
  GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG => array(
353
  'label' => __( 'Do not flag orders as being tracked', 'duracelltomi-google-tag-manager' ),
356
  'multiple times in any ad or measurement system so please only enable this feature if you really need it (with iDeal you might need this)!',
357
  'duracelltomi-google-tag-manager'
358
  ),
359
+ 'phase' => GTM4WP_PHASE_STABLE
 
360
  ),
361
 
362
  GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => array(
364
  'description' => sprintf(
365
  __(
366
  'Enter a comma separated list of Google Optimize container IDs that you would like to use on your site.<br />' .
367
+ 'This plugin will add the <a href="%s">page-hiding snippet</a> to your pages.<br />',
368
  'duracelltomi-google-tag-manager'
369
  ),
370
  'https://developers.google.com/optimize/#the_page-hiding_snippet_code'
377
  'description' => __( 'Enter here the amount of time in milliseconds that the page-hiding snippet should wait before page content gets visible even if Google Optimize has not been completely loaded yet.', 'duracelltomi-google-tag-manager' ),
378
  'phase' => GTM4WP_PHASE_EXPERIMENTAL,
379
  ),
380
+
381
  GTM4WP_OPTION_INTEGRATE_AMPID => array(
382
  'label' => __( "Google Tag Manager 'AMP' Container ID", 'duracelltomi-google-tag-manager' ),
383
  'description' => sprintf( __( 'Enter a comma separated list of Google Tag Manager container IDs that you would like to use on your site. This plugin will add the <a href="%s">AMP GTM snippet</a> to your AMP pages.', 'duracelltomi-google-tag-manager' ), 'https://support.google.com/tagmanager/answer/6103696?hl=en' ) .
429
  _e( 'Here you can check what data is needed to be included in the dataLayer to be able to access them in Google Tag Manager', 'duracelltomi-google-tag-manager' );
430
  echo '<br />';
431
  printf( __( '* Browser, OS and Device data is provided using <a href="%s">WhichBrowser</a> library.', 'duracelltomi-google-tag-manager' ), 'http://whichbrowser.net/' );
 
 
 
 
432
 
433
  break;
434
  }
435
 
436
  case GTM4WP_ADMIN_GROUP_EVENTS: {
437
  _e( 'Fire tags in Google Tag Manager on special events on your website', 'duracelltomi-google-tag-manager' );
 
 
 
438
 
439
  break;
440
  }
448
  }
449
 
450
  case GTM4WP_ADMIN_GROUP_BLACKLIST: {
451
+ _e( 'Here you can control which types of tags, triggers and variables can be executed on your site regardless of what tags are included in your container on the Google Tag Manager site. Use this to increase security!', 'duracelltomi-google-tag-manager' );
 
 
452
  echo '<br />';
453
+ _e( 'Do not modify if you do not know what to do, since it can cause issues with your tag deployment!', 'duracelltomi-google-tag-manager' );
454
  echo '<br />';
455
+ _e( 'For example blacklisting everything and only whitelisting the Google Analytics tag without whitelisting the URL variable type will cause your Google Analytics tags to be blocked anyway since the attached triggers (Page View) can not fire!', 'duracelltomi-google-tag-manager' );
456
 
457
  break;
458
  }
555
 
556
  case GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']': {
557
  echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_0" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="0" ' . ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 0 ? 'checked="checked"' : '' ) . '/> ' . __( 'Disable feature: control everything on Google Tag Manager interface', 'duracelltomi-google-tag-manager' ) . '<br />';
558
+ echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_1" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="1" ' . ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 1 ? 'checked="checked"' : '' ) . '/> ' . __( 'Allow all, except the checked items on all blacklist tabs (blacklist)', 'duracelltomi-google-tag-manager' ) . '<br />';
559
+ echo '<input type="radio" id="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']_2" name="' . GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']" value="2" ' . ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 2 ? 'checked="checked"' : '' ) . '/> ' . __( 'Block all, except the checked items on all blacklist tabs (whitelist)', 'duracelltomi-google-tag-manager' ) . '<br />';
560
  echo $args['description'];
561
 
562
  break;
596
  }
597
 
598
  default: {
599
+ if ( preg_match( '/' . GTM4WP_OPTIONS . "\\[blacklist\\-[^\\]]+\\]/i", $args['label_for'] ) ) {
600
+ if ( 'blacklist-sandboxed' == $args['entityid'] ) {
601
+ echo '<input type="checkbox" id="' . $args['label_for'] . '" name="' . $args['label_for'] . '" value="1" ' . checked( 1, $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_SANDBOXED ], false ) . ' /><br />' . $args['description'];
602
+ } else {
603
+ echo '<input type="checkbox" id="' . $args['label_for'] . '" name="' . $args['label_for'] . '" value="1" ' . checked( 1, in_array( $args['entityid'], $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_STATUS ] ), false ) . ' /><br />' . $args['description'];
604
+ }
605
+ } else {
606
+ $optval = $gtm4wp_options[ $args['optionfieldid'] ];
607
+
608
+ switch ( gettype( $optval ) ) {
609
+ case 'boolean': {
610
+ echo '<input type="checkbox" id="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" name="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" value="1" ' . checked( 1, $optval, false ) . ' /><br />' . $args['description'];
611
+
612
+ if ( isset( $args['plugintocheck'] ) && ( $args['plugintocheck'] != '' ) ) {
613
+ if ( is_plugin_active( $args['plugintocheck'] ) ) {
614
+ echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recommended to enable this integration!', 'duracelltomi-google-tag-manager' );
615
+ } else {
616
+ echo '<br />' . __( 'This plugin (' . $args['plugintocheck'] . ') is <strong class="gtm4wp-plugin-not-active">not active</strong>, enabling this integration could cause issues on frontend!', 'duracelltomi-google-tag-manager' );
617
+ }
618
  }
 
619
 
620
+ break;
621
+ }
622
 
623
+ case 'integer': {
624
+ echo '<input type="number" step="1" min="0" class="small-text" id="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" name="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" value="' . esc_attr( $optval ) . '" /><br />' . $args['description'];
625
 
626
+ if ( isset( $args['plugintocheck'] ) && ( $args['plugintocheck'] != '' ) ) {
627
+ if ( is_plugin_active( $args['plugintocheck'] ) ) {
628
+ echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recommended to enable this integration!', 'duracelltomi-google-tag-manager' );
629
+ } else {
630
+ echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-not-active">not active</strong>, enabling this integration could cause issues on frontend!', 'duracelltomi-google-tag-manager' );
631
+ }
632
  }
 
633
 
634
+ break;
635
+ }
636
 
637
+ default : {
638
+ echo '<input type="text" id="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" name="' . GTM4WP_OPTIONS . '[' . $args['optionfieldid'] . ']" value="' . esc_attr( $optval ) . '" size="80" /><br />' . $args['description'];
639
 
640
+ if ( isset( $args['plugintocheck'] ) && ( $args['plugintocheck'] != '' ) ) {
641
+ if ( is_plugin_active( $args['plugintocheck'] ) ) {
642
+ echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-active">active</strong>, it is strongly recommended to enable this integration!', 'duracelltomi-google-tag-manager' );
643
+ } else {
644
+ echo '<br />' . __( 'This plugin is <strong class="gtm4wp-plugin-not-active">not active</strong>, enabling this integration could cause issues on frontend!', 'duracelltomi-google-tag-manager' );
645
+ }
646
  }
647
  }
648
+ } // end switch gettype optval
649
+ }
650
  }
651
  } // end switch
652
  }
653
 
654
  function gtm4wp_sanitize_options( $options ) {
655
+ global $wpdb, $gtm4wp_entity_ids;
656
 
657
  $output = gtm4wp_reload_options();
658
 
667
  if ( substr( $optionname, 0, 8 ) == 'include-' ) {
668
  $output[ $optionname ] = (bool) $newoptionvalue;
669
 
670
+ // dataLayer events
 
 
 
 
671
  } elseif ( substr( $optionname, 0, 6 ) == 'event-' ) {
672
  $output[ $optionname ] = (bool) $newoptionvalue;
673
 
682
  }
683
  }
684
 
685
+ // blacklist / whitelist entities
686
+ } elseif ( substr( $optionname, 0, 10 ) == 'blacklist-' ) {
687
+ if ( GTM4WP_OPTION_BLACKLIST_ENABLE === $optionname ) {
688
+ $output[ $optionname ] = (int) $options[ GTM4WP_OPTION_BLACKLIST_ENABLE ];
689
+ } else if ( GTM4WP_OPTION_BLACKLIST_SANDBOXED == $optionname ) {
690
+ $output[ $optionname ] = (bool) $options[ GTM4WP_OPTION_BLACKLIST_SANDBOXED ];
691
+ } else if ( GTM4WP_OPTION_BLACKLIST_STATUS == $optionname ) {
692
+ $selected_blacklist_entities = array();
693
+
694
+ foreach( $gtm4wp_entity_ids as $gtm_entity_group_id => $gtm_entity_group_list ) {
695
+ foreach( $gtm_entity_group_list as $gtm_entity_id => $gtm_entity_label ) {
696
+ $newoptionvalue = (bool) $options[ 'blacklist-' . $gtm_entity_group_id . '-' . $gtm_entity_id ];
697
+ if ( $newoptionvalue ) {
698
+ $selected_blacklist_entities[] = $gtm_entity_id;
699
+ }
700
+ }
701
+ }
702
+
703
+ $output[ $optionname ] = implode( ',', $selected_blacklist_entities );
704
+ }
705
+
706
+ // Google Optimize settings
707
  } elseif ( $optionname == GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ) {
708
  $_goid_val = trim( $newoptionvalue );
709
  if ( '' == $_goid_val ) {
722
  } else {
723
  $output[ $optionname ] = $newoptionvalue;
724
  }
 
725
  } elseif ( $optionname == GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT ) {
726
  $output[ $optionname ] = (int) $newoptionvalue;
727
 
734
  } else if ( $optionname == GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY ) {
735
  $output[$optionname] = trim( (string) $newoptionvalue );
736
 
737
+ // Accelerated Mobile Pages settings
738
  } elseif ( $optionname == GTM4WP_OPTION_INTEGRATE_AMPID ) {
739
  $_ampid_val = trim( $newoptionvalue );
740
  if ( '' == $_ampid_val ) {
754
  $output[ $optionname ] = $newoptionvalue;
755
  }
756
 
757
+ // integrations
758
  } elseif ( substr( $optionname, 0, 10 ) == 'integrate-' ) {
759
  $output[ $optionname ] = (bool) $newoptionvalue;
760
 
761
+ // GTM code or dataLayer variable name
762
  } elseif ( ( $optionname == GTM4WP_OPTION_GTM_CODE ) || ( $optionname == GTM4WP_OPTION_DATALAYER_NAME ) || ( $optionname == GTM4WP_OPTION_ENV_GTM_AUTH ) || ( $optionname == GTM4WP_OPTION_ENV_GTM_PREVIEW ) ) {
763
  $newoptionvalue = trim( $newoptionvalue );
764
 
788
  $output[ $optionname ] = $newoptionvalue;
789
  }
790
 
791
+ // GTM container code placement
792
  } elseif ( $optionname == GTM4WP_OPTION_GTM_PLACEMENT ) {
793
  $output[ $optionname ] = (int) $newoptionvalue;
794
  if ( ( $output[ $optionname ] < 0 ) || ( $output[ $optionname ] > 3 ) ) {
795
  $output[ $optionname ] = 0;
796
  }
797
 
798
+ // scroll tracking content ID
799
  } elseif ( $optionname == GTM4WP_OPTION_SCROLLER_CONTENTID ) {
800
  $output[ $optionname ] = trim( str_replace( '#', '', $newoptionvalue ) );
801
 
802
+ // anything else
803
  } else {
804
  switch ( gettype( $optionvalue ) ) {
805
  case 'boolean': {
826
 
827
  function gtm4wp_admin_init() {
828
  global $gtm4wp_includefieldtexts, $gtm4wp_eventfieldtexts, $gtm4wp_integratefieldtexts, $gtm4wp_scrollerfieldtexts,
829
+ $gtm4wp_advancedfieldtexts, $gtm4wp_entity_ids;
830
 
831
  register_setting( GTM4WP_ADMIN_GROUP, GTM4WP_OPTIONS, 'gtm4wp_sanitize_options' );
832
 
851
 
852
  add_settings_field(
853
  GTM4WP_ADMIN_GROUP_PLACEMENT,
854
+ __( 'Container code <code>&lt;noscript&gt;</code> part placement', 'duracelltomi-google-tag-manager' ),
855
  'gtm4wp_admin_output_field',
856
  GTM4WP_ADMINSLUG,
857
  GTM4WP_ADMIN_GROUP_GENERAL,
858
  array(
859
  'label_for' => GTM4WP_ADMIN_GROUP_PLACEMENT,
860
+ 'description' => __( "Code placement decides where to put the second, so called noscript part of the GTM container code.<br />This code is usually only executed if your visitor has for some reason disabled JavaScript.<br/>The main GTM container code will be placed into the <code>&lt;head&gt;</code> section of your webpages anyway (where it belongs to).<br />If you select 'Custom' you need to edit your template file and add the following line just after the opening <code>&lt;body&gt;</code> tag:<br /><code>&lt;?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?&gt;</code>", 'duracelltomi-google-tag-manager' ),
 
861
  )
862
  );
863
 
869
  );
870
 
871
  foreach ( $gtm4wp_includefieldtexts as $fieldid => $fielddata ) {
872
+ $phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
873
+
874
  add_settings_field(
875
  'gtm4wp-admin-' . $fieldid . '-id',
876
+ $fielddata['label'] . '<span class="' . $phase . '"></span>',
877
  'gtm4wp_admin_output_field',
878
  GTM4WP_ADMINSLUG,
879
  GTM4WP_ADMIN_GROUP_INCLUDES,
893
  );
894
 
895
  foreach ( $gtm4wp_eventfieldtexts as $fieldid => $fielddata ) {
896
+ $phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
897
+
898
  add_settings_field(
899
  'gtm4wp-admin-' . $fieldid . '-id',
900
+ $fielddata['label'] . '<span class="' . $phase . '"></span>',
901
  'gtm4wp_admin_output_field',
902
  GTM4WP_ADMINSLUG,
903
  GTM4WP_ADMIN_GROUP_EVENTS,
917
  );
918
 
919
  foreach ( $gtm4wp_scrollerfieldtexts as $fieldid => $fielddata ) {
920
+ $phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
921
+
922
  add_settings_field(
923
  'gtm4wp-admin-' . $fieldid . '-id',
924
+ $fielddata['label'] . '<span class="' . $phase . '"></span>',
925
  'gtm4wp_admin_output_field',
926
  GTM4WP_ADMINSLUG,
927
  GTM4WP_ADMIN_GROUP_SCROLLER,
935
 
936
  add_settings_section(
937
  GTM4WP_ADMIN_GROUP_BLACKLIST,
938
+ __( 'Security', 'duracelltomi-google-tag-manager' ),
939
  'gtm4wp_admin_output_section',
940
  GTM4WP_ADMINSLUG
941
  );
942
 
943
+ add_settings_field(
944
+ GTM4WP_OPTION_BLACKLIST_ENABLE,
945
+ __( 'Enable blacklist/whitelist', 'duracelltomi-google-tag-manager' ),
946
+ 'gtm4wp_admin_output_field',
947
+ GTM4WP_ADMINSLUG,
948
+ GTM4WP_ADMIN_GROUP_BLACKLIST,
949
+ array(
950
+ 'label_for' => GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_ENABLE . ']',
951
+ 'description' => '',
952
+ 'optionsfieldid' => GTM4WP_OPTION_BLACKLIST_ENABLE
953
+ )
954
+ );
 
 
955
 
956
+ add_settings_field(
957
+ GTM4WP_OPTION_BLACKLIST_SANDBOXED,
958
+ __( 'Custom tag/variable templates', 'duracelltomi-google-tag-manager' ),
959
+ 'gtm4wp_admin_output_field',
960
+ GTM4WP_ADMINSLUG,
961
+ GTM4WP_ADMIN_GROUP_BLACKLIST,
962
+ array(
963
+ 'label_for' => GTM4WP_OPTIONS . '[' . GTM4WP_OPTION_BLACKLIST_SANDBOXED . ']',
964
+ 'description' => '',
965
+ 'entityid' => GTM4WP_OPTION_BLACKLIST_SANDBOXED
966
+ )
967
+ );
968
+
969
+ foreach( $gtm4wp_entity_ids as $gtm_entity_group_id => $gtm_entity_group_list ) {
970
+ foreach( $gtm_entity_group_list as $gtm_entity_id => $gtm_entity_label ) {
971
+ add_settings_field(
972
+ 'gtm4wp-admin-blacklist-' . $gtm_entity_group_id . '-' . $gtm_entity_id . '-id',
973
+ $gtm_entity_label,
974
+ 'gtm4wp_admin_output_field',
975
+ GTM4WP_ADMINSLUG,
976
+ GTM4WP_ADMIN_GROUP_BLACKLIST,
977
+ array(
978
+ 'label_for' => 'gtm4wp-options[blacklist-' . $gtm_entity_group_id . '-' . $gtm_entity_id . ']',
979
+ 'description' => '',
980
+ 'entityid' => $gtm_entity_id,
981
+ )
982
+ );
983
+ }
984
  }
985
 
986
  add_settings_section(
991
  );
992
 
993
  foreach ( $gtm4wp_integratefieldtexts as $fieldid => $fielddata ) {
994
+ $phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
995
+
996
  add_settings_field(
997
  'gtm4wp-admin-' . $fieldid . '-id',
998
+ $fielddata['label'] . '<span class="' . $phase . '"></span>',
999
  'gtm4wp_admin_output_field',
1000
  GTM4WP_ADMINSLUG,
1001
  GTM4WP_ADMIN_GROUP_INTEGRATION,
1016
  );
1017
 
1018
  foreach ( $gtm4wp_advancedfieldtexts as $fieldid => $fielddata ) {
1019
+ $phase = isset( $fielddata['phase'] ) ? $fielddata['phase'] : GTM4WP_PHASE_STABLE;
1020
+
1021
  add_settings_field(
1022
  'gtm4wp-admin-' . $fieldid . '-id',
1023
+ $fielddata['label'] . '<span class="' . $phase . '"></span>',
1024
  'gtm4wp_admin_output_field',
1025
  GTM4WP_ADMINSLUG,
1026
  GTM4WP_ADMIN_GROUP_ADVANCED,
1101
  'adwordstabtitle' => __( 'Google Ads', 'duracelltomi-google-tag-manager' ),
1102
  'browsertabtitle' => __( 'Browser/OS/Device', 'duracelltomi-google-tag-manager' ),
1103
  'blocktagstabtitle' => __( 'Blacklist tags', 'duracelltomi-google-tag-manager' ),
1104
+ 'blocktriggerstabtitle' => __( 'Blacklist triggers', 'duracelltomi-google-tag-manager' ),
1105
+ 'blockmacrostabtitle' => __( 'Blacklist variables', 'duracelltomi-google-tag-manager' ),
1106
  'wpcf7tabtitle' => __( 'Contact Form 7', 'duracelltomi-google-tag-manager' ),
1107
  'wctabtitle' => __( 'WooCommerce', 'duracelltomi-google-tag-manager' ),
1108
  'gotabtitle' => __( 'Google Optimize', 'duracelltomi-google-tag-manager' ),
1345
  $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ||
1346
  $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ];
1347
 
 
 
 
 
 
 
 
 
 
1348
  if ( ( false === $gtm4wp_user_notices_dismisses['wc-ga-plugin-warning'] ) && $is_wc_active && is_plugin_active( 'woocommerce-google-analytics-integration/woocommerce-google-analytics-integration.php' ) ) {
1349
  echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?wc-ga-plugin-warning"><p><strong>' . __( 'Notice: you should deactivate the plugin "WooCommerce Google Analytics Integration" if you are using Google Analytics tags inside Google Tag Manager!', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1350
  }
1357
  if ( ( false === $gtm4wp_user_notices_dismisses['php56-warning'] ) && ( version_compare( PHP_VERSION, '5.6.0' ) < 0 ) ) {
1358
  echo '<div class="gtm4wp-notice notice notice-warning is-dismissible" data-href="?php56-warning"><p><strong>' . __( 'Warning: You are using an outdated version of PHP (v' . PHP_VERSION . ') that can cause issues with the plugin Google Tag Manager for WordPress. Please consider to upgrade your PHP.', 'duracelltomi-google-tag-manager' ) . '</strong></p></div>';
1359
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1360
  }
1361
 
1362
  function gtm4wp_dismiss_notice() {
common/readoptions.php CHANGED
@@ -1,295 +1,432 @@
1
- <?php
2
- define( 'GTM4WP_OPTIONS', 'gtm4wp-options' );
3
- define( 'GTM4WP_OPTION_GTM_CODE', 'gtm-code' );
4
- define( 'GTM4WP_OPTION_GTM_PLACEMENT', 'gtm-code-placement' );
5
- define( 'GTM4WP_OPTION_DATALAYER_NAME', 'gtm-datalayer-variable-name' );
6
- define( 'GTM4WP_OPTION_ENV_GTM_AUTH', 'gtm-env-gtm-auth' );
7
- define( 'GTM4WP_OPTION_ENV_GTM_PREVIEW', 'gtm-env-gtm-preview' );
8
- define( 'GTM4WP_OPTION_DONOTTRACK', 'gtm-browser-do-not-track' );
9
- define( 'GTM4WP_OPTION_LOADEARLY', 'gtm-load-gtm-early' );
10
-
11
- define( 'GTM4WP_OPTION_INCLUDE_REMARKETING', 'include-remarketing' );
12
- define( 'GTM4WP_OPTION_INCLUDE_LOGGEDIN', 'include-loggedin' );
13
- define( 'GTM4WP_OPTION_INCLUDE_USERROLE', 'include-userrole' );
14
- define( 'GTM4WP_OPTION_INCLUDE_USERID', 'include-userid' );
15
- define( 'GTM4WP_OPTION_INCLUDE_USEREMAIL', 'include-useremail' );
16
- define( 'GTM4WP_OPTION_INCLUDE_USERREGDATE', 'include-userregdate' );
17
- define( 'GTM4WP_OPTION_INCLUDE_USERNAME', 'include-username' );
18
- define( 'GTM4WP_OPTION_INCLUDE_VISITOR_IP', 'include-visitor-ip' );
19
- define( 'GTM4WP_OPTION_INCLUDE_POSTTYPE', 'include-posttype' );
20
- define( 'GTM4WP_OPTION_INCLUDE_CATEGORIES', 'include-categories' );
21
- define( 'GTM4WP_OPTION_INCLUDE_TAGS', 'include-tags' );
22
- define( 'GTM4WP_OPTION_INCLUDE_AUTHORID', 'include-authorid' );
23
- define( 'GTM4WP_OPTION_INCLUDE_AUTHOR', 'include-author' );
24
- define( 'GTM4WP_OPTION_INCLUDE_POSTDATE', 'include-postdate' );
25
- define( 'GTM4WP_OPTION_INCLUDE_POSTTITLE', 'include-posttitle' );
26
- define( 'GTM4WP_OPTION_INCLUDE_POSTCOUNT', 'include-postcount' );
27
- define( 'GTM4WP_OPTION_INCLUDE_POSTID', 'include-postid' );
28
- define( 'GTM4WP_OPTION_INCLUDE_POSTFORMAT', 'include-postformat' );
29
- define( 'GTM4WP_OPTION_INCLUDE_POSTTERMLIST', 'include-postterms' );
30
- define( 'GTM4WP_OPTION_INCLUDE_SEARCHDATA', 'include-searchdata' );
31
- define( 'GTM4WP_OPTION_INCLUDE_BROWSERDATA', 'include-browserdata' );
32
- define( 'GTM4WP_OPTION_INCLUDE_OSDATA', 'include-osdata' );
33
- define( 'GTM4WP_OPTION_INCLUDE_DEVICEDATA', 'include-devicedata' );
34
- define( 'GTM4WP_OPTION_INCLUDE_MISCGEO', 'include-miscgeo' );
35
- define( 'GTM4WP_OPTION_INCLUDE_MISCGEOAPI', 'geo-apikey' );
36
- define( 'GTM4WP_OPTION_INCLUDE_MISCGEOCF', 'include-miscgeo-cloudflare' );
37
- define( 'GTM4WP_OPTION_INCLUDE_WEATHER', 'include-weather' );
38
- define( 'GTM4WP_OPTION_INCLUDE_WEATHERUNITS', 'weather-weatherunits' );
39
- define( 'GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI', 'weather-openweathermap-apikey' );
40
- define( 'GTM4WP_OPTION_INCLUDE_SITEID', 'include-siteid' );
41
- define( 'GTM4WP_OPTION_INCLUDE_SITENAME', 'include-sitename' );
42
-
43
- define( 'GTM4WP_OPTION_EVENTS_OUTBOUND', 'event-outbound' );
44
- define( 'GTM4WP_OPTION_EVENTS_DOWNLOADS', 'event-downloads' );
45
- define( 'GTM4WP_OPTION_EVENTS_DWLEXT', 'event-download-extensions' );
46
- define( 'GTM4WP_OPTION_EVENTS_EMAILCLICKS', 'event-email-clicks' );
47
- define( 'GTM4WP_OPTION_EVENTS_SOCIAL', 'event-social' );
48
-
49
- define( 'GTM4WP_OPTION_EVENTS_FORMMOVE', 'event-form-move' );
50
- define( 'GTM4WP_OPTION_EVENTS_NEWUSERREG', 'event-new-user-registration' );
51
- define( 'GTM4WP_OPTION_EVENTS_USERLOGIN', 'event-user-logged-in' );
52
-
53
- define( 'GTM4WP_OPTION_EVENTS_YOUTUBE', 'event-youtube' );
54
- define( 'GTM4WP_OPTION_EVENTS_VIMEO', 'event-vimeo' );
55
- define( 'GTM4WP_OPTION_EVENTS_SOUNDCLOUD', 'event-soundcloud' );
56
-
57
- define( 'GTM4WP_OPTION_SCROLLER_ENABLED', 'scroller-enabled' );
58
- define( 'GTM4WP_OPTION_SCROLLER_DEBUGMODE', 'scroller-debug-mode' );
59
- define( 'GTM4WP_OPTION_SCROLLER_CALLBACKTIME', 'scroller-callback-time' );
60
- define( 'GTM4WP_OPTION_SCROLLER_DISTANCE', 'scroller-distance' );
61
- define( 'GTM4WP_OPTION_SCROLLER_CONTENTID', 'scroller-contentid' );
62
- define( 'GTM4WP_OPTION_SCROLLER_READERTIME', 'scroller-readertime' );
63
-
64
- define( 'GTM4WP_OPTION_BLACKLIST_ENABLE', 'blacklist-enable' );
65
- define( 'GTM4WP_OPTION_BLACKLIST_ADADVISOR', 'blacklist-adadvisor' );
66
- define( 'GTM4WP_OPTION_BLACKLIST_ADROLL', 'blacklist-adroll' );
67
- define( 'GTM4WP_OPTION_BLACKLIST_AWCONV', 'blacklist-adwords-conversion' );
68
- define( 'GTM4WP_OPTION_BLACKLIST_AWREMARKET', 'blacklist-adwords-remarketing' );
69
- define( 'GTM4WP_OPTION_BLACKLIST_BIZO', 'blacklist-bizo' );
70
- define( 'GTM4WP_OPTION_BLACKLIST_CLICKTALE', 'blacklist-clicktale' );
71
- define( 'GTM4WP_OPTION_BLACKLIST_COMSCORE', 'blacklist-comscore' );
72
- define( 'GTM4WP_OPTION_BLACKLIST_CUSTOMHTML', 'blacklist-custom-html' );
73
- define( 'GTM4WP_OPTION_BLACKLIST_CUSTOMIMG', 'blacklist-custom-img-tag' );
74
- define( 'GTM4WP_OPTION_BLACKLIST_DBLCLKCOUNT', 'blacklist-doubleclick-counter' );
75
- define( 'GTM4WP_OPTION_BLACKLIST_DBLCLKSALES', 'blacklist-doubleclick-sales' );
76
- define( 'GTM4WP_OPTION_BLACKLIST_GACLASSIC', 'blacklist-google-analytics' );
77
- define( 'GTM4WP_OPTION_BLACKLIST_MARIN', 'blacklist-marin' );
78
- define( 'GTM4WP_OPTION_BLACKLIST_MPLEXIFRAME', 'blacklist-mediaplex-iframe' );
79
- define( 'GTM4WP_OPTION_BLACKLIST_MPLEXROI', 'blacklist-mediaplex-roi' );
80
- define( 'GTM4WP_OPTION_BLACKLIST_MEDIA6DEG', 'blacklist-media6degrees' );
81
- define( 'GTM4WP_OPTION_BLACKLIST_TURNCONV', 'blacklist-turn-conversion' );
82
- define( 'GTM4WP_OPTION_BLACKLIST_TURNDATA', 'blacklist-turn-data' );
83
- define( 'GTM4WP_OPTION_BLACKLIST_UA', 'blacklist-universal-analytics' );
84
-
85
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_DOMELEMENT', 'blacklist-macro-dom-element' );
86
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_CUSTOMJS', 'blacklist-macro-custom-js' );
87
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_CONSTANT', 'blacklist-macro-constant-string' );
88
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_1STCOOKIE', 'blacklist-macro-1st-party-cookie' );
89
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_EVENTNAME', 'blacklist-macro-event-name' );
90
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_JSVAR', 'blacklist-macro-javascript-variable' );
91
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_DLAYERVAR', 'blacklist-macro-datalayer-variable' );
92
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_RANDOMNUM', 'blacklist-macro-random-number' );
93
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_REFERRER', 'blacklist-macro-referrer' );
94
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_URL', 'blacklist-macro-url' );
95
- define( 'GTM4WP_OPTION_BLACKLIST_MACRO_AUTOEVENT', 'blacklist-macro-autoevent-variable' );
96
-
97
- define( 'GTM4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
98
-
99
- define( 'GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE', 'integrate-woocommerce' );
100
- define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC', 'integrate-woocommerce-track-classic-ecommerce' );
101
- define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC', 'integrate-woocommerce-track-enhanced-ecommerce' );
102
- define( 'GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION', 'integrate-woocommerce-product-per-impression' );
103
- define( 'GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP', 'integrate-woocommerce-cart-as-first-step' );
104
- define( 'GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL', 'integrate-woocommerce-cart-content-in-datalayer' );
105
- define( 'GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY', 'integrate-woocommerce-brand-taxonomy' );
106
- define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETING', 'integrate-woocommerce-remarketing' );
107
- define( 'GTM4WP_OPTION_INTEGRATE_WCUSESKU', 'integrate-woocommerce-remarketing-usesku' );
108
- define( 'GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH', 'integrate-woocommerce-use-full-category-path' );
109
- define( 'GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX', 'integrate-woocommerce-remarketing-productidprefix' );
110
- define( 'GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA', 'integrate-woocommerce-customer-data' );
111
- define( 'GTM4WP_OPTION_INTEGRATE_WCORDERDATA', 'integrate-woocommerce-order-data' );
112
- define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX', 'integrate-woocommerce-exclude-tax' );
113
- define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING', 'integrate-woocommerce-exclude-shipping' );
114
- define( 'GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG', 'integrate-woocommerce-do-not-use-order-tracked-flag' );
115
-
116
- define( 'GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS', 'integrate-google-optimize-idlist' );
117
- define( 'GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT', 'integrate-google-optimize-timeout' );
118
-
119
- define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
120
-
121
- define( 'GTM4WP_OPTION_INTEGRATE_AMPID', 'integrate-amp-id' );
122
-
123
- define( 'GTM4WP_PLACEMENT_FOOTER', 0 );
124
- define( 'GTM4WP_PLACEMENT_BODYOPEN', 1 );
125
- define( 'GTM4WP_PLACEMENT_BODYOPEN_AUTO', 2 );
126
- define( 'GTM4WP_PLACEMENT_OFF', 3 );
127
-
128
- global $gtm4wp_options, $gtm4wp_defaultoptions;
129
-
130
- $gtm4wp_options = array();
131
-
132
- $gtm4wp_defaultoptions = array(
133
- GTM4WP_OPTION_GTM_CODE => '',
134
- GTM4WP_OPTION_DATALAYER_NAME => '',
135
- GTM4WP_OPTION_GTM_PLACEMENT => GTM4WP_PLACEMENT_FOOTER,
136
- GTM4WP_OPTION_ENV_GTM_AUTH => '',
137
- GTM4WP_OPTION_ENV_GTM_PREVIEW => '',
138
- GTM4WP_OPTION_DONOTTRACK => false,
139
- GTM4WP_OPTION_LOADEARLY => false,
140
-
141
- GTM4WP_OPTION_INCLUDE_REMARKETING => false,
142
- GTM4WP_OPTION_INCLUDE_LOGGEDIN => false,
143
- GTM4WP_OPTION_INCLUDE_USERROLE => false,
144
- GTM4WP_OPTION_INCLUDE_USERID => false,
145
- GTM4WP_OPTION_INCLUDE_USEREMAIL => false,
146
- GTM4WP_OPTION_INCLUDE_USERREGDATE => false,
147
- GTM4WP_OPTION_INCLUDE_USERNAME => false,
148
- GTM4WP_OPTION_INCLUDE_VISITOR_IP => false,
149
- GTM4WP_OPTION_INCLUDE_POSTTYPE => true,
150
- GTM4WP_OPTION_INCLUDE_CATEGORIES => true,
151
- GTM4WP_OPTION_INCLUDE_TAGS => true,
152
- GTM4WP_OPTION_INCLUDE_AUTHOR => true,
153
- GTM4WP_OPTION_INCLUDE_AUTHORID => false,
154
- GTM4WP_OPTION_INCLUDE_POSTDATE => false,
155
- GTM4WP_OPTION_INCLUDE_POSTTITLE => false,
156
- GTM4WP_OPTION_INCLUDE_POSTCOUNT => false,
157
- GTM4WP_OPTION_INCLUDE_POSTID => false,
158
- GTM4WP_OPTION_INCLUDE_POSTFORMAT => false,
159
- GTM4WP_OPTION_INCLUDE_POSTTERMLIST => false,
160
- GTM4WP_OPTION_INCLUDE_SEARCHDATA => false,
161
- GTM4WP_OPTION_INCLUDE_BROWSERDATA => false,
162
- GTM4WP_OPTION_INCLUDE_OSDATA => false,
163
- GTM4WP_OPTION_INCLUDE_DEVICEDATA => false,
164
- GTM4WP_OPTION_INCLUDE_MISCGEO => false,
165
- GTM4WP_OPTION_INCLUDE_MISCGEOAPI => '',
166
- GTM4WP_OPTION_INCLUDE_MISCGEOCF => false,
167
- GTM4WP_OPTION_INCLUDE_WEATHER => false,
168
- GTM4WP_OPTION_INCLUDE_WEATHERUNITS => 0,
169
- GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI => '',
170
- GTM4WP_OPTION_INCLUDE_SITEID => false,
171
- GTM4WP_OPTION_INCLUDE_SITENAME => false,
172
-
173
- GTM4WP_OPTION_EVENTS_OUTBOUND => false,
174
- GTM4WP_OPTION_EVENTS_DOWNLOADS => false,
175
- GTM4WP_OPTION_EVENTS_DWLEXT => 'pdf,doc,docx,xls,xlsx,ppt,pptx,zip,rar,gz,tar',
176
- GTM4WP_OPTION_EVENTS_EMAILCLICKS => false,
177
- GTM4WP_OPTION_EVENTS_SOCIAL => false,
178
-
179
- GTM4WP_OPTION_EVENTS_FORMMOVE => true,
180
- GTM4WP_OPTION_EVENTS_NEWUSERREG => false,
181
- GTM4WP_OPTION_EVENTS_USERLOGIN => false,
182
-
183
- GTM4WP_OPTION_EVENTS_YOUTUBE => false,
184
- GTM4WP_OPTION_EVENTS_VIMEO => false,
185
- GTM4WP_OPTION_EVENTS_SOUNDCLOUD => false,
186
-
187
- GTM4WP_OPTION_SCROLLER_ENABLED => false,
188
- GTM4WP_OPTION_SCROLLER_DEBUGMODE => false,
189
- GTM4WP_OPTION_SCROLLER_CALLBACKTIME => 100,
190
- GTM4WP_OPTION_SCROLLER_DISTANCE => 150,
191
- GTM4WP_OPTION_SCROLLER_CONTENTID => 'content',
192
- GTM4WP_OPTION_SCROLLER_READERTIME => 60,
193
-
194
- GTM4WP_OPTION_BLACKLIST_ENABLE => 0,
195
- GTM4WP_OPTION_BLACKLIST_ADADVISOR => false,
196
- GTM4WP_OPTION_BLACKLIST_ADROLL => false,
197
- GTM4WP_OPTION_BLACKLIST_AWCONV => false,
198
- GTM4WP_OPTION_BLACKLIST_AWREMARKET => false,
199
- GTM4WP_OPTION_BLACKLIST_BIZO => false,
200
- GTM4WP_OPTION_BLACKLIST_CLICKTALE => false,
201
- GTM4WP_OPTION_BLACKLIST_COMSCORE => false,
202
- GTM4WP_OPTION_BLACKLIST_CUSTOMHTML => false,
203
- GTM4WP_OPTION_BLACKLIST_CUSTOMIMG => false,
204
- GTM4WP_OPTION_BLACKLIST_DBLCLKCOUNT => false,
205
- GTM4WP_OPTION_BLACKLIST_DBLCLKSALES => false,
206
- GTM4WP_OPTION_BLACKLIST_GACLASSIC => false,
207
- GTM4WP_OPTION_BLACKLIST_MARIN => false,
208
- GTM4WP_OPTION_BLACKLIST_MPLEXIFRAME => false,
209
- GTM4WP_OPTION_BLACKLIST_MPLEXROI => false,
210
- GTM4WP_OPTION_BLACKLIST_MEDIA6DEG => false,
211
- GTM4WP_OPTION_BLACKLIST_TURNCONV => false,
212
- GTM4WP_OPTION_BLACKLIST_TURNDATA => false,
213
- GTM4WP_OPTION_BLACKLIST_UA => false,
214
-
215
- GTM4WP_OPTION_BLACKLIST_MACRO_DOMELEMENT => true,
216
- GTM4WP_OPTION_BLACKLIST_MACRO_CUSTOMJS => true,
217
- GTM4WP_OPTION_BLACKLIST_MACRO_CONSTANT => true,
218
- GTM4WP_OPTION_BLACKLIST_MACRO_1STCOOKIE => true,
219
- GTM4WP_OPTION_BLACKLIST_MACRO_EVENTNAME => true,
220
- GTM4WP_OPTION_BLACKLIST_MACRO_JSVAR => true,
221
- GTM4WP_OPTION_BLACKLIST_MACRO_DLAYERVAR => true,
222
- GTM4WP_OPTION_BLACKLIST_MACRO_RANDOMNUM => true,
223
- GTM4WP_OPTION_BLACKLIST_MACRO_REFERRER => true,
224
- GTM4WP_OPTION_BLACKLIST_MACRO_URL => true,
225
- GTM4WP_OPTION_BLACKLIST_MACRO_AUTOEVENT => true,
226
-
227
- GTM4WP_OPTION_INTEGRATE_WPCF7 => false,
228
-
229
- GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => false,
230
- GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => false,
231
- GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION => 0,
232
- GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP => false,
233
- GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL => false,
234
- GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY => '',
235
- GTM4WP_OPTION_INTEGRATE_WCREMARKETING => false,
236
- GTM4WP_OPTION_INTEGRATE_WCUSESKU => false,
237
- GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH => false,
238
- GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => '',
239
- GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA => false,
240
- GTM4WP_OPTION_INTEGRATE_WCORDERDATA => false,
241
- GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => false,
242
- GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING => false,
243
- GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG => false,
244
-
245
- GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => '',
246
- GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT => 4000,
247
-
248
- GTM4WP_OPTION_INTEGRATE_WPECOMMERCE => false,
249
-
250
- GTM4WP_OPTION_INTEGRATE_AMPID => ''
251
- );
252
-
253
- function gtm4wp_reload_options() {
254
- global $gtm4wp_defaultoptions;
255
-
256
- $storedoptions = (array) get_option( GTM4WP_OPTIONS );
257
- if ( ! is_array( $gtm4wp_defaultoptions ) ) {
258
- $gtm4wp_defaultoptions = array();
259
- }
260
-
261
- // update WooCommerce settings from 0.7.x to 0.8
262
- if ( isset( $storedoptions[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ] ) && ! isset( $storedoptions[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) ) {
263
- $storedoptions[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] = $storedoptions[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ];
264
- $storedoptions[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] = false;
265
- $storedoptions[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] = $storedoptions[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ];
266
-
267
- unset( $storedoptions[ GTM4WP_OPTION_INTEGRATE_WOOCOMMERCE ] );
268
- }
269
-
270
- $return_options = array_merge( $gtm4wp_defaultoptions, $storedoptions );
271
-
272
- if ( defined( 'GTM4WP_HARDCODED_GTM_ID' ) ) {
273
- $return_options[ GTM4WP_OPTION_GTM_CODE ] = GTM4WP_HARDCODED_GTM_ID;
274
- }
275
-
276
- if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ) {
277
- $return_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] = GTM4WP_HARDCODED_GTM_ENV_AUTH;
278
- }
279
-
280
- if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ) {
281
- $return_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] = GTM4WP_HARDCODED_GTM_ENV_PREVIEW;
282
- }
283
-
284
- return $return_options;
285
- }
286
-
287
- function gtp4wp_debug_file( $debug_data ) {
288
- $fp = fopen( dirname( __FILE__ ) . '/' . date( 'Y-m-d-H-i-s-u' ) . '.txt', 'w' );
289
- if ( $fp ) {
290
- fwrite( $fp, $debug_data );
291
- fclose( $fp );
292
- }
293
- }
294
-
295
- $gtm4wp_options = gtm4wp_reload_options();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ define( 'GTM4WP_OPTIONS', 'gtm4wp-options' );
3
+ define( 'GTM4WP_OPTION_GTM_CODE', 'gtm-code' );
4
+ define( 'GTM4WP_OPTION_GTM_PLACEMENT', 'gtm-code-placement' );
5
+ define( 'GTM4WP_OPTION_DATALAYER_NAME', 'gtm-datalayer-variable-name' );
6
+ define( 'GTM4WP_OPTION_ENV_GTM_AUTH', 'gtm-env-gtm-auth' );
7
+ define( 'GTM4WP_OPTION_ENV_GTM_PREVIEW', 'gtm-env-gtm-preview' );
8
+ define( 'GTM4WP_OPTION_DONOTTRACK', 'gtm-browser-do-not-track' );
9
+ define( 'GTM4WP_OPTION_LOADEARLY', 'gtm-load-gtm-early' );
10
+
11
+ define( 'GTM4WP_OPTION_INCLUDE_REMARKETING', 'include-remarketing' );
12
+ define( 'GTM4WP_OPTION_INCLUDE_LOGGEDIN', 'include-loggedin' );
13
+ define( 'GTM4WP_OPTION_INCLUDE_USERROLE', 'include-userrole' );
14
+ define( 'GTM4WP_OPTION_INCLUDE_USERID', 'include-userid' );
15
+ define( 'GTM4WP_OPTION_INCLUDE_USEREMAIL', 'include-useremail' );
16
+ define( 'GTM4WP_OPTION_INCLUDE_USERREGDATE', 'include-userregdate' );
17
+ define( 'GTM4WP_OPTION_INCLUDE_USERNAME', 'include-username' );
18
+ define( 'GTM4WP_OPTION_INCLUDE_VISITOR_IP', 'include-visitor-ip' );
19
+ define( 'GTM4WP_OPTION_INCLUDE_POSTTYPE', 'include-posttype' );
20
+ define( 'GTM4WP_OPTION_INCLUDE_CATEGORIES', 'include-categories' );
21
+ define( 'GTM4WP_OPTION_INCLUDE_TAGS', 'include-tags' );
22
+ define( 'GTM4WP_OPTION_INCLUDE_AUTHORID', 'include-authorid' );
23
+ define( 'GTM4WP_OPTION_INCLUDE_AUTHOR', 'include-author' );
24
+ define( 'GTM4WP_OPTION_INCLUDE_POSTDATE', 'include-postdate' );
25
+ define( 'GTM4WP_OPTION_INCLUDE_POSTTITLE', 'include-posttitle' );
26
+ define( 'GTM4WP_OPTION_INCLUDE_POSTCOUNT', 'include-postcount' );
27
+ define( 'GTM4WP_OPTION_INCLUDE_POSTID', 'include-postid' );
28
+ define( 'GTM4WP_OPTION_INCLUDE_POSTFORMAT', 'include-postformat' );
29
+ define( 'GTM4WP_OPTION_INCLUDE_POSTTERMLIST', 'include-postterms' );
30
+ define( 'GTM4WP_OPTION_INCLUDE_SEARCHDATA', 'include-searchdata' );
31
+ define( 'GTM4WP_OPTION_INCLUDE_BROWSERDATA', 'include-browserdata' );
32
+ define( 'GTM4WP_OPTION_INCLUDE_OSDATA', 'include-osdata' );
33
+ define( 'GTM4WP_OPTION_INCLUDE_DEVICEDATA', 'include-devicedata' );
34
+ define( 'GTM4WP_OPTION_INCLUDE_MISCGEO', 'include-miscgeo' );
35
+ define( 'GTM4WP_OPTION_INCLUDE_MISCGEOAPI', 'geo-apikey' );
36
+ define( 'GTM4WP_OPTION_INCLUDE_MISCGEOCF', 'include-miscgeo-cloudflare' );
37
+ define( 'GTM4WP_OPTION_INCLUDE_WEATHER', 'include-weather' );
38
+ define( 'GTM4WP_OPTION_INCLUDE_WEATHERUNITS', 'weather-weatherunits' );
39
+ define( 'GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI', 'weather-openweathermap-apikey' );
40
+ define( 'GTM4WP_OPTION_INCLUDE_SITEID', 'include-siteid' );
41
+ define( 'GTM4WP_OPTION_INCLUDE_SITENAME', 'include-sitename' );
42
+
43
+ define( 'GTM4WP_OPTION_EVENTS_FORMMOVE', 'event-form-move' );
44
+ define( 'GTM4WP_OPTION_EVENTS_NEWUSERREG', 'event-new-user-registration' );
45
+ define( 'GTM4WP_OPTION_EVENTS_USERLOGIN', 'event-user-logged-in' );
46
+
47
+ define( 'GTM4WP_OPTION_EVENTS_YOUTUBE', 'event-youtube' );
48
+ define( 'GTM4WP_OPTION_EVENTS_VIMEO', 'event-vimeo' );
49
+ define( 'GTM4WP_OPTION_EVENTS_SOUNDCLOUD', 'event-soundcloud' );
50
+
51
+ define( 'GTM4WP_OPTION_SCROLLER_ENABLED', 'scroller-enabled' );
52
+ define( 'GTM4WP_OPTION_SCROLLER_DEBUGMODE', 'scroller-debug-mode' );
53
+ define( 'GTM4WP_OPTION_SCROLLER_CALLBACKTIME', 'scroller-callback-time' );
54
+ define( 'GTM4WP_OPTION_SCROLLER_DISTANCE', 'scroller-distance' );
55
+ define( 'GTM4WP_OPTION_SCROLLER_CONTENTID', 'scroller-contentid' );
56
+ define( 'GTM4WP_OPTION_SCROLLER_READERTIME', 'scroller-readertime' );
57
+
58
+ define( 'GTM4WP_OPTION_BLACKLIST_ENABLE', 'blacklist-enable' );
59
+ define( 'GTM4WP_OPTION_BLACKLIST_SANDBOXED', 'blacklist-sandboxed' );
60
+ define( 'GTM4WP_OPTION_BLACKLIST_STATUS', 'blacklist-status' );
61
+
62
+ // deprecated options BEGIN
63
+ define( 'GTM4WP_OPTION_BLACKLIST_ADADVISOR', 'blacklist-adadvisor' );
64
+ define( 'GTM4WP_OPTION_BLACKLIST_ADROLL', 'blacklist-adroll' );
65
+ define( 'GTM4WP_OPTION_BLACKLIST_AWCONV', 'blacklist-adwords-conversion' );
66
+ define( 'GTM4WP_OPTION_BLACKLIST_AWREMARKET', 'blacklist-adwords-remarketing' );
67
+ define( 'GTM4WP_OPTION_BLACKLIST_BIZO', 'blacklist-bizo' );
68
+ define( 'GTM4WP_OPTION_BLACKLIST_CLICKTALE', 'blacklist-clicktale' );
69
+ define( 'GTM4WP_OPTION_BLACKLIST_COMSCORE', 'blacklist-comscore' );
70
+ define( 'GTM4WP_OPTION_BLACKLIST_CUSTOMHTML', 'blacklist-custom-html' );
71
+ define( 'GTM4WP_OPTION_BLACKLIST_CUSTOMIMG', 'blacklist-custom-img-tag' );
72
+ define( 'GTM4WP_OPTION_BLACKLIST_DBLCLKCOUNT', 'blacklist-doubleclick-counter' );
73
+ define( 'GTM4WP_OPTION_BLACKLIST_DBLCLKSALES', 'blacklist-doubleclick-sales' );
74
+ define( 'GTM4WP_OPTION_BLACKLIST_GACLASSIC', 'blacklist-google-analytics' );
75
+ define( 'GTM4WP_OPTION_BLACKLIST_MARIN', 'blacklist-marin' );
76
+ define( 'GTM4WP_OPTION_BLACKLIST_MPLEXIFRAME', 'blacklist-mediaplex-iframe' );
77
+ define( 'GTM4WP_OPTION_BLACKLIST_MPLEXROI', 'blacklist-mediaplex-roi' );
78
+ define( 'GTM4WP_OPTION_BLACKLIST_MEDIA6DEG', 'blacklist-media6degrees' );
79
+ define( 'GTM4WP_OPTION_BLACKLIST_TURNCONV', 'blacklist-turn-conversion' );
80
+ define( 'GTM4WP_OPTION_BLACKLIST_TURNDATA', 'blacklist-turn-data' );
81
+ define( 'GTM4WP_OPTION_BLACKLIST_UA', 'blacklist-universal-analytics' );
82
+
83
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_DOMELEMENT', 'blacklist-macro-dom-element' );
84
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_CUSTOMJS', 'blacklist-macro-custom-js' );
85
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_CONSTANT', 'blacklist-macro-constant-string' );
86
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_1STCOOKIE', 'blacklist-macro-1st-party-cookie' );
87
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_EVENTNAME', 'blacklist-macro-event-name' );
88
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_JSVAR', 'blacklist-macro-javascript-variable' );
89
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_DLAYERVAR', 'blacklist-macro-datalayer-variable' );
90
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_RANDOMNUM', 'blacklist-macro-random-number' );
91
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_REFERRER', 'blacklist-macro-referrer' );
92
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_URL', 'blacklist-macro-url' );
93
+ define( 'GTM4WP_OPTION_BLACKLIST_MACRO_AUTOEVENT', 'blacklist-macro-autoevent-variable' );
94
+ // deprecated options END
95
+
96
+ define( 'GTM4WP_OPTION_INTEGRATE_WPCF7', 'integrate-wpcf7' );
97
+
98
+ define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC', 'integrate-woocommerce-track-classic-ecommerce' );
99
+ define( 'GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC', 'integrate-woocommerce-track-enhanced-ecommerce' );
100
+ define( 'GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION', 'integrate-woocommerce-product-per-impression' );
101
+ define( 'GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP', 'integrate-woocommerce-cart-as-first-step' );
102
+ define( 'GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL', 'integrate-woocommerce-cart-content-in-datalayer' );
103
+ define( 'GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY', 'integrate-woocommerce-brand-taxonomy' );
104
+ define( 'GTM4WP_OPTION_INTEGRATE_WCREMARKETING', 'integrate-woocommerce-remarketing' );
105
+ define( 'GTM4WP_OPTION_INTEGRATE_WCUSESKU', 'integrate-woocommerce-remarketing-usesku' );
106
+ define( 'GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH', 'integrate-woocommerce-use-full-category-path' );
107
+ define( 'GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX', 'integrate-woocommerce-remarketing-productidprefix' );
108
+ define( 'GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA', 'integrate-woocommerce-customer-data' );
109
+ define( 'GTM4WP_OPTION_INTEGRATE_WCORDERDATA', 'integrate-woocommerce-order-data' );
110
+ define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX', 'integrate-woocommerce-exclude-tax' );
111
+ define( 'GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING', 'integrate-woocommerce-exclude-shipping' );
112
+ define( 'GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG', 'integrate-woocommerce-do-not-use-order-tracked-flag' );
113
+
114
+ define( 'GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS', 'integrate-google-optimize-idlist' );
115
+ define( 'GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT', 'integrate-google-optimize-timeout' );
116
+
117
+ define( 'GTM4WP_OPTION_INTEGRATE_WPECOMMERCE', 'integrate-wp-e-commerce' );
118
+
119
+ define( 'GTM4WP_OPTION_INTEGRATE_AMPID', 'integrate-amp-id' );
120
+
121
+ define( 'GTM4WP_PLACEMENT_FOOTER', 0 );
122
+ define( 'GTM4WP_PLACEMENT_BODYOPEN', 1 );
123
+ define( 'GTM4WP_PLACEMENT_BODYOPEN_AUTO', 2 );
124
+ define( 'GTM4WP_PLACEMENT_OFF', 3 );
125
+
126
+ global $gtm4wp_options, $gtm4wp_defaultoptions, $gtm4wp_entity_ids;
127
+
128
+ $gtm4wp_options = array();
129
+
130
+ $gtm4wp_defaultoptions = array(
131
+ GTM4WP_OPTION_GTM_CODE => '',
132
+ GTM4WP_OPTION_DATALAYER_NAME => '',
133
+ GTM4WP_OPTION_GTM_PLACEMENT => GTM4WP_PLACEMENT_FOOTER,
134
+ GTM4WP_OPTION_ENV_GTM_AUTH => '',
135
+ GTM4WP_OPTION_ENV_GTM_PREVIEW => '',
136
+ GTM4WP_OPTION_DONOTTRACK => false,
137
+ GTM4WP_OPTION_LOADEARLY => false,
138
+
139
+ GTM4WP_OPTION_INCLUDE_REMARKETING => false,
140
+ GTM4WP_OPTION_INCLUDE_LOGGEDIN => false,
141
+ GTM4WP_OPTION_INCLUDE_USERROLE => false,
142
+ GTM4WP_OPTION_INCLUDE_USERID => false,
143
+ GTM4WP_OPTION_INCLUDE_USEREMAIL => false,
144
+ GTM4WP_OPTION_INCLUDE_USERREGDATE => false,
145
+ GTM4WP_OPTION_INCLUDE_USERNAME => false,
146
+ GTM4WP_OPTION_INCLUDE_VISITOR_IP => false,
147
+ GTM4WP_OPTION_INCLUDE_POSTTYPE => true,
148
+ GTM4WP_OPTION_INCLUDE_CATEGORIES => true,
149
+ GTM4WP_OPTION_INCLUDE_TAGS => true,
150
+ GTM4WP_OPTION_INCLUDE_AUTHOR => true,
151
+ GTM4WP_OPTION_INCLUDE_AUTHORID => false,
152
+ GTM4WP_OPTION_INCLUDE_POSTDATE => false,
153
+ GTM4WP_OPTION_INCLUDE_POSTTITLE => false,
154
+ GTM4WP_OPTION_INCLUDE_POSTCOUNT => false,
155
+ GTM4WP_OPTION_INCLUDE_POSTID => false,
156
+ GTM4WP_OPTION_INCLUDE_POSTFORMAT => false,
157
+ GTM4WP_OPTION_INCLUDE_POSTTERMLIST => false,
158
+ GTM4WP_OPTION_INCLUDE_SEARCHDATA => false,
159
+ GTM4WP_OPTION_INCLUDE_BROWSERDATA => false,
160
+ GTM4WP_OPTION_INCLUDE_OSDATA => false,
161
+ GTM4WP_OPTION_INCLUDE_DEVICEDATA => false,
162
+ GTM4WP_OPTION_INCLUDE_MISCGEO => false,
163
+ GTM4WP_OPTION_INCLUDE_MISCGEOAPI => '',
164
+ GTM4WP_OPTION_INCLUDE_MISCGEOCF => false,
165
+ GTM4WP_OPTION_INCLUDE_WEATHER => false,
166
+ GTM4WP_OPTION_INCLUDE_WEATHERUNITS => 0,
167
+ GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI => '',
168
+ GTM4WP_OPTION_INCLUDE_SITEID => false,
169
+ GTM4WP_OPTION_INCLUDE_SITENAME => false,
170
+
171
+ GTM4WP_OPTION_EVENTS_FORMMOVE => false,
172
+ GTM4WP_OPTION_EVENTS_NEWUSERREG => false,
173
+ GTM4WP_OPTION_EVENTS_USERLOGIN => false,
174
+
175
+ GTM4WP_OPTION_EVENTS_YOUTUBE => false,
176
+ GTM4WP_OPTION_EVENTS_VIMEO => false,
177
+ GTM4WP_OPTION_EVENTS_SOUNDCLOUD => false,
178
+
179
+ GTM4WP_OPTION_SCROLLER_ENABLED => false,
180
+ GTM4WP_OPTION_SCROLLER_DEBUGMODE => false,
181
+ GTM4WP_OPTION_SCROLLER_CALLBACKTIME => 100,
182
+ GTM4WP_OPTION_SCROLLER_DISTANCE => 150,
183
+ GTM4WP_OPTION_SCROLLER_CONTENTID => 'content',
184
+ GTM4WP_OPTION_SCROLLER_READERTIME => 60,
185
+
186
+ GTM4WP_OPTION_BLACKLIST_ENABLE => 0,
187
+ GTM4WP_OPTION_BLACKLIST_SANDBOXED => false,
188
+ GTM4WP_OPTION_BLACKLIST_STATUS => '',
189
+
190
+ GTM4WP_OPTION_INTEGRATE_WPCF7 => false,
191
+
192
+ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC => false,
193
+ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC => false,
194
+ GTM4WP_OPTION_INTEGRATE_WCPRODPERIMPRESSION => 0,
195
+ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP => false,
196
+ GTM4WP_OPTION_INTEGRATE_WCEINCLUDECARTINDL => false,
197
+ GTM4WP_OPTION_INTEGRATE_WCEECBRANDTAXONOMY => '',
198
+ GTM4WP_OPTION_INTEGRATE_WCREMARKETING => false,
199
+ GTM4WP_OPTION_INTEGRATE_WCUSESKU => false,
200
+ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH => false,
201
+ GTM4WP_OPTION_INTEGRATE_WCREMPRODIDPREFIX => '',
202
+ GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA => false,
203
+ GTM4WP_OPTION_INTEGRATE_WCORDERDATA => false,
204
+ GTM4WP_OPTION_INTEGRATE_WCEXCLUDETAX => false,
205
+ GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING => false,
206
+ GTM4WP_OPTION_INTEGRATE_WCNOORDERTRACKEDFLAG => false,
207
+
208
+ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS => '',
209
+ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT => 4000,
210
+
211
+ GTM4WP_OPTION_INTEGRATE_WPECOMMERCE => false,
212
+
213
+ GTM4WP_OPTION_INTEGRATE_AMPID => ''
214
+ );
215
+
216
+ $gtm4wp_entity_ids = array(
217
+ 'tags' => array(
218
+ 'abtGeneric' => 'AB TASTY Generic Tag',
219
+ 'ta' => 'AdAdvisor Tag',
220
+ 'adm' => 'Adometry Tag',
221
+ 'asp' => 'AdRoll Smart Pixel Tag',
222
+ 'awct' => 'Google Ads Conversion Tracking Tag',
223
+ 'sp' => 'Google Ads Remarketing Tag',
224
+ 'awc' => 'Affiliate Window Conversion Tag',
225
+ 'awj' => 'Affiliate Window Journey Tag',
226
+ 'baut' => 'Bing Ads Universal Event Tracking',
227
+ 'bb' => 'Bizrate Insights Buyer Survey Solution',
228
+ 'bsa' => 'Bizrate Insights Site Abandonment Survey Solution',
229
+ 'cts' => 'ClickTale Standard Tracking Tag',
230
+ 'csm' => 'comScore Unified Digital Measurement Tag',
231
+ 'mpm' => 'Conversant Mediaplex - IFRAME MCT Tag',
232
+ 'mpr' => 'Conversant Mediaplex - Standard IMG ROI Tag',
233
+ 'gclidw' => 'Conversion Linker',
234
+ 'cegg' => 'Crazy Egg Tag',
235
+ 'crto' => 'Criteo OneTag',
236
+ 'html' => 'Custom HTML Tag',
237
+ 'img' => 'Custom Image Tag',
238
+ 'dstag' => 'DistroScale Tag',
239
+ 'flc' => 'Floodlight Counter Tag',
240
+ 'fls' => 'Floodlight Sales Tag',
241
+ 'm6d' => 'Dstillery Universal Pixel Tag',
242
+ 'ela' => 'Eulerian Analytics Tag',
243
+ 'ga' => 'Google Analytics Tag (classic, legacy)',
244
+ 'ua' => 'Google Analytics Tag (universal, latest)',
245
+ 'gcs' => 'Google Consumer Surveys Website Satisfaction',
246
+ 'opt' => 'Google Optimize',
247
+ 'ts' => 'Google Trusted Stores Tag',
248
+ 'hjtc' => 'Hotjar Tracking Code',
249
+ 'infinity' => 'Infinity Call Tracking Tag',
250
+ 'sca' => 'Intent Media - Search Compare Ads',
251
+ 'k50Init' => 'K50 tracking tag',
252
+ 'll' => 'LeadLab',
253
+ 'bzi' => 'LinkedIn Tag',
254
+ 'ljs' => 'Lytics JS Tag',
255
+ 'ms' => 'Marin Software Tag',
256
+ 'mpm' => 'Mediaplex - IFRAME MCT Tag',
257
+ 'mpr' => 'Mediaplex - Standard IMG ROI Tag',
258
+ 'messagemate' => 'Message Mate',
259
+ 'mf' => 'Mouseflow Tag',
260
+ 'ta' => 'Neustar Pixel',
261
+ 'ndcr' => 'Nielsen DCR Static Lite Tag',
262
+ 'nudge' => 'Nudge Content Analytics Tag',
263
+ 'okt' => 'Oktopost Tracking Code',
264
+ 'omc' => 'Optimise Conversion Tag',
265
+ 'messagemate' => 'OwnerListens Message Mate',
266
+ 'pa' => 'Perfect Audience Pixel',
267
+ 'pc' => 'Personali Canvas',
268
+ 'pntr' => 'Pinterest',
269
+ 'placedPixel' => 'Placed',
270
+ 'pijs' => 'Pulse Insights Voice of Customer Platform',
271
+ 'qcm' => 'Quantcast Audience Measurement',
272
+ 'qpx' => 'Quora Pixel',
273
+ 'fxm' => 'Rawsoft FoxMetrics',
274
+ 'scjs' => 'SaleCycle JavaScript Tag',
275
+ 'scp' => 'SaleCycle Pixel Tag',
276
+ 'sfc' => 'SearchForce JavaScript Tracking for Conversion Page',
277
+ 'sfl' => 'SearchForce JavaScript Tracking for Landing Page',
278
+ 'sfr' => 'SearchForce Redirection Tracking Tag',
279
+ 'shareaholic' => 'Shareaholic',
280
+ 'svw' => 'Survicate Widget',
281
+ 'tdlc' => 'Tradedoubler Lead Conversion Tag',
282
+ 'tdsc' => 'Tradedoubler Sale Conversion Tag',
283
+ 'tc' => 'Turn Conversion Tracking Tag',
284
+ 'tdc' => 'Turn Data Collection Tag',
285
+ 'twitter_website_tag' => 'Twitter Universal Website Tag',
286
+ 'uslt' => 'Upsellit Global Footer Tag',
287
+ 'uspt' => 'Upsellit Confirmation Tag',
288
+ 'vei' => 'Ve Interactive JavaScript Tag',
289
+ 'veip' => 'Ve Interactive Pixel',
290
+ 'vdc' => 'VisualDNA Conversion Tag',
291
+ 'xpsh' => 'Xtremepush',
292
+ 'yieldify' => 'Yieldify',
293
+ 'zone' => 'Zones'
294
+ ),
295
+ 'triggers' => array(
296
+ 'evl' => 'Element Visibility Listener/Trigger',
297
+ 'cl' => 'Click Listener/Trigger',
298
+ 'fsl' => 'Form Submit Listener/Trigger',
299
+ 'hl' => 'History Listener/Trigger',
300
+ 'jel' => 'JavaScript Error Listener/Trigger',
301
+ 'lcl' => 'Link Click Listener/Trigger',
302
+ 'sdl' => 'Scroll Depth Listener/Trigger',
303
+ 'tl' => 'Timer Listener/Trigger',
304
+ 'ytl' => 'YouTube Video Listener/Trigger'
305
+ ),
306
+ 'variables' => array(
307
+ 'k' => '1st Party Cookie',
308
+ 'c' => 'Constant',
309
+ 'ctv' => 'Container Version Number',
310
+ 'e' => 'Custom Event',
311
+ 'jsm' => 'Custom JavaScript Variable',
312
+ 'v' => 'Data Layer Variable',
313
+ 'dbg' => 'Debug Mode',
314
+ 'd' => 'DOM Element',
315
+ 'vis' => 'Element Visibility',
316
+ 'f' => 'HTTP Referrer',
317
+ 'j' => 'JavaScript Variable',
318
+ 'smm' => 'Lookup Table',
319
+ 'r' => 'Random Number',
320
+ 'remm' => 'RegEx Table',
321
+ 'u' => 'URL'
322
+ )
323
+ );
324
+
325
+ function gtm4wp_migrate_blacklist_whitelist( $current_options ) {
326
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] > 0 ) {
327
+ $_gtmrestrictlistitems = array();
328
+
329
+ // IDs from https://developers.google.com/tag-manager/devguide#security
330
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_ADADVISOR ] ) {
331
+ $_gtmrestrictlistitems[] = 'ta';
332
+ }
333
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_ADROLL ] ) {
334
+ $_gtmrestrictlistitems[] = 'asp';
335
+ }
336
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_AWCONV ] ) {
337
+ $_gtmrestrictlistitems[] = 'awct';
338
+ }
339
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_AWREMARKET ] ) {
340
+ $_gtmrestrictlistitems[] = 'sp';
341
+ }
342
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_BIZO ] ) {
343
+ $_gtmrestrictlistitems[] = 'bzi';
344
+ }
345
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_CLICKTALE ] ) {
346
+ $_gtmrestrictlistitems[] = 'cts';
347
+ }
348
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_COMSCORE ] ) {
349
+ $_gtmrestrictlistitems[] = 'csm';
350
+ }
351
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_CUSTOMHTML ] ) {
352
+ $_gtmrestrictlistitems[] = 'html';
353
+ }
354
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_CUSTOMIMG ] ) {
355
+ $_gtmrestrictlistitems[] = 'img';
356
+ }
357
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_DBLCLKCOUNT ] ) {
358
+ $_gtmrestrictlistitems[] = 'flc';
359
+ }
360
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_DBLCLKSALES ] ) {
361
+ $_gtmrestrictlistitems[] = 'fls';
362
+ }
363
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_GACLASSIC ] ) {
364
+ $_gtmrestrictlistitems[] = 'ga';
365
+ }
366
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_MARIN ] ) {
367
+ $_gtmrestrictlistitems[] = 'ms';
368
+ }
369
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_MPLEXIFRAME ] ) {
370
+ $_gtmrestrictlistitems[] = 'mpm';
371
+ }
372
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_MPLEXROI ] ) {
373
+ $_gtmrestrictlistitems[] = 'mpr';
374
+ }
375
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_MEDIA6DEG ] ) {
376
+ $_gtmrestrictlistitems[] = 'm6d';
377
+ }
378
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_TURNCONV ] ) {
379
+ $_gtmrestrictlistitems[] = 'tc';
380
+ }
381
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_TURNDATA ] ) {
382
+ $_gtmrestrictlistitems[] = 'tdc';
383
+ }
384
+ if ( $current_options[ GTM4WP_OPTION_BLACKLIST_UA ] ) {
385
+ $_gtmrestrictlistitems[] = 'ua';
386
+ }
387
+
388
+ $current_options[ GTM4WP_OPTION_BLACKLIST_STATUS ] = implode( ',', $_gtmrestrictlistitems );
389
+ }
390
+
391
+ return $current_options;
392
+ }
393
+
394
+ function gtm4wp_reload_options() {
395
+ global $gtm4wp_defaultoptions;
396
+
397
+ $storedoptions = (array) get_option( GTM4WP_OPTIONS );
398
+ if ( ! is_array( $gtm4wp_defaultoptions ) ) {
399
+ $gtm4wp_defaultoptions = array();
400
+ }
401
+
402
+ if ( !isset( $storedoptions[ GTM4WP_OPTION_BLACKLIST_STATUS ] ) ) {
403
+ $storedoptions = gtm4wp_migrate_blacklist_whitelist( $storedoptions );
404
+ }
405
+
406
+ $return_options = array_merge( $gtm4wp_defaultoptions, $storedoptions );
407
+ $return_options[ GTM4WP_OPTION_BLACKLIST_STATUS ] = explode( ',', $return_options[ GTM4WP_OPTION_BLACKLIST_STATUS ] );
408
+
409
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ID' ) ) {
410
+ $return_options[ GTM4WP_OPTION_GTM_CODE ] = GTM4WP_HARDCODED_GTM_ID;
411
+ }
412
+
413
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_AUTH' ) ) {
414
+ $return_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] = GTM4WP_HARDCODED_GTM_ENV_AUTH;
415
+ }
416
+
417
+ if ( defined( 'GTM4WP_HARDCODED_GTM_ENV_PREVIEW' ) ) {
418
+ $return_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] = GTM4WP_HARDCODED_GTM_ENV_PREVIEW;
419
+ }
420
+
421
+ return $return_options;
422
+ }
423
+
424
+ function gtp4wp_debug_file( $debug_data ) {
425
+ $fp = fopen( dirname( __FILE__ ) . '/' . date( 'Y-m-d-H-i-s-u' ) . '.txt', 'w' );
426
+ if ( $fp ) {
427
+ fwrite( $fp, $debug_data );
428
+ fclose( $fp );
429
+ }
430
+ }
431
+
432
+ $gtm4wp_options = gtm4wp_reload_options();
css/admin-gtm4wp.css CHANGED
@@ -1,72 +1,72 @@
1
- .tabinfo {
2
- display: block;
3
- clear: both;
4
- margin: 20px 10px;
5
- }
6
-
7
- .gtm4wp-plugin-active {
8
- color: #0c0;
9
- }
10
-
11
- .gtm4wp-plugin-not-active {
12
- color: #c00;
13
- }
14
-
15
- .adminsubtabs {
16
- list-style: none;
17
- margin: 16px 0;
18
- padding: 0;
19
- font-size: 13px;
20
- float: left;
21
- color: #666;
22
- }
23
-
24
- .adminsubtabs li {
25
- display: inline-block;
26
- margin: 0;
27
- padding: 0 10px;
28
- white-space: nowrap;
29
- border-right: 1px solid #666;
30
- }
31
-
32
- .adminsubtabs li:last-child {
33
- border-right: 0;
34
- }
35
-
36
- .adminsubtabs a {
37
- padding: .2em;
38
- text-decoration: none;
39
- }
40
-
41
- .adminsubtabs a.subtab-active {
42
- color: #000;
43
- font-weight: bold;
44
- }
45
-
46
- .gtm4wp-phase-beta,
47
- .gtm4wp-phase-experimental,
48
- .gtm4wp-phase-deprecated {
49
- display: inline-block;
50
- background-color: #f00;
51
- color: #fff;
52
- font-size: 9px;
53
- padding: 2px;
54
- margin-left: 5px;
55
- }
56
-
57
- .gtm4wp-phase-beta:before {
58
- content: "beta";
59
- }
60
-
61
- .gtm4wp-phase-deprecated {
62
- background-color: #ddd;
63
- color: #000;
64
- }
65
-
66
- .gtm4wp-phase-experimental:before {
67
- content: "experimental";
68
- }
69
-
70
- .gtm4wp-phase-deprecated:before {
71
- content: "deprecated";
72
  }
1
+ .tabinfo {
2
+ display: block;
3
+ clear: both;
4
+ margin: 20px 10px;
5
+ }
6
+
7
+ .gtm4wp-plugin-active {
8
+ color: #0c0;
9
+ }
10
+
11
+ .gtm4wp-plugin-not-active {
12
+ color: #c00;
13
+ }
14
+
15
+ .adminsubtabs {
16
+ list-style: none;
17
+ margin: 16px 0;
18
+ padding: 0;
19
+ font-size: 13px;
20
+ float: left;
21
+ color: #666;
22
+ }
23
+
24
+ .adminsubtabs li {
25
+ display: inline-block;
26
+ margin: 0;
27
+ padding: 0 10px;
28
+ white-space: nowrap;
29
+ border-right: 1px solid #666;
30
+ }
31
+
32
+ .adminsubtabs li:last-child {
33
+ border-right: 0;
34
+ }
35
+
36
+ .adminsubtabs a {
37
+ padding: .2em;
38
+ text-decoration: none;
39
+ }
40
+
41
+ .adminsubtabs a.subtab-active {
42
+ color: #000;
43
+ font-weight: bold;
44
+ }
45
+
46
+ .gtm4wp-phase-beta,
47
+ .gtm4wp-phase-experimental,
48
+ .gtm4wp-phase-deprecated {
49
+ display: inline-block;
50
+ background-color: #f00;
51
+ color: #fff;
52
+ font-size: 9px;
53
+ padding: 2px;
54
+ margin-left: 5px;
55
+ }
56
+
57
+ .gtm4wp-phase-beta:before {
58
+ content: "beta";
59
+ }
60
+
61
+ .gtm4wp-phase-deprecated {
62
+ background-color: #ddd;
63
+ color: #000;
64
+ }
65
+
66
+ .gtm4wp-phase-experimental:before {
67
+ content: "experimental";
68
+ }
69
+
70
+ .gtm4wp-phase-deprecated:before {
71
+ content: "deprecated";
72
  }
duracelltomi-google-tag-manager-for-wordpress.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
- Version: 1.11.6
5
  Plugin URI: https://gtm4wp.com/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
@@ -9,11 +9,11 @@ Author URI: https://gtm4wp.com/
9
  Text Domain: duracelltomi-google-tag-manager
10
  Domain Path: /languages
11
 
12
- WC requires at least: 2.6
13
- WC tested up to: 4.7.0
14
  */
15
 
16
- define( 'GTM4WP_VERSION', '1.11.6' );
17
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
  global $gtp4wp_plugin_url, $gtp4wp_plugin_basename;
1
  <?php
2
  /*
3
  Plugin Name: Google Tag Manager for Wordpress
4
+ Version: 1.12
5
  Plugin URI: https://gtm4wp.com/
6
  Description: The first Google Tag Manager plugin for WordPress with business goals in mind
7
  Author: Thomas Geiger
9
  Text Domain: duracelltomi-google-tag-manager
10
  Domain Path: /languages
11
 
12
+ WC requires at least: 3.2
13
+ WC tested up to: 5.1.0
14
  */
15
 
16
+ define( 'GTM4WP_VERSION', '1.12' );
17
  define( 'GTM4WP_PATH', plugin_dir_path( __FILE__ ) );
18
 
19
  global $gtp4wp_plugin_url, $gtp4wp_plugin_basename;
integration/amp.php CHANGED
@@ -1,161 +1,161 @@
1
- <?php
2
- /**
3
- * AMP (Accelerated Mobile Pages Support) for gtm4wp
4
- *
5
- * This intergration added AMP support when using amp-wp, the existing dataLayer used
6
- * for Google Tag Manager on HTML is loaded and built into AMP compatible code.
7
- *
8
- * @author Vincent Koc <https://github.com/koconder/>
9
- * @package gtm4wp
10
- */
11
-
12
- /**
13
- *
14
- * Todo's
15
- *
16
- * - Better handling of gtm4wp_amp_gtmampcode_check() to allow for other plugins
17
- * - Develop array's into strings as AMP GTM dose not allow custom js variables
18
- * - Better Client ID support (https://github.com/Automattic/amp-wp/issues/775)
19
- * - Update AMP cache on GTM changes (https://github.com/Automattic/amp-wp/pull/605)
20
- * - Supporting PWA with SuperPWA intergration with AMP and PWA for offline
21
- */
22
-
23
-
24
- /**
25
- * Check if we are running AMP
26
- *
27
- * @author Vincent Koc <https://github.com/koconder/>
28
- * @return bool Returns true if we are running on an AMP page
29
- */
30
- function gtm4wp_amp_running() {
31
- if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
32
- return true;
33
- }
34
-
35
- return false;
36
- }
37
-
38
- /**
39
- * Pre-injection Check AMP Project's AMP Analytics tag, using amp-wp hook
40
- *
41
- * @link https://github.com/Automattic/amp-wp/blob/develop/includes/amp-post-template-actions.php
42
- * @author Vincent Koc <https://github.com/koconder/>
43
- * @return array Returns AMP Analytics array used by amp-wp
44
- */
45
- function gtm4wp_amp_gtmampcode_check( $data ) {
46
- global $gtm4wp_amp_headerinjected;
47
-
48
- //run once
49
- if($gtm4wp_amp_headerinjected){
50
- return $data;
51
- }
52
-
53
- // AMP-WP Plugin
54
- if ( ! empty( $data['amp_analytics'] ) ) {
55
- // Inject into AMP Plugin to load
56
- $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
57
- $gtm4wp_amp_headerinjected = true;
58
-
59
- // Manually load into AMP-WP Plugin
60
- } else {
61
- // Inject manually based on AMP <head> hook
62
- add_action( 'amp_post_template_head', 'gtm4wp_amp_gtmampcode_injecthead' );
63
- }
64
-
65
- // Return the $data back to amp-wp hook
66
- return $data;
67
- }
68
-
69
- /**
70
- * Post-check AMP Project's AMP Analytics tag, using amp-wp hook
71
- *
72
- * @link https://github.com/Automattic/amp-wp/blob/develop/includes/amp-post-template-actions.php
73
- * @author Vincent Koc <https://github.com/koconder/>
74
- */
75
- function gtm4wp_amp_gtmampcode_injecthead() {
76
- global $gtm4wp_amp_headerinjected;
77
-
78
- $gtm4wp_amp_headerinjected = true;
79
- echo '<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>';
80
- }
81
-
82
- /**
83
- * Generate AMP ready Google Tag Manager code
84
- *
85
- * @author Vincent Koc <https://github.com/koconder/>
86
- * @return int Returns number of injected snippets, false if no injection
87
- */
88
- function gtm4wp_amp_gtmcode() {
89
- global $gtm4wp_datalayer_json, $gtm4wp_options, $gtm4wp_amp_bodyinjected;
90
-
91
- //run once
92
- if($gtm4wp_amp_bodyinjected){
93
- return false;
94
- }
95
-
96
- $gtm4wp_amp_bodyinjected = true;
97
- // Check dataLayer is loaded from the plugin
98
- if ( ! empty( $gtm4wp_datalayer_json ) ) {
99
-
100
- // Builds a list of GTM id's
101
- $gtm4wp_ampids = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_AMPID ] );
102
- $gtm4wp_ampid_list = array();
103
-
104
- // Counter used for status return
105
- $x = 0;
106
-
107
- // Check we have more than one valid Google Tag Manager ID
108
- if ( count( $gtm4wp_ampids ) > 0 ) {
109
-
110
- // Loop through each GTM idea and build the AMP GTM code
111
- foreach ( $gtm4wp_ampids as $gtm4wp_oneampid ) {
112
-
113
- // Docs: https://developers.google.com/analytics/devguides/collection/amp-analytics/
114
- // Examples: from https://www.simoahava.com/analytics/accelerated-mobile-pages-via-google-tag-manager/
115
- // Inject the AMP GTM code
116
- // TODO: Use AMP classes to enable cross-compatibility with other future plugins
117
- echo '<!-- Google Tag Manager --><amp-analytics config="https://www.googletagmanager.com/amp.json?id=' . $gtm4wp_oneampid . '&gtm.url=SOURCE_URL" data-credentials="include">' . gtm4wp_amp_gtmvariables() . '</amp-analytics>';
118
-
119
- // Add to counter
120
- $x++;
121
- }
122
-
123
- // Check how many injections for return
124
- if ( $x > 0 ) {
125
- return $x;
126
- }
127
- }
128
- }
129
-
130
- // No injection has occured
131
- return false;
132
- }
133
-
134
- /**
135
- * Generate the AMP "vars" from the GTM dataLayer
136
- *
137
- * @author Vincent Koc <https://github.com/koconder/>
138
- * @return string Returns json dataLayer for AMP code
139
- */
140
- function gtm4wp_amp_gtmvariables() {
141
- global $gtm4wp_datalayer_json;
142
- return '{"vars":{' . $gtm4wp_datalayer_json . '} }';
143
- }
144
-
145
-
146
- // Set Status at start
147
- $gtm4wp_amp_headerinjected = false;
148
- $gtm4wp_amp_bodyinjected = false;
149
-
150
- // Load AMP-Analytics tag into <head>
151
- add_action( 'amp_post_template_data', 'gtm4wp_amp_gtmampcode_check' );
152
-
153
- // Load the GTM code processing to gain the GTM DataLayer
154
- add_action( 'amp_post_template_head', 'gtm4wp_wp_header_begin' );
155
- add_action( 'amp_post_template_head', 'gtm4wp_wp_header_top', 1 );
156
-
157
- // Try amp_wp_body_open
158
- // (https://github.com/Automattic/amp-wp/pull/1143)
159
- add_action( 'amp_post_template_body_open', 'gtm4wp_amp_gtmcode');
160
- // Publish the GTM code and dataLayer to the footer
161
- add_action( 'amp_post_template_footer', 'gtm4wp_amp_gtmcode' );
1
+ <?php
2
+ /**
3
+ * AMP (Accelerated Mobile Pages Support) for gtm4wp
4
+ *
5
+ * This intergration added AMP support when using amp-wp, the existing dataLayer used
6
+ * for Google Tag Manager on HTML is loaded and built into AMP compatible code.
7
+ *
8
+ * @author Vincent Koc <https://github.com/koconder/>
9
+ * @package gtm4wp
10
+ */
11
+
12
+ /**
13
+ *
14
+ * Todo's
15
+ *
16
+ * - Better handling of gtm4wp_amp_gtmampcode_check() to allow for other plugins
17
+ * - Develop array's into strings as AMP GTM dose not allow custom js variables
18
+ * - Better Client ID support (https://github.com/Automattic/amp-wp/issues/775)
19
+ * - Update AMP cache on GTM changes (https://github.com/Automattic/amp-wp/pull/605)
20
+ * - Supporting PWA with SuperPWA intergration with AMP and PWA for offline
21
+ */
22
+
23
+
24
+ /**
25
+ * Check if we are running AMP
26
+ *
27
+ * @author Vincent Koc <https://github.com/koconder/>
28
+ * @return bool Returns true if we are running on an AMP page
29
+ */
30
+ function gtm4wp_amp_running() {
31
+ if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) {
32
+ return true;
33
+ }
34
+
35
+ return false;
36
+ }
37
+
38
+ /**
39
+ * Pre-injection Check AMP Project's AMP Analytics tag, using amp-wp hook
40
+ *
41
+ * @link https://github.com/Automattic/amp-wp/blob/develop/includes/amp-post-template-actions.php
42
+ * @author Vincent Koc <https://github.com/koconder/>
43
+ * @return array Returns AMP Analytics array used by amp-wp
44
+ */
45
+ function gtm4wp_amp_gtmampcode_check( $data ) {
46
+ global $gtm4wp_amp_headerinjected;
47
+
48
+ //run once
49
+ if($gtm4wp_amp_headerinjected){
50
+ return $data;
51
+ }
52
+
53
+ // AMP-WP Plugin
54
+ if ( ! empty( $data['amp_analytics'] ) ) {
55
+ // Inject into AMP Plugin to load
56
+ $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
57
+ $gtm4wp_amp_headerinjected = true;
58
+
59
+ // Manually load into AMP-WP Plugin
60
+ } else {
61
+ // Inject manually based on AMP <head> hook
62
+ add_action( 'amp_post_template_head', 'gtm4wp_amp_gtmampcode_injecthead' );
63
+ }
64
+
65
+ // Return the $data back to amp-wp hook
66
+ return $data;
67
+ }
68
+
69
+ /**
70
+ * Post-check AMP Project's AMP Analytics tag, using amp-wp hook
71
+ *
72
+ * @link https://github.com/Automattic/amp-wp/blob/develop/includes/amp-post-template-actions.php
73
+ * @author Vincent Koc <https://github.com/koconder/>
74
+ */
75
+ function gtm4wp_amp_gtmampcode_injecthead() {
76
+ global $gtm4wp_amp_headerinjected;
77
+
78
+ $gtm4wp_amp_headerinjected = true;
79
+ echo '<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>';
80
+ }
81
+
82
+ /**
83
+ * Generate AMP ready Google Tag Manager code
84
+ *
85
+ * @author Vincent Koc <https://github.com/koconder/>
86
+ * @return int Returns number of injected snippets, false if no injection
87
+ */
88
+ function gtm4wp_amp_gtmcode() {
89
+ global $gtm4wp_datalayer_json, $gtm4wp_options, $gtm4wp_amp_bodyinjected;
90
+
91
+ //run once
92
+ if($gtm4wp_amp_bodyinjected){
93
+ return false;
94
+ }
95
+
96
+ $gtm4wp_amp_bodyinjected = true;
97
+ // Check dataLayer is loaded from the plugin
98
+ if ( ! empty( $gtm4wp_datalayer_json ) ) {
99
+
100
+ // Builds a list of GTM id's
101
+ $gtm4wp_ampids = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_AMPID ] );
102
+ $gtm4wp_ampid_list = array();
103
+
104
+ // Counter used for status return
105
+ $x = 0;
106
+
107
+ // Check we have more than one valid Google Tag Manager ID
108
+ if ( count( $gtm4wp_ampids ) > 0 ) {
109
+
110
+ // Loop through each GTM idea and build the AMP GTM code
111
+ foreach ( $gtm4wp_ampids as $gtm4wp_oneampid ) {
112
+
113
+ // Docs: https://developers.google.com/analytics/devguides/collection/amp-analytics/
114
+ // Examples: from https://www.simoahava.com/analytics/accelerated-mobile-pages-via-google-tag-manager/
115
+ // Inject the AMP GTM code
116
+ // TODO: Use AMP classes to enable cross-compatibility with other future plugins
117
+ echo '<!-- Google Tag Manager --><amp-analytics config="https://www.googletagmanager.com/amp.json?id=' . $gtm4wp_oneampid . '&gtm.url=SOURCE_URL" data-credentials="include"><script type="application/json">' . gtm4wp_amp_gtmvariables() . '</script></amp-analytics>';
118
+
119
+ // Add to counter
120
+ $x++;
121
+ }
122
+
123
+ // Check how many injections for return
124
+ if ( $x > 0 ) {
125
+ return $x;
126
+ }
127
+ }
128
+ }
129
+
130
+ // No injection has occured
131
+ return false;
132
+ }
133
+
134
+ /**
135
+ * Generate the AMP "vars" from the GTM dataLayer
136
+ *
137
+ * @author Vincent Koc <https://github.com/koconder/>
138
+ * @return string Returns json dataLayer for AMP code
139
+ */
140
+ function gtm4wp_amp_gtmvariables() {
141
+ global $gtm4wp_datalayer_json;
142
+ return '{"vars":' . $gtm4wp_datalayer_json . ' }';
143
+ }
144
+
145
+
146
+ // Set Status at start
147
+ $gtm4wp_amp_headerinjected = false;
148
+ $gtm4wp_amp_bodyinjected = false;
149
+
150
+ // Load AMP-Analytics tag into <head>
151
+ add_action( 'amp_post_template_data', 'gtm4wp_amp_gtmampcode_check' );
152
+
153
+ // Load the GTM code processing to gain the GTM DataLayer
154
+ add_action( 'amp_post_template_head', 'gtm4wp_wp_header_begin' );
155
+ add_action( 'amp_post_template_head', 'gtm4wp_wp_header_top', 1 );
156
+
157
+ // Try amp_wp_body_open
158
+ // (https://github.com/Automattic/amp-wp/pull/1143)
159
+ add_action( 'amp_post_template_body_open', 'gtm4wp_amp_gtmcode');
160
+ // Publish the GTM code and dataLayer to the footer
161
+ add_action( 'amp_post_template_footer', 'gtm4wp_amp_gtmcode' );
integration/google-optimize.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- function gtm4wp_go_pagehiding_snippet() {
3
- global $gtm4wp_options;
4
-
5
- $gtm4wp_goids = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] );
6
- $gtm4wp_goid_pagehiding_list = array();
7
- if ( count( $gtm4wp_goids ) > 0 ) {
8
- foreach ( $gtm4wp_goids as $gtm4wp_onegoid ) {
9
- $gtm4wp_goid_pagehiding_list[] = "'" . $gtm4wp_onegoid . "': true";
10
- }
11
-
12
- $gtm4wp_gotimeout = (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT ];
13
- if ( 0 == $gtm4wp_gotimeout ) {
14
- $gtm4wp_gotimeout = 4000;
15
- }
16
-
17
- echo "
18
- <!-- GTM4WP: Google Optimize Anti-flicker snippet -->
19
- <style>
20
- .async-hide {
21
- opacity: 0 !important
22
- }
23
- </style>
24
- <script>
25
- (function(a,s,y,n,c,h,i,d,e) {
26
- s.className+=' '+y;
27
- h.start=1*new Date;
28
- h.end=i=function() {
29
- s.className=s.className.replace(RegExp(' ?'+y),'')
30
- };
31
- (a[n]=a[n]||[]).hide=h;
32
- setTimeout(function() {
33
- i();
34
- h.end=null
35
- },c);
36
- h.timeout=c;
37
- })(window,document.documentElement,'async-hide','dataLayer'," . $gtm4wp_gotimeout . ",{" . implode( ", ", $gtm4wp_goid_pagehiding_list ) . "});
38
- </script>
39
- <!-- GTM4WP: End of Google Optimize Page Hiding snippet -->";
40
- }
41
- }
42
-
43
- function gtm4wp_go_snippet( $content ) {
44
- global $gtm4wp_options;
45
-
46
- $gtm4wp_goids = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] );
47
- $gtm4wp_goid_list = array();
48
- if ( count( $gtm4wp_goids ) > 0 ) {
49
- foreach ( $gtm4wp_goids as $gtm4wp_onegoid ) {
50
- $gtm4wp_goid_list[] = '
51
- <script src="https://www.googleoptimize.com/optimize.js?id=' . $gtm4wp_onegoid . '" onerror="dataLayer.hide.end && dataLayer.hide.end()"></script>';
52
- }
53
-
54
- $content .= "
55
- <!-- GTM4WP: Load Google Optimize containers -->
56
- " . implode("", $gtm4wp_goid_list) . "
57
- <!-- GTM4WP: End of Load Google Optimize containers -->";
58
- }
59
-
60
- return $content;
61
- }
62
-
63
- add_action( 'wp_head', 'gtm4wp_go_pagehiding_snippet', 1 );
64
- add_filter( GTM4WP_WPFILTER_AFTER_DATALAYER, 'gtm4wp_go_snippet' );
1
+ <?php
2
+ function gtm4wp_go_pagehiding_snippet() {
3
+ global $gtm4wp_options;
4
+
5
+ $gtm4wp_goids = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] );
6
+ $gtm4wp_goid_pagehiding_list = array();
7
+ if ( count( $gtm4wp_goids ) > 0 ) {
8
+ foreach ( $gtm4wp_goids as $gtm4wp_onegoid ) {
9
+ $gtm4wp_goid_pagehiding_list[] = "'" . $gtm4wp_onegoid . "': true";
10
+ }
11
+
12
+ $gtm4wp_gotimeout = (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZETIMEOUT ];
13
+ if ( 0 == $gtm4wp_gotimeout ) {
14
+ $gtm4wp_gotimeout = 4000;
15
+ }
16
+
17
+ echo "
18
+ <!-- GTM4WP: Google Optimize Anti-flicker snippet -->
19
+ <style>
20
+ .async-hide {
21
+ opacity: 0 !important
22
+ }
23
+ </style>
24
+ <script>
25
+ (function(a,s,y,n,c,h,i,d,e) {
26
+ s.className+=' '+y;
27
+ h.start=1*new Date;
28
+ h.end=i=function() {
29
+ s.className=s.className.replace(RegExp(' ?'+y),'')
30
+ };
31
+ (a[n]=a[n]||[]).hide=h;
32
+ setTimeout(function() {
33
+ i();
34
+ h.end=null
35
+ },c);
36
+ h.timeout=c;
37
+ })(window,document.documentElement,'async-hide','dataLayer'," . $gtm4wp_gotimeout . ",{" . implode( ", ", $gtm4wp_goid_pagehiding_list ) . "});
38
+ </script>
39
+ <!-- GTM4WP: End of Google Optimize Page Hiding snippet -->";
40
+ }
41
+ }
42
+
43
+ function gtm4wp_go_snippet( $content ) {
44
+ global $gtm4wp_options;
45
+
46
+ $gtm4wp_goids = explode( ',', $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] );
47
+ $gtm4wp_goid_list = array();
48
+ if ( count( $gtm4wp_goids ) > 0 ) {
49
+ foreach ( $gtm4wp_goids as $gtm4wp_onegoid ) {
50
+ $gtm4wp_goid_list[] = '
51
+ <script src="https://www.googleoptimize.com/optimize.js?id=' . $gtm4wp_onegoid . '" onerror="dataLayer.hide.end && dataLayer.hide.end()"></script>';
52
+ }
53
+
54
+ $content .= "
55
+ <!-- GTM4WP: Load Google Optimize containers -->
56
+ " . implode("", $gtm4wp_goid_list) . "
57
+ <!-- GTM4WP: End of Load Google Optimize containers -->";
58
+ }
59
+
60
+ return $content;
61
+ }
62
+
63
+ add_action( 'wp_head', 'gtm4wp_go_pagehiding_snippet', 1 );
64
+ add_filter( GTM4WP_WPFILTER_AFTER_DATALAYER, 'gtm4wp_go_snippet' );
integration/soundcloud.php CHANGED
@@ -1,6 +1,6 @@
1
- <?php
2
- if ( ! is_admin() ) {
3
- $in_footer = apply_filters( 'gtm4wp_soundcloud', false );
4
- wp_enqueue_script( 'gtm4wp-soundcloud-api', 'https://w.soundcloud.com/player/api.js', array(), '1.0', $in_footer );
5
- wp_enqueue_script( 'gtm4wp-soundcloud', $gtp4wp_plugin_url . 'js/gtm4wp-soundcloud.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
6
- }
1
+ <?php
2
+ if ( ! is_admin() ) {
3
+ $in_footer = apply_filters( 'gtm4wp_soundcloud', false );
4
+ wp_enqueue_script( 'gtm4wp-soundcloud-api', 'https://w.soundcloud.com/player/api.js', array(), '1.0', $in_footer );
5
+ wp_enqueue_script( 'gtm4wp-soundcloud', $gtp4wp_plugin_url . 'js/gtm4wp-soundcloud.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
6
+ }
integration/vimeo.php CHANGED
@@ -1,7 +1,7 @@
1
- <?php
2
- if ( ! is_admin() ) {
3
- $in_footer = apply_filters( 'gtm4wp_vimeo', false );
4
- // wp_enqueue_script( "gtm4wp-vimeo-froogaloop", $gtp4wp_plugin_url . "js/froogaloop.js", array(), "2.0", $in_footer );
5
- wp_enqueue_script( 'gtm4wp-vimeo-api', 'https://player.vimeo.com/api/player.js', array(), '1.0', $in_footer );
6
- wp_enqueue_script( 'gtm4wp-vimeo', $gtp4wp_plugin_url . 'js/gtm4wp-vimeo.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
7
- }
1
+ <?php
2
+ if ( ! is_admin() ) {
3
+ $in_footer = apply_filters( 'gtm4wp_vimeo', false );
4
+ // wp_enqueue_script( "gtm4wp-vimeo-froogaloop", $gtp4wp_plugin_url . "js/froogaloop.js", array(), "2.0", $in_footer );
5
+ wp_enqueue_script( 'gtm4wp-vimeo-api', 'https://player.vimeo.com/api/player.js', array(), '1.0', $in_footer );
6
+ wp_enqueue_script( 'gtm4wp-vimeo', $gtp4wp_plugin_url . 'js/gtm4wp-vimeo.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
7
+ }
integration/woocommerce.php CHANGED
@@ -6,24 +6,12 @@ define( 'GTM4WP_WPFILTER_EEC_ORDER_ITEM', 'gtm4wp_eec_order_item' );
6
  $gtm4wp_product_counter = 0;
7
  $gtm4wp_last_widget_title = 'Sidebar Products';
8
  if ( function_exists( 'WC' ) ) {
9
- $GLOBALS['gtm4wp_is_woocommerce3'] = version_compare( WC()->version, '3.0', '>=' );
10
  $GLOBALS['gtm4wp_is_woocommerce3_7'] = version_compare( WC()->version, '3.7', '>=' );
11
  } else {
12
- $GLOBALS['gtm4wp_is_woocommerce3'] = false;
13
  $GLOBALS['gtm4wp_is_woocommerce3_7'] = false;
14
  }
15
  $GLOBALS['gtm4wp_grouped_product_ix'] = 1;
16
 
17
- function gtm4wp_woocommerce_addjs( $js ) {
18
- $woo = WC();
19
-
20
- if ( version_compare( $woo->version, '2.1', '>=' ) ) {
21
- wc_enqueue_js( $js );
22
- } else {
23
- $woo->add_inline_js( $js );
24
- }
25
- }
26
-
27
  // from https://snippets.webaware.com.au/ramblings/php-really-doesnt-unicode/
28
  function gtm4wp_untexturize( $fancy ) {
29
  $fixes = false;
@@ -114,7 +102,7 @@ function gtm4wp_woocommerce_getproductterm( $product_id, $taxonomy ) {
114
  }
115
 
116
  function gtm4wp_process_product( $product, $additional_product_attributes, $attributes_used_for ) {
117
- global $gtm4wp_options, $gtm4wp_is_woocommerce3;
118
 
119
  if ( ! $product ) {
120
  return false;
@@ -130,7 +118,7 @@ function gtm4wp_process_product( $product, $additional_product_attributes, $attr
130
  $product_sku = $product->get_sku();
131
 
132
  if ( 'variation' == $product_type ) {
133
- $parent_product_id = ( $gtm4wp_is_woocommerce3 ? $product->get_parent_id() : $product->id );
134
  $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
135
  } else {
136
  $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
@@ -168,8 +156,54 @@ function gtm4wp_process_product( $product, $additional_product_attributes, $attr
168
  return apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, $attributes_used_for );
169
  }
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  function gtm4wp_process_order_items( $order ) {
172
- global $gtm4wp_options, $gtm4wp_is_woocommerce3;
173
 
174
  $return_data = array(
175
  'products' => [],
@@ -189,7 +223,7 @@ function gtm4wp_process_order_items( $order ) {
189
  continue;
190
  }
191
 
192
- $product = ( $gtm4wp_is_woocommerce3 ? $item->get_product() : $order->get_product_from_item( $item ) );
193
  $inc_tax = ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) );
194
  $product_price = (float) $order->get_item_total( $item, $inc_tax );
195
  $eec_product_array = gtm4wp_process_product( $product, array(
@@ -210,7 +244,7 @@ function gtm4wp_process_order_items( $order ) {
210
 
211
  function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
212
  global $gtm4wp_options;
213
-
214
  if ( function_exists( 'WC' ) && WC()->cart ) {
215
  $gtm4wp_needs_shipping_address = (bool) WC()->cart->needs_shipping_address();
216
  } else {
@@ -231,11 +265,11 @@ function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
231
  }
232
 
233
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
234
- global $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3, $gtm4wp_is_woocommerce3_7;
235
 
236
  $woo = WC();
237
 
238
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA ] && $gtm4wp_is_woocommerce3 ) {
239
  if ( $woo->customer instanceof WC_Customer ) {
240
  // we need to use this instead of $woo->customer as this will load proper total order number and value from the database instead of the session
241
  $woo_customer = new WC_Customer( $woo->customer->get_id() );
@@ -285,7 +319,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
285
  if (
286
  !apply_filters( GTM4WP_WPFILTER_EEC_CART_ITEM, true, $cart_item_data )
287
  || !apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item_data, $cart_item_id )
288
- ) {
289
  continue;
290
  }
291
 
@@ -311,7 +345,10 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
311
  $dataLayer['ecomm_totalvalue'] = 0;
312
  }
313
  } elseif ( is_product() ) {
314
- if ( ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) ) {
 
 
 
315
  $postid = get_the_ID();
316
  $product = wc_get_product( $postid );
317
 
@@ -349,23 +386,31 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
349
  }
350
 
351
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
 
 
352
  $dataLayer['ecommerce'] = array(
353
- 'currencyCode' => get_woocommerce_currency(),
354
  'detail' => array(
355
  'products' => array(
356
  $eec_product_array
357
- ),
358
- ),
359
  );
360
  }
361
  }
362
  }
363
  }
364
  } elseif ( is_cart() ) {
365
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
 
 
 
 
366
  $gtm4wp_cart_products = array();
367
  $gtm4wp_cart_products_remarketing = array();
368
 
 
 
369
  foreach ( $woo->cart->get_cart() as $cart_item_id => $cart_item_data ) {
370
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data['data'], $cart_item_data, $cart_item_id );
371
 
@@ -377,10 +422,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
377
  'quantity' => $cart_item_data['quantity']
378
  ), 'cart' );
379
 
380
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
381
- $gtm4wp_cart_products[] = $eec_product_array;
382
- }
383
-
384
  $gtm4wp_cart_products_remarketing[] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
385
  }
386
 
@@ -395,16 +437,23 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
395
  $dataLayer['ecomm_totalvalue'] = (float) $cart_total;
396
  }
397
 
398
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
399
- $dataLayer['ecommerce'] = array(
400
- 'currencyCode' => get_woocommerce_currency(),
401
- 'checkout' => array(
402
- 'actionField' => array(
403
- 'step' => 1,
404
- ),
405
- 'products' => $gtm4wp_cart_products,
406
- ),
407
- );
 
 
 
 
 
 
 
408
  }
409
  }
410
  } elseif ( is_order_received_page() ) {
@@ -421,11 +470,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
421
  $order = wc_get_order( $order_id );
422
 
423
  if ( $order instanceof WC_Order ) {
424
- if ( $gtm4wp_is_woocommerce3 ) {
425
- $this_order_key = $order->get_order_key();
426
- } else {
427
- $this_order_key = $order->order_key;
428
- }
429
 
430
  if ( $this_order_key != $order_key ) {
431
  unset( $order );
@@ -435,7 +480,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
435
  }
436
  }
437
 
438
- if ( isset($order) && $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCORDERDATA ] && $gtm4wp_is_woocommerce3 ) {
439
  $order_items = gtm4wp_process_order_items( $order );
440
 
441
  $dataLayer['orderData'] = array(
@@ -516,16 +561,14 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
516
  $order_revenue = (float) $order->get_total();
517
  }
518
 
519
- if ( $gtm4wp_is_woocommerce3 ) {
520
- $order_shipping_cost = (float) $order->get_shipping_total();
521
- } else {
522
- $order_shipping_cost = (float) $order->get_total_shipping();
523
- }
524
 
525
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING ] ) {
526
  $order_revenue -= $order_shipping_cost;
527
  }
528
 
 
 
529
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
530
  $dataLayer['event'] = 'gtm4wp.orderCompleted';
531
  $dataLayer['transactionId'] = $order->get_order_number();
@@ -533,23 +576,23 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
533
  $dataLayer['transactionTotal'] = $order_revenue;
534
  $dataLayer['transactionShipping'] = $order_shipping_cost;
535
  $dataLayer['transactionTax'] = (float) $order->get_total_tax();
536
- $dataLayer['transactionCurrency'] = $order->get_currency();
537
  }
538
 
539
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
540
  $dataLayer['event'] = 'gtm4wp.orderCompletedEEC';
541
  $dataLayer['ecommerce'] = array(
542
- 'currencyCode' => $order->get_currency(),
543
  'purchase' => array(
544
  'actionField' => array(
545
  'id' => $order->get_order_number(),
546
  'affiliation' => '',
547
  'revenue' => $order_revenue,
548
  'tax' => (float) $order->get_total_tax(),
549
- 'shipping' => (float)( $gtm4wp_is_woocommerce3 ? $order->get_shipping_total() : $order->get_total_shipping() ),
550
  'coupon' => implode( ', ', ( $gtm4wp_is_woocommerce3_7 ? $order->get_coupon_codes() : $order->get_used_coupons() ) ),
551
- ),
552
- ),
553
  );
554
  }
555
 
@@ -576,7 +619,10 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
576
  }
577
  }
578
  } elseif ( is_checkout() ) {
579
- if ( ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] ) ) {
 
 
 
580
  $gtm4wp_checkout_products = array();
581
  $gtm4wp_checkout_products_remarketing = array();
582
  $gtm4wp_totalvalue = 0;
@@ -605,19 +651,30 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
605
  }
606
 
607
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
 
 
 
 
 
 
 
 
 
608
  $dataLayer['ecommerce'] = array(
609
- 'currencyCode' => get_woocommerce_currency(),
610
  'checkout' => array(
611
  'actionField' => array(
612
  'step' => 1 + (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ],
613
  ),
614
  'products' => $gtm4wp_checkout_products,
615
- ),
616
  );
617
 
618
- gtm4wp_woocommerce_addjs('
619
- window.gtm4wp_checkout_products = ' . json_encode( $gtm4wp_checkout_products ) . ';
620
- window.gtm4wp_checkout_step_offset = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ';'
 
 
621
  );
622
  }
623
  }
@@ -636,8 +693,11 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
636
  'quantity' => $cart_item['quantity']
637
  ), 'readdedtocart' );
638
 
 
 
 
639
  $dataLayer['ecommerce'] = array(
640
- 'currencyCode' => get_woocommerce_currency(),
641
  'add' => array(
642
  'products' => array(
643
  $eec_product_array
@@ -646,7 +706,7 @@ function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
646
  );
647
  }
648
 
649
- gtm4wp_woocommerce_addjs( "document.cookie = 'gtm4wp_product_readded_to_cart=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';" );
650
  unset( $_COOKIE['gtm4wp_product_readded_to_cart'] );
651
  }
652
 
@@ -670,7 +730,7 @@ function gtm4wp_woocommerce_single_add_to_cart_tracking() {
670
 
671
  $GLOBALS['gtm4wp_cart_item_proddata'] = '';
672
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item = '', $cart_id = '' ) {
673
- global $gtm4wp_options, $gtm4wp_is_woocommerce3;
674
 
675
  $eec_product_array = gtm4wp_process_product( $product, array(
676
  'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 )
@@ -954,13 +1014,15 @@ function gtm4wp_wc_quick_view_before_single_product() {
954
  }
955
 
956
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
 
 
957
  $dataLayer['ecommerce'] = array(
958
- 'currencyCode' => get_woocommerce_currency(),
959
  'detail' => array(
960
  'products' => array(
961
  $eec_product_array
962
- ),
963
- ),
964
  );
965
  }
966
  }
6
  $gtm4wp_product_counter = 0;
7
  $gtm4wp_last_widget_title = 'Sidebar Products';
8
  if ( function_exists( 'WC' ) ) {
 
9
  $GLOBALS['gtm4wp_is_woocommerce3_7'] = version_compare( WC()->version, '3.7', '>=' );
10
  } else {
 
11
  $GLOBALS['gtm4wp_is_woocommerce3_7'] = false;
12
  }
13
  $GLOBALS['gtm4wp_grouped_product_ix'] = 1;
14
 
 
 
 
 
 
 
 
 
 
 
15
  // from https://snippets.webaware.com.au/ramblings/php-really-doesnt-unicode/
16
  function gtm4wp_untexturize( $fancy ) {
17
  $fixes = false;
102
  }
103
 
104
  function gtm4wp_process_product( $product, $additional_product_attributes, $attributes_used_for ) {
105
+ global $gtm4wp_options;
106
 
107
  if ( ! $product ) {
108
  return false;
118
  $product_sku = $product->get_sku();
119
 
120
  if ( 'variation' == $product_type ) {
121
+ $parent_product_id = $product->get_parent_id();
122
  $product_cat = gtm4wp_get_product_category( $parent_product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
123
  } else {
124
  $product_cat = gtm4wp_get_product_category( $product_id, $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCUSEFULLCATEGORYPATH ] );
156
  return apply_filters( GTM4WP_WPFILTER_EEC_PRODUCT_ARRAY, $_temp_productdata, $attributes_used_for );
157
  }
158
 
159
+ function gtm4wp_map_eec_to_ga4( $productdata ) {
160
+ if ( !is_array($productdata) ) {
161
+ return;
162
+ }
163
+
164
+ $category_path = array_key_exists( "category", $productdata ) ? $productdata[ "category" ] : "";
165
+ $category_parts = explode('/', $category_path);
166
+
167
+ // default, required parameters
168
+ $ga4_product = array(
169
+ 'item_id' => array_key_exists( "id", $productdata ) ? $productdata[ "id" ] : "",
170
+ 'item_name' => array_key_exists( "name", $productdata ) ? $productdata[ "name" ] : "",
171
+ 'item_brand' => array_key_exists( "brand", $productdata ) ? $productdata[ "brand" ] : "",
172
+ 'price' => array_key_exists( "price", $productdata ) ? $productdata[ "price" ] : ""
173
+ );
174
+
175
+ // category, also handle category path
176
+ if ( 1 == count($category_parts) ) {
177
+ $ga4_product[ "item_category" ] = $category_parts[0];
178
+ } else if ( count($category_parts) > 1 ) {
179
+ $ga4_product[ "item_category" ] = $category_parts[0];
180
+ for( $i=1; $i < min( 5, count( $category_parts ) ); $i++ ) {
181
+ $ga4_product[ "item_category_" + ($i+1) ] = $category_parts[$i];
182
+ }
183
+ }
184
+
185
+ // optional parameters which should not be included in the array if not set
186
+ if ( array_key_exists( "variant", $productdata ) ) {
187
+ $ga4_product[ "item_variant" ] = $productdata[ "variant" ];
188
+ }
189
+ if ( array_key_exists( "listname", $productdata ) ) {
190
+ $ga4_product[ "item_list_name" ] = $productdata[ "listname" ];
191
+ }
192
+ if ( array_key_exists( "listposition", $productdata ) ) {
193
+ $ga4_product[ "index" ] = $productdata[ "listposition" ];
194
+ }
195
+ if ( array_key_exists( "quantity", $productdata ) ) {
196
+ $ga4_product[ "quantity" ] = $productdata[ "quantity" ];
197
+ }
198
+ if ( array_key_exists( "coupon", $productdata ) ) {
199
+ $ga4_product[ "coupon" ] = $productdata[ "coupon" ];
200
+ }
201
+
202
+ return $ga4_product;
203
+ }
204
+
205
  function gtm4wp_process_order_items( $order ) {
206
+ global $gtm4wp_options;
207
 
208
  $return_data = array(
209
  'products' => [],
223
  continue;
224
  }
225
 
226
+ $product = $item->get_product();
227
  $inc_tax = ( 'incl' === get_option( 'woocommerce_tax_display_shop' ) );
228
  $product_price = (float) $order->get_item_total( $item, $inc_tax );
229
  $eec_product_array = gtm4wp_process_product( $product, array(
244
 
245
  function gtm4wp_woocommerce_addglobalvars( $return = '' ) {
246
  global $gtm4wp_options;
247
+
248
  if ( function_exists( 'WC' ) && WC()->cart ) {
249
  $gtm4wp_needs_shipping_address = (bool) WC()->cart->needs_shipping_address();
250
  } else {
265
  }
266
 
267
  function gtm4wp_woocommerce_datalayer_filter_items( $dataLayer ) {
268
+ global $gtm4wp_options, $wp_query, $gtm4wp_datalayer_name, $gtm4wp_product_counter, $gtm4wp_is_woocommerce3_7;
269
 
270
  $woo = WC();
271
 
272
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCCUSTOMERDATA ] ) {
273
  if ( $woo->customer instanceof WC_Customer ) {
274
  // we need to use this instead of $woo->customer as this will load proper total order number and value from the database instead of the session
275
  $woo_customer = new WC_Customer( $woo->customer->get_id() );
319
  if (
320
  !apply_filters( GTM4WP_WPFILTER_EEC_CART_ITEM, true, $cart_item_data )
321
  || !apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item_data, $cart_item_id )
322
+ ) {
323
  continue;
324
  }
325
 
345
  $dataLayer['ecomm_totalvalue'] = 0;
346
  }
347
  } elseif ( is_product() ) {
348
+ if (
349
+ $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ]
350
+ || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] )
351
+ ) {
352
  $postid = get_the_ID();
353
  $product = wc_get_product( $postid );
354
 
386
  }
387
 
388
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
389
+ $currencyCode = get_woocommerce_currency();
390
+
391
  $dataLayer['ecommerce'] = array(
392
+ 'currencyCode' => $currencyCode,
393
  'detail' => array(
394
  'products' => array(
395
  $eec_product_array
396
+ )
397
+ )
398
  );
399
  }
400
  }
401
  }
402
  }
403
  } elseif ( is_cart() ) {
404
+ if (
405
+ $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ]
406
+ || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ]
407
+ || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ]
408
+ ) {
409
  $gtm4wp_cart_products = array();
410
  $gtm4wp_cart_products_remarketing = array();
411
 
412
+ $gtm4wp_currency = get_woocommerce_currency();
413
+
414
  foreach ( $woo->cart->get_cart() as $cart_item_id => $cart_item_data ) {
415
  $product = apply_filters( 'woocommerce_cart_item_product', $cart_item_data['data'], $cart_item_data, $cart_item_id );
416
 
422
  'quantity' => $cart_item_data['quantity']
423
  ), 'cart' );
424
 
425
+ $gtm4wp_cart_products[] = $eec_product_array;
 
 
 
426
  $gtm4wp_cart_products_remarketing[] = gtm4wp_prefix_productid( $eec_product_array[ 'id' ] );
427
  }
428
 
437
  $dataLayer['ecomm_totalvalue'] = (float) $cart_total;
438
  }
439
 
440
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
441
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] ) {
442
+ $dataLayer['ecommerce'] = array(
443
+ 'currencyCode' => $gtm4wp_currency,
444
+ 'checkout' => array(
445
+ 'actionField' => array(
446
+ 'step' => 1,
447
+ ),
448
+ 'products' => $gtm4wp_cart_products,
449
+ )
450
+ );
451
+ } else {
452
+ // add only ga4 products to populate view_cart event
453
+ $dataLayer['ecommerce'] = array(
454
+ 'cart' => $gtm4wp_cart_products
455
+ );
456
+ }
457
  }
458
  }
459
  } elseif ( is_order_received_page() ) {
470
  $order = wc_get_order( $order_id );
471
 
472
  if ( $order instanceof WC_Order ) {
473
+ $this_order_key = $order->get_order_key();
 
 
 
 
474
 
475
  if ( $this_order_key != $order_key ) {
476
  unset( $order );
480
  }
481
  }
482
 
483
+ if ( isset($order) && $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCORDERDATA ] ) {
484
  $order_items = gtm4wp_process_order_items( $order );
485
 
486
  $dataLayer['orderData'] = array(
561
  $order_revenue = (float) $order->get_total();
562
  }
563
 
564
+ $order_shipping_cost = (float) $order->get_shipping_total();
 
 
 
 
565
 
566
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEXCLUDESHIPPING ] ) {
567
  $order_revenue -= $order_shipping_cost;
568
  }
569
 
570
+ $order_currency = $order->get_currency();
571
+
572
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] ) {
573
  $dataLayer['event'] = 'gtm4wp.orderCompleted';
574
  $dataLayer['transactionId'] = $order->get_order_number();
576
  $dataLayer['transactionTotal'] = $order_revenue;
577
  $dataLayer['transactionShipping'] = $order_shipping_cost;
578
  $dataLayer['transactionTax'] = (float) $order->get_total_tax();
579
+ $dataLayer['transactionCurrency'] = $order_currency;
580
  }
581
 
582
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
583
  $dataLayer['event'] = 'gtm4wp.orderCompletedEEC';
584
  $dataLayer['ecommerce'] = array(
585
+ 'currencyCode' => $order_currency,
586
  'purchase' => array(
587
  'actionField' => array(
588
  'id' => $order->get_order_number(),
589
  'affiliation' => '',
590
  'revenue' => $order_revenue,
591
  'tax' => (float) $order->get_total_tax(),
592
+ 'shipping' => (float)( $order->get_shipping_total() ),
593
  'coupon' => implode( ', ', ( $gtm4wp_is_woocommerce3_7 ? $order->get_coupon_codes() : $order->get_used_coupons() ) ),
594
+ )
595
+ )
596
  );
597
  }
598
 
619
  }
620
  }
621
  } elseif ( is_checkout() ) {
622
+ if (
623
+ ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] )
624
+ || ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCREMARKETING ] )
625
+ ) {
626
  $gtm4wp_checkout_products = array();
627
  $gtm4wp_checkout_products_remarketing = array();
628
  $gtm4wp_totalvalue = 0;
651
  }
652
 
653
  if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
654
+ $currencyCode = get_woocommerce_currency();
655
+
656
+ $ga4_products = array();
657
+ $sum_value = 0;
658
+ foreach( $gtm4wp_checkout_products as $oneproduct ) {
659
+ $ga4_products[] = gtm4wp_map_eec_to_ga4( $oneproduct );
660
+ $sum_value += $oneproduct["price"] * $oneproduct["quantity"];
661
+ }
662
+
663
  $dataLayer['ecommerce'] = array(
664
+ 'currencyCode' => $currencyCode,
665
  'checkout' => array(
666
  'actionField' => array(
667
  'step' => 1 + (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ],
668
  ),
669
  'products' => $gtm4wp_checkout_products,
670
+ )
671
  );
672
 
673
+ wc_enqueue_js('
674
+ window.gtm4wp_checkout_products = ' . json_encode( $gtm4wp_checkout_products ) . ';
675
+ window.gtm4wp_checkout_products_ga4 = ' . json_encode( $ga4_products ) . ';
676
+ window.gtm4wp_checkout_value = ' . (float) $sum_value . ';
677
+ window.gtm4wp_checkout_step_offset = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCEECCARTASFIRSTSTEP ] . ';'
678
  );
679
  }
680
  }
693
  'quantity' => $cart_item['quantity']
694
  ), 'readdedtocart' );
695
 
696
+ $currencyCode = get_woocommerce_currency();
697
+
698
+ $dataLayer['event'] = 'gtm4wp.addProductToCartEEC';
699
  $dataLayer['ecommerce'] = array(
700
+ 'currencyCode' => $currencyCode,
701
  'add' => array(
702
  'products' => array(
703
  $eec_product_array
706
  );
707
  }
708
 
709
+ wc_enqueue_js( "document.cookie = 'gtm4wp_product_readded_to_cart=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';" );
710
  unset( $_COOKIE['gtm4wp_product_readded_to_cart'] );
711
  }
712
 
730
 
731
  $GLOBALS['gtm4wp_cart_item_proddata'] = '';
732
  function gtm4wp_woocommerce_cart_item_product_filter( $product, $cart_item = '', $cart_id = '' ) {
733
+ global $gtm4wp_options;
734
 
735
  $eec_product_array = gtm4wp_process_product( $product, array(
736
  'productlink' => apply_filters( 'the_permalink', get_permalink(), 0 )
1014
  }
1015
 
1016
  if ( true === $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) {
1017
+ $currencyCode = get_woocommerce_currency();
1018
+
1019
  $dataLayer['ecommerce'] = array(
1020
+ 'currencyCode' => $currencyCode,
1021
  'detail' => array(
1022
  'products' => array(
1023
  $eec_product_array
1024
+ )
1025
+ )
1026
  );
1027
  }
1028
  }
integration/youtube.php CHANGED
@@ -1,18 +1,18 @@
1
- <?php
2
- function gtm4wp_youtube( $return, $url, $data ) {
3
- $site_url = site_url();
4
- $site_url_parts = parse_url( $site_url );
5
-
6
- if ( false !== strpos( $return, 'youtube.com' ) ) {
7
- return str_replace( 'feature=oembed', 'feature=oembed&enablejsapi=1&origin=' . $site_url_parts['scheme'] . '://' . $site_url_parts['host'], $return );
8
- } else {
9
- return $return;
10
- }
11
- }
12
-
13
- add_filter( 'oembed_result', 'gtm4wp_youtube', 10, 3 );
14
-
15
- if ( ! is_admin() ) {
16
- $in_footer = apply_filters( 'gtm4wp_youtube', false );
17
- wp_enqueue_script( 'gtm4wp-youtube', $gtp4wp_plugin_url . 'js/gtm4wp-youtube.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
18
- }
1
+ <?php
2
+ function gtm4wp_youtube( $return, $url, $data ) {
3
+ $site_url = site_url();
4
+ $site_url_parts = parse_url( $site_url );
5
+
6
+ if ( false !== strpos( $return, 'youtube.com' ) ) {
7
+ return str_replace( 'feature=oembed', 'feature=oembed&enablejsapi=1&origin=' . $site_url_parts['scheme'] . '://' . $site_url_parts['host'], $return );
8
+ } else {
9
+ return $return;
10
+ }
11
+ }
12
+
13
+ add_filter( 'oembed_result', 'gtm4wp_youtube', 10, 3 );
14
+
15
+ if ( ! is_admin() ) {
16
+ $in_footer = apply_filters( 'gtm4wp_youtube', false );
17
+ wp_enqueue_script( 'gtm4wp-youtube', $gtp4wp_plugin_url . 'js/gtm4wp-youtube.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
18
+ }
js/admin-subtabs.js CHANGED
@@ -1,81 +1,85 @@
1
-
2
- var adminsubtabs = {
3
- 0: {},
4
- 1: {
5
- "posts": {
6
- tabtext: gtm4wp.posttabtitle,
7
- numitems: 11
8
- },
9
- "search": {
10
- tabtext: gtm4wp.searchtabtitle,
11
- numitems: 1
12
- },
13
- "visitor": {
14
- tabtext: gtm4wp.visitortabtitle,
15
- numitems: 7
16
- },
17
- "adwords": {
18
- tabtext: gtm4wp.adwordstabtitle,
19
- numitems: 1
20
- },
21
- "whichbrowser": {
22
- tabtext: gtm4wp.browsertabtitle,
23
- numitems: 3
24
- },
25
- "weather": {
26
- tabtext: gtm4wp.weathertabtitle,
27
- numitems: 6
28
- },
29
- "site": {
30
- tabtext: gtm4wp.sitetabtitle,
31
- numitems: 2
32
- }/*,
33
- "misc": {
34
- tabtext: gtm4wp.misctabtitle,
35
- numitems: 1
36
- }*/
37
- },
38
- 2: {
39
- "generalevents": {
40
- tabtext: gtm4wp.generaleventstabtitle,
41
- numitems: 3
42
- },
43
- "mediaevents": {
44
- tabtext: gtm4wp.mediaeventstabtitle,
45
- numitems: 3
46
- },
47
- "depecratedevents": {
48
- tabtext: gtm4wp.depecratedeventstabtitle,
49
- numitems: 4
50
- }
51
- },
52
- 3: {},
53
- 4: {
54
- "blocktags": {
55
- tabtext: gtm4wp.blocktagstabtitle,
56
- numitems: 20
57
- },
58
- "blockmacros": {
59
- tabtext: gtm4wp.blockmacrostabtitle,
60
- numitems: 20
61
- }
62
- },
63
- 5: {
64
- "int-wpcf7": {
65
- tabtext: gtm4wp.wpcf7tabtitle,
66
- numitems: 1
67
- },
68
- "int-wc": {
69
- tabtext: gtm4wp.wctabtitle,
70
- numitems: 15
71
- },
72
- "int-google-optimize": {
73
- tabtext: gtm4wp.gotabtitle,
74
- numitems: 2
75
- },
76
- "int-amp": {
77
- tabtext: gtm4wp.amptabtitle,
78
- numitems: 1
79
- }
80
- }
81
- };
 
 
 
 
1
+
2
+ var adminsubtabs = {
3
+ 0: {},
4
+ 1: {
5
+ "posts": {
6
+ tabtext: gtm4wp.posttabtitle,
7
+ numitems: 11
8
+ },
9
+ "search": {
10
+ tabtext: gtm4wp.searchtabtitle,
11
+ numitems: 1
12
+ },
13
+ "visitor": {
14
+ tabtext: gtm4wp.visitortabtitle,
15
+ numitems: 7
16
+ },
17
+ "adwords": {
18
+ tabtext: gtm4wp.adwordstabtitle,
19
+ numitems: 1
20
+ },
21
+ "whichbrowser": {
22
+ tabtext: gtm4wp.browsertabtitle,
23
+ numitems: 3
24
+ },
25
+ "weather": {
26
+ tabtext: gtm4wp.weathertabtitle,
27
+ numitems: 6
28
+ },
29
+ "site": {
30
+ tabtext: gtm4wp.sitetabtitle,
31
+ numitems: 2
32
+ }/*,
33
+ "misc": {
34
+ tabtext: gtm4wp.misctabtitle,
35
+ numitems: 1
36
+ }*/
37
+ },
38
+ 2: {
39
+ "generalevents": {
40
+ tabtext: gtm4wp.generaleventstabtitle,
41
+ numitems: 3
42
+ },
43
+ "mediaevents": {
44
+ tabtext: gtm4wp.mediaeventstabtitle,
45
+ numitems: 3
46
+ },
47
+ "depecratedevents": {
48
+ tabtext: gtm4wp.depecratedeventstabtitle,
49
+ numitems: 0
50
+ }
51
+ },
52
+ 3: {},
53
+ 4: {
54
+ "blocktags": {
55
+ tabtext: gtm4wp.blocktagstabtitle,
56
+ numitems: 74
57
+ },
58
+ "blocktriggers": {
59
+ tabtext: gtm4wp.blocktriggerstabtitle,
60
+ numitems: 9
61
+ },
62
+ "blockmacros": {
63
+ tabtext: gtm4wp.blockmacrostabtitle,
64
+ numitems: 15
65
+ }
66
+ },
67
+ 5: {
68
+ "int-wpcf7": {
69
+ tabtext: gtm4wp.wpcf7tabtitle,
70
+ numitems: 1
71
+ },
72
+ "int-wc": {
73
+ tabtext: gtm4wp.wctabtitle,
74
+ numitems: 15
75
+ },
76
+ "int-google-optimize": {
77
+ tabtext: gtm4wp.gotabtitle,
78
+ numitems: 2
79
+ },
80
+ "int-amp": {
81
+ tabtext: gtm4wp.amptabtitle,
82
+ numitems: 1
83
+ }
84
+ }
85
+ };
js/admin-tabcreator.js CHANGED
@@ -1,80 +1,80 @@
1
- jQuery( function() {
2
- var admintabs = [];
3
- var adminsubtabsdata = window.adminsubtabs || {};
4
- var adminsubtabs = [];
5
-
6
- jQuery( '#wpbody form h2' ).each(function( i ) {
7
- admintabs.push( '<a class="nav-tab" href="#">' + jQuery(this).text() + '</a>' );
8
-
9
- jQuery(this)
10
- .remove();
11
-
12
- if ( adminsubtabsdata[ i ] ) {
13
- var _subtabs = [];
14
- var _startrow = 0;
15
-
16
- for (var j in adminsubtabsdata[ i ] ) {
17
- _subtabs.push( '<a href="#" data-formtableid="' + i + '" data-startrow="' + _startrow + '" data-endrow="' + (_startrow + adminsubtabsdata[ i ][ j ].numitems) + '">' + adminsubtabsdata[ i ][ j ].tabtext + '</a>' );
18
- _startrow += adminsubtabsdata[ i ][ j ].numitems;
19
- }
20
-
21
- if ( _subtabs.length > 0 ) {
22
- adminsubtabs.push( '<ul class="adminsubtabs" id="adminsubtabs' + i + '"><li>' + _subtabs.join('</li><li>') + '</li></ul>' );
23
- }
24
- }
25
- });
26
-
27
- jQuery("#wpbody form[action='options.php']")
28
- .prepend( adminsubtabs.join('') )
29
- .prepend( '<h2 class="nav-tab-wrapper">' + admintabs.join('') + '</h2>' );
30
-
31
- jQuery( '.adminsubtabs li a' )
32
- .on( 'click', function() {
33
- var jqthis = jQuery(this);
34
-
35
- jqthis
36
- .parent()
37
- .parent()
38
- .find( 'a' )
39
- .removeClass( 'subtab-active' );
40
-
41
- jqthis
42
- .addClass( 'subtab-active' );
43
-
44
- jQuery( '.form-table:eq(' + jqthis.data( 'formtableid' ) + ') tr' )
45
- .hide()
46
- .slice( jqthis.data('startrow'), jqthis.data('endrow') )
47
- .show();
48
-
49
- return false;
50
- });
51
-
52
- jQuery( '.nav-tab-wrapper a' )
53
- .on( "click", function() {
54
- jQuery( '.nav-tab-wrapper a.nav-tab-active' )
55
- .removeClass( "nav-tab-active" );
56
-
57
- jQuery( '#wpbody form .tabinfo,#wpbody form .form-table,.adminsubtabs' )
58
- .hide();
59
-
60
- var tabindex = jQuery(this)
61
- .addClass( 'nav-tab-active' )
62
- .index();
63
-
64
- jQuery( '#wpbody form .tabinfo:eq(' + tabindex + '),#wpbody form .form-table:eq(' + tabindex + ')' )
65
- .show();
66
-
67
- jQuery( '#wpbody #adminsubtabs' + tabindex + ':not(.subtab-activated)' )
68
- .find( 'a:first' )
69
- .trigger( 'click' );
70
-
71
- jQuery( '#wpbody #adminsubtabs' + tabindex )
72
- .addClass( 'subtab-activated' )
73
- .show();
74
-
75
- return false;
76
- });
77
-
78
- jQuery( '.nav-tab-wrapper a:first' )
79
- .trigger( 'click' );
80
  });
1
+ jQuery( function() {
2
+ var admintabs = [];
3
+ var adminsubtabsdata = window.adminsubtabs || {};
4
+ var adminsubtabs = [];
5
+
6
+ jQuery( '#wpbody form h2' ).each(function( i ) {
7
+ admintabs.push( '<a class="nav-tab" href="#">' + jQuery(this).text() + '</a>' );
8
+
9
+ jQuery(this)
10
+ .remove();
11
+
12
+ if ( adminsubtabsdata[ i ] ) {
13
+ var _subtabs = [];
14
+ var _startrow = 0;
15
+
16
+ for (var j in adminsubtabsdata[ i ] ) {
17
+ _subtabs.push( '<a href="#" data-formtableid="' + i + '" data-startrow="' + _startrow + '" data-endrow="' + (_startrow + adminsubtabsdata[ i ][ j ].numitems) + '">' + adminsubtabsdata[ i ][ j ].tabtext + '</a>' );
18
+ _startrow += adminsubtabsdata[ i ][ j ].numitems;
19
+ }
20
+
21
+ if ( _subtabs.length > 0 ) {
22
+ adminsubtabs.push( '<ul class="adminsubtabs" id="adminsubtabs' + i + '"><li>' + _subtabs.join('</li><li>') + '</li></ul>' );
23
+ }
24
+ }
25
+ });
26
+
27
+ jQuery("#wpbody form[action='options.php']")
28
+ .prepend( adminsubtabs.join('') )
29
+ .prepend( '<h2 class="nav-tab-wrapper">' + admintabs.join('') + '</h2>' );
30
+
31
+ jQuery( '.adminsubtabs li a' )
32
+ .on( 'click', function() {
33
+ var jqthis = jQuery(this);
34
+
35
+ jqthis
36
+ .parent()
37
+ .parent()
38
+ .find( 'a' )
39
+ .removeClass( 'subtab-active' );
40
+
41
+ jqthis
42
+ .addClass( 'subtab-active' );
43
+
44
+ jQuery( '.form-table:eq(' + jqthis.data( 'formtableid' ) + ') tr' )
45
+ .hide()
46
+ .slice( jqthis.data('startrow'), jqthis.data('endrow') )
47
+ .show();
48
+
49
+ return false;
50
+ });
51
+
52
+ jQuery( '.nav-tab-wrapper a' )
53
+ .on( "click", function() {
54
+ jQuery( '.nav-tab-wrapper a.nav-tab-active' )
55
+ .removeClass( "nav-tab-active" );
56
+
57
+ jQuery( '#wpbody form .tabinfo,#wpbody form .form-table,.adminsubtabs' )
58
+ .hide();
59
+
60
+ var tabindex = jQuery(this)
61
+ .addClass( 'nav-tab-active' )
62
+ .index();
63
+
64
+ jQuery( '#wpbody form .tabinfo:eq(' + tabindex + '),#wpbody form .form-table:eq(' + tabindex + ')' )
65
+ .show();
66
+
67
+ jQuery( '#wpbody #adminsubtabs' + tabindex + ':not(.subtab-activated)' )
68
+ .find( 'a:first' )
69
+ .trigger( 'click' );
70
+
71
+ jQuery( '#wpbody #adminsubtabs' + tabindex )
72
+ .addClass( 'subtab-activated' )
73
+ .show();
74
+
75
+ return false;
76
+ });
77
+
78
+ jQuery( '.nav-tab-wrapper a:first' )
79
+ .trigger( 'click' );
80
  });
js/analytics-talk-content-tracking.js CHANGED
@@ -1,138 +1,138 @@
1
- /*
2
- * Source: http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/
3
- * Original authors:
4
- * - Nick Mihailovski
5
- * - Thomas Baekdal
6
- * - Avinash Kaushik
7
- * - Joost de Valk
8
- * - Eivind Savio
9
- * - Justin Cutroni
10
- *
11
- * Google Tag Manager dataLayer events added by:
12
- * Thomas Geiger
13
- * gtm4wp.com
14
- */
15
-
16
- if ( "undefined" == typeof console ) {
17
- window.console = {
18
- log: function () {}
19
- };
20
- }
21
-
22
- jQuery( function( $ ) {
23
- // Debug flag
24
- var debugMode = gtm4wp_scrollerscript_debugmode;
25
-
26
- // Default time delay before checking location
27
- var callBackTime = gtm4wp_scrollerscript_callbacktime;
28
-
29
- // # px before tracking a reader
30
- var readerLocation = gtm4wp_scrollerscript_readerlocation;
31
-
32
- // Set some flags for tracking & execution
33
- var timer = 0;
34
- var scroller = false;
35
- var endContent = false;
36
- var didComplete = false;
37
-
38
- // Set some time variables to calculate reading time
39
- var startTime = new Date();
40
- var beginning = startTime.getTime();
41
- var totalTime = 0;
42
-
43
- // Track the aticle load
44
- if ( !debugMode ) {
45
- window[ gtm4wp_datalayer_name ].push({
46
- 'event': 'gtm4wp.reading.articleLoaded'
47
- });
48
- } else {
49
- console.log( 'Article loaded' );
50
- }
51
-
52
- // Check the location and track user
53
- function trackLocation() {
54
- bottom = $( window ).height() + $( window ).scrollTop();
55
- height = $( document ).height();
56
-
57
- // If user starts to scroll send an event
58
- if ( bottom > readerLocation && !scroller ) {
59
- currentTime = new Date();
60
- scrollStart = currentTime.getTime();
61
- timeToScroll = Math.round( ( scrollStart - beginning ) / 1000 );
62
-
63
- if ( !debugMode ) {
64
- window[ gtm4wp_datalayer_name ].push({
65
- 'event': 'gtm4wp.reading.startReading',
66
- 'timeToScroll': timeToScroll
67
- });
68
- } else {
69
- console.log( 'Started reading ' + timeToScroll );
70
- }
71
- scroller = true;
72
- }
73
-
74
- // If user has hit the bottom of the content send an event
75
- if ( bottom >= $( '#' + gtm4wp_scrollerscript_contentelementid ).scrollTop() + $( '#' + gtm4wp_scrollerscript_contentelementid ).innerHeight() && !endContent ) {
76
- currentTime = new Date();
77
- contentScrollEnd = currentTime.getTime();
78
- timeToContentEnd = Math.round( ( contentScrollEnd - scrollStart ) / 1000 );
79
-
80
- if ( !debugMode ) {
81
- window[ gtm4wp_datalayer_name ].push({
82
- 'event': 'gtm4wp.reading.contentBottom',
83
- 'timeToScroll': timeToContentEnd
84
- });
85
- } else {
86
- console.log( 'End content section ' + timeToContentEnd );
87
- }
88
-
89
- endContent = true;
90
- }
91
-
92
- // If user has hit the bottom of page send an event
93
- if ( bottom >= height && !didComplete ) {
94
- currentTime = new Date();
95
- end = currentTime.getTime();
96
- totalTime = Math.round( ( end - scrollStart ) / 1000 );
97
-
98
- if ( !debugMode ) {
99
- if ( totalTime < gtm4wp_scrollerscript_scannertime ) {
100
- window[ gtm4wp_datalayer_name ].push({
101
- 'event': 'gtm4wp.reading.readerType',
102
- 'readerType': 'scanner'
103
- });
104
- } else {
105
- window[ gtm4wp_datalayer_name ].push({
106
- 'event': 'gtm4wp.reading.readerType',
107
- 'readerType': 'reader'
108
- });
109
- }
110
-
111
- window[ gtm4wp_datalayer_name ].push({
112
- 'event': 'gtm4wp.reading.pagebottom',
113
- 'timeToScroll': totalTime
114
- });
115
- } else {
116
- if ( totalTime < gtm4wp_scrollerscript_scannertime ) {
117
- console.log( 'The visitor seems to be a "scanner"' );
118
- } else {
119
- console.log( 'The visitor seems to be a "reader"' );
120
- }
121
-
122
- console.log( 'Bottom of page ' + totalTime );
123
- }
124
-
125
- didComplete = true;
126
- }
127
- }
128
-
129
- // Track the scrolling and track location
130
- $( window ).scroll(function() {
131
- if ( timer ) {
132
- clearTimeout( timer );
133
- }
134
-
135
- // Use a buffer so we don't call trackLocation too often.
136
- timer = setTimeout( trackLocation, callBackTime );
137
- });
138
  });
1
+ /*
2
+ * Source: http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analytics-part-1/
3
+ * Original authors:
4
+ * - Nick Mihailovski
5
+ * - Thomas Baekdal
6
+ * - Avinash Kaushik
7
+ * - Joost de Valk
8
+ * - Eivind Savio
9
+ * - Justin Cutroni
10
+ *
11
+ * Google Tag Manager dataLayer events added by:
12
+ * Thomas Geiger
13
+ * gtm4wp.com
14
+ */
15
+
16
+ if ( "undefined" == typeof console ) {
17
+ window.console = {
18
+ log: function () {}
19
+ };
20
+ }
21
+
22
+ jQuery( function( $ ) {
23
+ // Debug flag
24
+ var debugMode = gtm4wp_scrollerscript_debugmode;
25
+
26
+ // Default time delay before checking location
27
+ var callBackTime = gtm4wp_scrollerscript_callbacktime;
28
+
29
+ // # px before tracking a reader
30
+ var readerLocation = gtm4wp_scrollerscript_readerlocation;
31
+
32
+ // Set some flags for tracking & execution
33
+ var timer = 0;
34
+ var scroller = false;
35
+ var endContent = false;
36
+ var didComplete = false;
37
+
38
+ // Set some time variables to calculate reading time
39
+ var startTime = new Date();
40
+ var beginning = startTime.getTime();
41
+ var totalTime = 0;
42
+
43
+ // Track the aticle load
44
+ if ( !debugMode ) {
45
+ window[ gtm4wp_datalayer_name ].push({
46
+ 'event': 'gtm4wp.reading.articleLoaded'
47
+ });
48
+ } else {
49
+ console.log( 'Article loaded' );
50
+ }
51
+
52
+ // Check the location and track user
53
+ function trackLocation() {
54
+ bottom = $( window ).height() + $( window ).scrollTop();
55
+ height = $( document ).height();
56
+
57
+ // If user starts to scroll send an event
58
+ if ( bottom > readerLocation && !scroller ) {
59
+ currentTime = new Date();
60
+ scrollStart = currentTime.getTime();
61
+ timeToScroll = Math.round( ( scrollStart - beginning ) / 1000 );
62
+
63
+ if ( !debugMode ) {
64
+ window[ gtm4wp_datalayer_name ].push({
65
+ 'event': 'gtm4wp.reading.startReading',
66
+ 'timeToScroll': timeToScroll
67
+ });
68
+ } else {
69
+ console.log( 'Started reading ' + timeToScroll );
70
+ }
71
+ scroller = true;
72
+ }
73
+
74
+ // If user has hit the bottom of the content send an event
75
+ if ( bottom >= $( '#' + gtm4wp_scrollerscript_contentelementid ).scrollTop() + $( '#' + gtm4wp_scrollerscript_contentelementid ).innerHeight() && !endContent ) {
76
+ currentTime = new Date();
77
+ contentScrollEnd = currentTime.getTime();
78
+ timeToContentEnd = Math.round( ( contentScrollEnd - scrollStart ) / 1000 );
79
+
80
+ if ( !debugMode ) {
81
+ window[ gtm4wp_datalayer_name ].push({
82
+ 'event': 'gtm4wp.reading.contentBottom',
83
+ 'timeToScroll': timeToContentEnd
84
+ });
85
+ } else {
86
+ console.log( 'End content section ' + timeToContentEnd );
87
+ }
88
+
89
+ endContent = true;
90
+ }
91
+
92
+ // If user has hit the bottom of page send an event
93
+ if ( bottom >= height && !didComplete ) {
94
+ currentTime = new Date();
95
+ end = currentTime.getTime();
96
+ totalTime = Math.round( ( end - scrollStart ) / 1000 );
97
+
98
+ if ( !debugMode ) {
99
+ if ( totalTime < gtm4wp_scrollerscript_scannertime ) {
100
+ window[ gtm4wp_datalayer_name ].push({
101
+ 'event': 'gtm4wp.reading.readerType',
102
+ 'readerType': 'scanner'
103
+ });
104
+ } else {
105
+ window[ gtm4wp_datalayer_name ].push({
106
+ 'event': 'gtm4wp.reading.readerType',
107
+ 'readerType': 'reader'
108
+ });
109
+ }
110
+
111
+ window[ gtm4wp_datalayer_name ].push({
112
+ 'event': 'gtm4wp.reading.pagebottom',
113
+ 'timeToScroll': totalTime
114
+ });
115
+ } else {
116
+ if ( totalTime < gtm4wp_scrollerscript_scannertime ) {
117
+ console.log( 'The visitor seems to be a "scanner"' );
118
+ } else {
119
+ console.log( 'The visitor seems to be a "reader"' );
120
+ }
121
+
122
+ console.log( 'Bottom of page ' + totalTime );
123
+ }
124
+
125
+ didComplete = true;
126
+ }
127
+ }
128
+
129
+ // Track the scrolling and track location
130
+ $( window ).scroll(function() {
131
+ if ( timer ) {
132
+ clearTimeout( timer );
133
+ }
134
+
135
+ // Use a buffer so we don't call trackLocation too often.
136
+ timer = setTimeout( trackLocation, callBackTime );
137
+ });
138
  });
js/froogaloop.js CHANGED
@@ -1,259 +1,259 @@
1
- // Init style shamelessly stolen from jQuery http://jquery.com
2
- var Froogaloop = (function() {
3
- // Define a local copy of Froogaloop
4
- function Froogaloop(iframe) {
5
- // The Froogaloop object is actually just the init constructor
6
- return new Froogaloop.fn.init(iframe);
7
- }
8
-
9
- var eventCallbacks = {},
10
- hasWindowEvent = false,
11
- isReady = false,
12
- slice = Array.prototype.slice,
13
- playerOrigin = '*';
14
-
15
- Froogaloop.fn = Froogaloop.prototype = {
16
- element: null,
17
-
18
- init: function(iframe) {
19
- if (typeof iframe === "string") {
20
- iframe = document.getElementById(iframe);
21
- }
22
-
23
- this.element = iframe;
24
-
25
- return this;
26
- },
27
-
28
- /*
29
- * Calls a function to act upon the player.
30
- *
31
- * @param {string} method The name of the Javascript API method to call. Eg: 'play'.
32
- * @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method
33
- * or callback function when the method returns a value.
34
- */
35
- api: function(method, valueOrCallback) {
36
- if (!this.element || !method) {
37
- return false;
38
- }
39
-
40
- var self = this,
41
- element = self.element,
42
- target_id = element.id !== '' ? element.id : null,
43
- params = !isFunction(valueOrCallback) ? valueOrCallback : null,
44
- callback = isFunction(valueOrCallback) ? valueOrCallback : null;
45
-
46
- // Store the callback for get functions
47
- if (callback) {
48
- storeCallback(method, callback, target_id);
49
- }
50
-
51
- postMessage(method, params, element);
52
- return self;
53
- },
54
-
55
- /*
56
- * Registers an event listener and a callback function that gets called when the event fires.
57
- *
58
- * @param eventName (String): Name of the event to listen for.
59
- * @param callback (Function): Function that should be called when the event fires.
60
- */
61
- addEvent: function(eventName, callback) {
62
- if (!this.element) {
63
- return false;
64
- }
65
-
66
- var self = this,
67
- element = self.element,
68
- target_id = element.id !== '' ? element.id : null;
69
-
70
-
71
- storeCallback(eventName, callback, target_id);
72
-
73
- // The ready event is not registered via postMessage. It fires regardless.
74
- if (eventName != 'ready') {
75
- postMessage('addEventListener', eventName, element);
76
- } else if (eventName == 'ready' && isReady) {
77
- callback.call(null, target_id);
78
- }
79
-
80
- return self;
81
- },
82
-
83
- /*
84
- * Unregisters an event listener that gets called when the event fires.
85
- *
86
- * @param eventName (String): Name of the event to stop listening for.
87
- */
88
- removeEvent: function(eventName) {
89
- if (!this.element) {
90
- return false;
91
- }
92
-
93
- var self = this,
94
- element = self.element,
95
- target_id = element.id !== '' ? element.id : null,
96
- removed = removeCallback(eventName, target_id);
97
-
98
- // The ready event is not registered
99
- if (eventName != 'ready' && removed) {
100
- postMessage('removeEventListener', eventName, element);
101
- }
102
- }
103
- };
104
-
105
- /**
106
- * Handles posting a message to the parent window.
107
- *
108
- * @param method (String): name of the method to call inside the player. For api calls
109
- * this is the name of the api method (api_play or api_pause) while for events this method
110
- * is api_addEventListener.
111
- * @param params (Object or Array): List of parameters to submit to the method. Can be either
112
- * a single param or an array list of parameters.
113
- * @param target (HTMLElement): Target iframe to post the message to.
114
- */
115
-
116
- function postMessage(method, params, target) {
117
- if (!target.contentWindow.postMessage) {
118
- return false;
119
- }
120
-
121
- var data = JSON.stringify({
122
- method: method,
123
- value: params
124
- });
125
-
126
- target.contentWindow.postMessage(data, playerOrigin);
127
- }
128
-
129
- /**
130
- * Event that fires whenever the window receives a message from its parent
131
- * via window.postMessage.
132
- */
133
-
134
- function onMessageReceived(event) {
135
- var data, method;
136
-
137
- try {
138
- data = JSON.parse(event.data);
139
- method = data.event || data.method;
140
- } catch (e) {
141
- //fail silently... like a ninja!
142
- }
143
-
144
- if (method == 'ready' && !isReady) {
145
- isReady = true;
146
- }
147
-
148
- // Handles messages from the vimeo player only
149
- if (!(/^https?:\/\/player.vimeo.com/).test(event.origin)) {
150
- return false;
151
- }
152
-
153
- if (playerOrigin === '*') {
154
- playerOrigin = event.origin;
155
- }
156
-
157
- var value = data.value,
158
- eventData = data.data,
159
- target_id = target_id === '' ? null : data.player_id,
160
-
161
- callback = getCallback(method, target_id),
162
- params = [];
163
-
164
- if (!callback) {
165
- return false;
166
- }
167
-
168
- if (value !== undefined) {
169
- params.push(value);
170
- }
171
-
172
- if (eventData) {
173
- params.push(eventData);
174
- }
175
-
176
- if (target_id) {
177
- params.push(target_id);
178
- }
179
-
180
- return params.length > 0 ? callback.apply(null, params) : callback.call();
181
- }
182
-
183
-
184
- /**
185
- * Stores submitted callbacks for each iframe being tracked and each
186
- * event for that iframe.
187
- *
188
- * @param eventName (String): Name of the event. Eg. api_onPlay
189
- * @param callback (Function): Function that should get executed when the
190
- * event is fired.
191
- * @param target_id (String) [Optional]: If handling more than one iframe then
192
- * it stores the different callbacks for different iframes based on the iframe's
193
- * id.
194
- */
195
-
196
- function storeCallback(eventName, callback, target_id) {
197
- if (target_id) {
198
- if (!eventCallbacks[target_id]) {
199
- eventCallbacks[target_id] = {};
200
- }
201
- eventCallbacks[target_id][eventName] = callback;
202
- } else {
203
- eventCallbacks[eventName] = callback;
204
- }
205
- }
206
-
207
- /**
208
- * Retrieves stored callbacks.
209
- */
210
-
211
- function getCallback(eventName, target_id) {
212
- if (target_id) {
213
- return eventCallbacks[target_id][eventName];
214
- } else {
215
- return eventCallbacks[eventName];
216
- }
217
- }
218
-
219
- function removeCallback(eventName, target_id) {
220
- if (target_id && eventCallbacks[target_id]) {
221
- if (!eventCallbacks[target_id][eventName]) {
222
- return false;
223
- }
224
- eventCallbacks[target_id][eventName] = null;
225
- } else {
226
- if (!eventCallbacks[eventName]) {
227
- return false;
228
- }
229
- eventCallbacks[eventName] = null;
230
- }
231
-
232
- return true;
233
- }
234
-
235
- function isFunction(obj) {
236
- return !!(obj && obj.constructor && obj.call && obj.apply);
237
- }
238
-
239
- function isArray(obj) {
240
- return toString.call(obj) === '[object Array]';
241
- }
242
-
243
- // Give the init function the Froogaloop prototype for later instantiation
244
- Froogaloop.fn.init.prototype = Froogaloop.fn;
245
-
246
- // Listens for the message event.
247
- // W3C
248
- if (window.addEventListener) {
249
- window.addEventListener('message', onMessageReceived, false);
250
- }
251
- // IE
252
- else {
253
- window.attachEvent('onmessage', onMessageReceived);
254
- }
255
-
256
- // Expose froogaloop to the global object
257
- return (window.Froogaloop = window.$f = Froogaloop);
258
-
259
- })();
1
+ // Init style shamelessly stolen from jQuery http://jquery.com
2
+ var Froogaloop = (function() {
3
+ // Define a local copy of Froogaloop
4
+ function Froogaloop(iframe) {
5
+ // The Froogaloop object is actually just the init constructor
6
+ return new Froogaloop.fn.init(iframe);
7
+ }
8
+
9
+ var eventCallbacks = {},
10
+ hasWindowEvent = false,
11
+ isReady = false,
12
+ slice = Array.prototype.slice,
13
+ playerOrigin = '*';
14
+
15
+ Froogaloop.fn = Froogaloop.prototype = {
16
+ element: null,
17
+
18
+ init: function(iframe) {
19
+ if (typeof iframe === "string") {
20
+ iframe = document.getElementById(iframe);
21
+ }
22
+
23
+ this.element = iframe;
24
+
25
+ return this;
26
+ },
27
+
28
+ /*
29
+ * Calls a function to act upon the player.
30
+ *
31
+ * @param {string} method The name of the Javascript API method to call. Eg: 'play'.
32
+ * @param {Array|Function} valueOrCallback params Array of parameters to pass when calling an API method
33
+ * or callback function when the method returns a value.
34
+ */
35
+ api: function(method, valueOrCallback) {
36
+ if (!this.element || !method) {
37
+ return false;
38
+ }
39
+
40
+ var self = this,
41
+ element = self.element,
42
+ target_id = element.id !== '' ? element.id : null,
43
+ params = !isFunction(valueOrCallback) ? valueOrCallback : null,
44
+ callback = isFunction(valueOrCallback) ? valueOrCallback : null;
45
+
46
+ // Store the callback for get functions
47
+ if (callback) {
48
+ storeCallback(method, callback, target_id);
49
+ }
50
+
51
+ postMessage(method, params, element);
52
+ return self;
53
+ },
54
+
55
+ /*
56
+ * Registers an event listener and a callback function that gets called when the event fires.
57
+ *
58
+ * @param eventName (String): Name of the event to listen for.
59
+ * @param callback (Function): Function that should be called when the event fires.
60
+ */
61
+ addEvent: function(eventName, callback) {
62
+ if (!this.element) {
63
+ return false;
64
+ }
65
+
66
+ var self = this,
67
+ element = self.element,
68
+ target_id = element.id !== '' ? element.id : null;
69
+
70
+
71
+ storeCallback(eventName, callback, target_id);
72
+
73
+ // The ready event is not registered via postMessage. It fires regardless.
74
+ if (eventName != 'ready') {
75
+ postMessage('addEventListener', eventName, element);
76
+ } else if (eventName == 'ready' && isReady) {
77
+ callback.call(null, target_id);
78
+ }
79
+
80
+ return self;
81
+ },
82
+
83
+ /*
84
+ * Unregisters an event listener that gets called when the event fires.
85
+ *
86
+ * @param eventName (String): Name of the event to stop listening for.
87
+ */
88
+ removeEvent: function(eventName) {
89
+ if (!this.element) {
90
+ return false;
91
+ }
92
+
93
+ var self = this,
94
+ element = self.element,
95
+ target_id = element.id !== '' ? element.id : null,
96
+ removed = removeCallback(eventName, target_id);
97
+
98
+ // The ready event is not registered
99
+ if (eventName != 'ready' && removed) {
100
+ postMessage('removeEventListener', eventName, element);
101
+ }
102
+ }
103
+ };
104
+
105
+ /**
106
+ * Handles posting a message to the parent window.
107
+ *
108
+ * @param method (String): name of the method to call inside the player. For api calls
109
+ * this is the name of the api method (api_play or api_pause) while for events this method
110
+ * is api_addEventListener.
111
+ * @param params (Object or Array): List of parameters to submit to the method. Can be either
112
+ * a single param or an array list of parameters.
113
+ * @param target (HTMLElement): Target iframe to post the message to.
114
+ */
115
+
116
+ function postMessage(method, params, target) {
117
+ if (!target.contentWindow.postMessage) {
118
+ return false;
119
+ }
120
+
121
+ var data = JSON.stringify({
122
+ method: method,
123
+ value: params
124
+ });
125
+
126
+ target.contentWindow.postMessage(data, playerOrigin);
127
+ }
128
+
129
+ /**
130
+ * Event that fires whenever the window receives a message from its parent
131
+ * via window.postMessage.
132
+ */
133
+
134
+ function onMessageReceived(event) {
135
+ var data, method;
136
+
137
+ try {
138
+ data = JSON.parse(event.data);
139
+ method = data.event || data.method;
140
+ } catch (e) {
141
+ //fail silently... like a ninja!
142
+ }
143
+
144
+ if (method == 'ready' && !isReady) {
145
+ isReady = true;
146
+ }
147
+
148
+ // Handles messages from the vimeo player only
149
+ if (!(/^https?:\/\/player.vimeo.com/).test(event.origin)) {
150
+ return false;
151
+ }
152
+
153
+ if (playerOrigin === '*') {
154
+ playerOrigin = event.origin;
155
+ }
156
+
157
+ var value = data.value,
158
+ eventData = data.data,
159
+ target_id = target_id === '' ? null : data.player_id,
160
+
161
+ callback = getCallback(method, target_id),
162
+ params = [];
163
+
164
+ if (!callback) {
165
+ return false;
166
+ }
167
+
168
+ if (value !== undefined) {
169
+ params.push(value);
170
+ }
171
+
172
+ if (eventData) {
173
+ params.push(eventData);
174
+ }
175
+
176
+ if (target_id) {
177
+ params.push(target_id);
178
+ }
179
+
180
+ return params.length > 0 ? callback.apply(null, params) : callback.call();
181
+ }
182
+
183
+
184
+ /**
185
+ * Stores submitted callbacks for each iframe being tracked and each
186
+ * event for that iframe.
187
+ *
188
+ * @param eventName (String): Name of the event. Eg. api_onPlay
189
+ * @param callback (Function): Function that should get executed when the
190
+ * event is fired.
191
+ * @param target_id (String) [Optional]: If handling more than one iframe then
192
+ * it stores the different callbacks for different iframes based on the iframe's
193
+ * id.
194
+ */
195
+
196
+ function storeCallback(eventName, callback, target_id) {
197
+ if (target_id) {
198
+ if (!eventCallbacks[target_id]) {
199
+ eventCallbacks[target_id] = {};
200
+ }
201
+ eventCallbacks[target_id][eventName] = callback;
202
+ } else {
203
+ eventCallbacks[eventName] = callback;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Retrieves stored callbacks.
209
+ */
210
+
211
+ function getCallback(eventName, target_id) {
212
+ if (target_id) {
213
+ return eventCallbacks[target_id][eventName];
214
+ } else {
215
+ return eventCallbacks[eventName];
216
+ }
217
+ }
218
+
219
+ function removeCallback(eventName, target_id) {
220
+ if (target_id && eventCallbacks[target_id]) {
221
+ if (!eventCallbacks[target_id][eventName]) {
222
+ return false;
223
+ }
224
+ eventCallbacks[target_id][eventName] = null;
225
+ } else {
226
+ if (!eventCallbacks[eventName]) {
227
+ return false;
228
+ }
229
+ eventCallbacks[eventName] = null;
230
+ }
231
+
232
+ return true;
233
+ }
234
+
235
+ function isFunction(obj) {
236
+ return !!(obj && obj.constructor && obj.call && obj.apply);
237
+ }
238
+
239
+ function isArray(obj) {
240
+ return toString.call(obj) === '[object Array]';
241
+ }
242
+
243
+ // Give the init function the Froogaloop prototype for later instantiation
244
+ Froogaloop.fn.init.prototype = Froogaloop.fn;
245
+
246
+ // Listens for the message event.
247
+ // W3C
248
+ if (window.addEventListener) {
249
+ window.addEventListener('message', onMessageReceived, false);
250
+ }
251
+ // IE
252
+ else {
253
+ window.attachEvent('onmessage', onMessageReceived);
254
+ }
255
+
256
+ // Expose froogaloop to the global object
257
+ return (window.Froogaloop = window.$f = Froogaloop);
258
+
259
+ })();
js/gtm4wp-contact-form-7-tracker.js CHANGED
@@ -1,24 +1,24 @@
1
- jQuery( function() {
2
- jQuery( ".wpcf7" )
3
- .on( 'wpcf7mailsent', function( e ) {
4
- var gtm4wp_cf7formid = '(not set)';
5
- if ( e && e.detail && e.detail.contactFormId ) {
6
- gtm4wp_cf7formid = e.detail.contactFormId;
7
- } else if ( e && e.originalEvent && e.originalEvent.detail && e.originalEvent.detail.contactFormId ) {
8
- gtm4wp_cf7formid = e.originalEvent.detail.contactFormId;
9
- }
10
-
11
- var gtm4wp_cf7forminputs = [];
12
- if ( e && e.detail && e.detail.inputs ) {
13
- gtm4wp_cf7forminputs = e.detail.inputs;
14
- } else if ( e && e.originalEvent && e.originalEvent.detail && e.originalEvent.detail.inputs ) {
15
- gtm4wp_cf7forminputs = e.originalEvent.detail.inputs;
16
- }
17
-
18
- window[ gtm4wp_datalayer_name ].push({
19
- 'event': 'gtm4wp.contactForm7Submitted',
20
- 'gtm4wp.cf7formid': gtm4wp_cf7formid,
21
- 'gtm4wp.cf7inputs': gtm4wp_cf7forminputs
22
- });
23
- });
24
  });
1
+ jQuery( function() {
2
+ jQuery( ".wpcf7" )
3
+ .on( 'wpcf7mailsent', function( e ) {
4
+ var gtm4wp_cf7formid = '(not set)';
5
+ if ( e && e.detail && e.detail.contactFormId ) {
6
+ gtm4wp_cf7formid = e.detail.contactFormId;
7
+ } else if ( e && e.originalEvent && e.originalEvent.detail && e.originalEvent.detail.contactFormId ) {
8
+ gtm4wp_cf7formid = e.originalEvent.detail.contactFormId;
9
+ }
10
+
11
+ var gtm4wp_cf7forminputs = [];
12
+ if ( e && e.detail && e.detail.inputs ) {
13
+ gtm4wp_cf7forminputs = e.detail.inputs;
14
+ } else if ( e && e.originalEvent && e.originalEvent.detail && e.originalEvent.detail.inputs ) {
15
+ gtm4wp_cf7forminputs = e.originalEvent.detail.inputs;
16
+ }
17
+
18
+ window[ gtm4wp_datalayer_name ].push({
19
+ 'event': 'gtm4wp.contactForm7Submitted',
20
+ 'gtm4wp.cf7formid': gtm4wp_cf7formid,
21
+ 'gtm4wp.cf7inputs': gtm4wp_cf7forminputs
22
+ });
23
+ });
24
  });
js/gtm4wp-download-tracker.js DELETED
@@ -1,14 +0,0 @@
1
- function gtm4wp_track_downloads(track_extensions) {
2
- var gtm4wp_extensions_to_track = track_extensions.split(",");
3
-
4
- for ( var i = 0; i < gtm4wp_extensions_to_track.length; i++ ) {
5
- jQuery( "a[href$=\\." + gtm4wp_extensions_to_track[i].toLowerCase() + "], a[href$=\\." + gtm4wp_extensions_to_track[i].toUpperCase() + "]" )
6
- .on( "click", function() {
7
- window[ gtm4wp_datalayer_name ].push({
8
- 'event': 'gtm4wp.downloadClick',
9
- 'linkhref': jQuery( this ).attr( "href" )
10
- });
11
- })
12
- .attr( "target", "_blank" );
13
- } // end for i
14
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/gtm4wp-email-link-tracker.js DELETED
@@ -1,12 +0,0 @@
1
- jQuery( function() {
2
- jQuery( "a[href^=mailto]" )
3
- .on( "click", function() {
4
- var gtm4wp_linkparts = jQuery( this ).attr( "href" ).split( ":" );
5
-
6
- window[ gtm4wp_datalayer_name ].push({
7
- 'event': 'gtm4wp.emailClick',
8
- 'linkhref': gtm4wp_linkparts
9
- });
10
- })
11
- .attr( "target", "_blank" );
12
- });
 
 
 
 
 
 
 
 
 
 
 
 
js/gtm4wp-form-move-tracker.js CHANGED
@@ -1,50 +1,50 @@
1
- jQuery( function() {
2
- jQuery( ":input" )
3
- .on( "focus", function() {
4
- var input = jQuery(this);
5
- var inputID = input.attr("id") || "(no input ID)";
6
- var inputName = input.attr("name") || "(no input name)";
7
- var inputClass = input.attr("class") || "(no input class)";
8
-
9
- var form = jQuery(this.form);
10
- var formID = form.attr("id") || "(no form ID)";
11
- var formName = form.attr("name") || "(no form name)";
12
- var formClass = form.attr("class") || "(no form class)";
13
-
14
- window[ gtm4wp_datalayer_name ].push({
15
- 'event' : 'gtm4wp.formElementEnter',
16
-
17
- 'inputID' : inputID,
18
- 'inputName' : inputName,
19
- 'inputClass': inputClass,
20
-
21
- 'formID' : formID,
22
- 'formName' : formName,
23
- 'formClass': formClass
24
- });
25
- })
26
-
27
- .on( "blur", function() {
28
- var input = jQuery(this);
29
- var inputID = input.attr("id") || "(no input ID)";
30
- var inputName = input.attr("name") || "(no input name)";
31
- var inputClass = input.attr("class") || "(no input class)";
32
-
33
- var form = jQuery(this.form);
34
- var formID = form.attr("id") || "(no form ID)";
35
- var formName = form.attr("name") || "(no form name)";
36
- var formClass = form.attr("class") || "(no form class)";
37
-
38
- window[ gtm4wp_datalayer_name ].push({
39
- 'event' : 'gtm4wp.formElementLeave',
40
-
41
- 'inputID' : inputID,
42
- 'inputName' : inputName,
43
- 'inputClass': inputClass,
44
-
45
- 'formID' : formID,
46
- 'formName' : formName,
47
- 'formClass': formClass
48
- });
49
- });
50
  });
1
+ jQuery( function() {
2
+ jQuery( ":input" )
3
+ .on( "focus", function() {
4
+ var input = jQuery(this);
5
+ var inputID = input.attr("id") || "(no input ID)";
6
+ var inputName = input.attr("name") || "(no input name)";
7
+ var inputClass = input.attr("class") || "(no input class)";
8
+
9
+ var form = jQuery(this.form);
10
+ var formID = form.attr("id") || "(no form ID)";
11
+ var formName = form.attr("name") || "(no form name)";
12
+ var formClass = form.attr("class") || "(no form class)";
13
+
14
+ window[ gtm4wp_datalayer_name ].push({
15
+ 'event' : 'gtm4wp.formElementEnter',
16
+
17
+ 'inputID' : inputID,
18
+ 'inputName' : inputName,
19
+ 'inputClass': inputClass,
20
+
21
+ 'formID' : formID,
22
+ 'formName' : formName,
23
+ 'formClass': formClass
24
+ });
25
+ })
26
+
27
+ .on( "blur", function() {
28
+ var input = jQuery(this);
29
+ var inputID = input.attr("id") || "(no input ID)";
30
+ var inputName = input.attr("name") || "(no input name)";
31
+ var inputClass = input.attr("class") || "(no input class)";
32
+
33
+ var form = jQuery(this.form);
34
+ var formID = form.attr("id") || "(no form ID)";
35
+ var formName = form.attr("name") || "(no form name)";
36
+ var formClass = form.attr("class") || "(no form class)";
37
+
38
+ window[ gtm4wp_datalayer_name ].push({
39
+ 'event' : 'gtm4wp.formElementLeave',
40
+
41
+ 'inputID' : inputID,
42
+ 'inputName' : inputName,
43
+ 'inputClass': inputClass,
44
+
45
+ 'formID' : formID,
46
+ 'formName' : formName,
47
+ 'formClass': formClass
48
+ });
49
+ });
50
  });
js/gtm4wp-outbound-click-tracker.js DELETED
@@ -1,19 +0,0 @@
1
- jQuery( function() {
2
- var gtm4wp_localdomain = window.location.hostname.replace( "www.", "" );
3
-
4
- jQuery( "a[href^=http]" )
5
- .each( function() {
6
- var gtm4wp_linkhref = jQuery( this ).attr( "href" );
7
-
8
- if ( gtm4wp_linkhref.indexOf( gtm4wp_localdomain ) == -1 ) {
9
- jQuery( this )
10
- .on( "click", function() {
11
- window[ gtm4wp_datalayer_name ].push({
12
- 'event': 'gtm4wp.outboundClick',
13
- 'linkhref': jQuery( this ).attr( "href" )
14
- });
15
- })
16
- .attr( "target", "_blank" );
17
- }
18
- });
19
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/gtm4wp-social-tracker.js DELETED
@@ -1,107 +0,0 @@
1
- jQuery( function() {
2
- if ( typeof FB != "undefined" ) {
3
- FB.Event.subscribe( 'edge.create', function( href, widget ) {
4
- window[ gtm4wp_datalayer_name ].push({
5
- 'event': 'gtm4wp.socialAction',
6
- 'network': 'facebook',
7
- 'socialAction': 'like',
8
- 'opt_target': href,
9
- 'opt_pagePath': window.location.href
10
- });
11
- });
12
-
13
- FB.Event.subscribe( 'edge.remove', function( href, widget ) {
14
- window[ gtm4wp_datalayer_name ].push({
15
- 'event': 'gtm4wp.socialAction',
16
- 'network': 'facebook',
17
- 'socialAction': 'unlike',
18
- 'opt_target': href,
19
- 'opt_pagePath': window.location.href
20
- });
21
- });
22
-
23
- FB.Event.subscribe( 'comment.create', function( href, commentID ) {
24
- window[ gtm4wp_datalayer_name ].push({
25
- 'event': 'gtm4wp.socialAction',
26
- 'network': 'facebook',
27
- 'socialAction': 'comment',
28
- 'opt_target': href,
29
- 'opt_pagePath': window.location.href
30
- });
31
- });
32
-
33
- FB.Event.subscribe( 'comment.remove', function( href, commentID ) {
34
- window[ gtm4wp_datalayer_name ].push({
35
- 'event': 'gtm4wp.socialAction',
36
- 'network': 'facebook',
37
- 'socialAction': 'uncomment',
38
- 'opt_target': href,
39
- 'opt_pagePath': window.location.href
40
- });
41
- });
42
-
43
- FB.Event.subscribe( 'message.send', function( response ) {
44
- window[ gtm4wp_datalayer_name ].push({
45
- 'event': 'gtm4wp.socialAction',
46
- 'network': 'facebook',
47
- 'socialAction': 'send',
48
- 'opt_target': response,
49
- 'opt_pagePath': window.location.href
50
- });
51
- });
52
- } // end of Facebook social events
53
-
54
- if ( typeof window.twttr == "undefined" ) {
55
- window.twttr = (function ( d, s, id ) {
56
- var t, js, fjs = d.getElementsByTagName(s)[0];
57
- if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;
58
- js.src="https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);
59
- return window.twttr || (t = {
60
- _e: [],
61
- ready: function(f) {
62
- t._e.push(f);
63
- }
64
- });
65
- } (document, "script", "twitter-wjs"));
66
- } // end of loading Twitter JS
67
-
68
- if ( typeof window.twttr != "undefined" ) {
69
- window.twttr.ready(function ( twttr ) {
70
- twttr.events.bind( 'tweet', function ( intent_event ) {
71
- if ( intent_event ) {
72
- var label = intent_event.data.tweet_id;
73
-
74
- if (typeof label != 'undefined' && label) {
75
- if(label == 'label'){
76
- label = window.location.href;
77
- }
78
- }else{
79
- label = window.location.href;
80
- }
81
-
82
- window[ gtm4wp_datalayer_name ].push({
83
- 'event': 'gtm4wp.socialAction',
84
- 'network': 'twitter',
85
- 'socialAction': 'tweet',
86
- 'opt_target': label,
87
- 'opt_pagePath': window.location.href
88
- });
89
- }
90
- });
91
-
92
- window.twttr.events.bind( 'follow', function ( intent_event ) {
93
- if ( intent_event ) {
94
- var label = intent_event.data.user_id + " (" + intent_event.data.screen_name + ")";
95
-
96
- window[ gtm4wp_datalayer_name ].push({
97
- 'event': 'gtm4wp.socialAction',
98
- 'network': 'twitter',
99
- 'socialAction': 'follow',
100
- 'opt_target': label,
101
- 'opt_pagePath': window.location.href
102
- });
103
- }
104
- });
105
- });
106
- }
107
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/gtm4wp-soundcloud.js CHANGED
@@ -1,137 +1,137 @@
1
- var gtm4wp_soundclound_percentage_tracking = 10;
2
- var gtm4wp_soundclound_percentage_tracking_marks = {};
3
-
4
- jQuery(function() {
5
- // jQuery( '[id^="soundcloudplayer_"]' ).each(function() {
6
- jQuery( 'iframe[src*="soundcloud.com"]' ).each(function() {
7
- var iframe = this,
8
- widget = SC.Widget( this ),
9
- jqframe = jQuery( iframe ),
10
- sound = {};
11
-
12
- widget.bind( SC.Widget.Events.READY, function() {
13
- widget.getCurrentSound(function( soundData ) {
14
-
15
- jqframe.attr( "data-player_id", soundData.id );
16
- jqframe.attr( "data-player_author", soundData.user.username );
17
- jqframe.attr( "data-player_title", soundData.title );
18
- jqframe.attr( "data-player_url", soundData.permalink_url );
19
- jqframe.attr( "data-player_duration", soundData.duration );
20
-
21
- sound = soundData;
22
-
23
- window[ gtm4wp_datalayer_name ].push({
24
- 'event': 'gtm4wp.mediaPlayerReady',
25
- 'mediaType': 'soundcloud',
26
- 'mediaData': {
27
- 'id': soundData.id,
28
- 'author': soundData.user.username,
29
- 'title': soundData.title,
30
- 'url': soundData.permalink_url,
31
- 'duration': soundData.duration
32
- },
33
- 'mediaCurrentTime': 0
34
- });
35
- }); // end of api call getDuration
36
-
37
- widget.bind( SC.Widget.Events.PLAY_PROGRESS, function( eventData ) {
38
- gtm4wp_onSoundCloudPercentageChange( eventData );
39
- });
40
-
41
- widget.bind( SC.Widget.Events.PLAY, function( eventData ) {
42
- gtm4wp_onSoundCloudPlayerStateChange( eventData, 'play' );
43
- });
44
-
45
- widget.bind( SC.Widget.Events.PAUSE, function( eventData ) {
46
- gtm4wp_onSoundCloudPlayerStateChange( eventData, 'pause' );
47
- });
48
-
49
- widget.bind( SC.Widget.Events.FINISH, function( eventData ) {
50
- gtm4wp_onSoundCloudPlayerStateChange( eventData, 'ended' );
51
- });
52
-
53
- widget.bind( SC.Widget.Events.SEEK, function( eventData ) {
54
- gtm4wp_onSoundCloudPlayerStateChange( eventData, 'seeked' );
55
- });
56
-
57
- widget.bind( SC.Widget.Events.CLICK_DOWNLOAD, function() {
58
- gtm4wp_onSoundCloudPlayerEvent( 'click-download' );
59
- });
60
-
61
- widget.bind( SC.Widget.Events.CLICK_BUY, function() {
62
- gtm4wp_onSoundCloudPlayerEvent( 'click-buy' );
63
- });
64
-
65
- widget.bind( SC.Widget.Events.OPEN_SHARE_PANEL, function() {
66
- gtm4wp_onSoundCloudPlayerEvent( 'open-share-panel' );
67
- });
68
-
69
- widget.bind( SC.Widget.Events.ERROR, function() {
70
- gtm4wp_onSoundCloudPlayerEvent( 'error' );
71
- });
72
- });
73
-
74
- var gtm4wp_onSoundCloudPlayerStateChange = function( eventData, playerState ) {
75
- window[ gtm4wp_datalayer_name ].push({
76
- 'event': 'gtm4wp.mediaPlayerStateChange',
77
- 'mediaType': 'soundcloud',
78
- 'mediaData': {
79
- 'id': sound.id,
80
- 'author': sound.user.username,
81
- 'title': sound.title,
82
- 'url': sound.permalink_url,
83
- 'duration': sound.duration
84
- },
85
- 'mediaCurrentTime': eventData.currentPosition,
86
- 'mediaPlayerState': playerState
87
- });
88
- };
89
-
90
- var gtm4wp_onSoundCloudPercentageChange = function( eventData ) {
91
- var mediaPercentage = Math.floor( eventData.currentPosition / sound.duration * 100 );
92
-
93
- if ( typeof gtm4wp_soundclound_percentage_tracking_marks[ sound.id ] == "undefined" ) {
94
- gtm4wp_soundclound_percentage_tracking_marks[ sound.id ] = [];
95
- }
96
-
97
- for( var i=0; i<100; i+=gtm4wp_soundclound_percentage_tracking ) {
98
- if ( ( mediaPercentage > i ) && ( gtm4wp_soundclound_percentage_tracking_marks[ sound.id ].indexOf( i ) == -1 ) ) {
99
- gtm4wp_soundclound_percentage_tracking_marks[ sound.id ].push( i );
100
-
101
- window[ gtm4wp_datalayer_name ].push({
102
- 'event': 'gtm4wp.mediaPlaybackPercentage',
103
- 'mediaType': 'soundcloud',
104
- 'mediaData': {
105
- 'id': sound.id,
106
- 'author': sound.user.username,
107
- 'title': sound.title,
108
- 'url': sound.permalink_url,
109
- 'duration': sound.duration
110
- },
111
- 'mediaCurrentTime': eventData.currentPosition,
112
- 'mediaPercentage': i
113
- });
114
- }
115
- }
116
- };
117
-
118
- var gtm4wp_onSoundCloudPlayerEvent = function( eventName ) {
119
- widget.getPosition(function( currentPosition ) {
120
- window[ gtm4wp_datalayer_name ].push({
121
- 'event': 'gtm4wp.mediaPlayerEvent',
122
- 'mediaType': 'soundcloud',
123
- 'mediaData': {
124
- 'id': sound.id,
125
- 'author': sound.user.username,
126
- 'title': sound.title,
127
- 'url': sound.permalink_url,
128
- 'duration': soundData.duration
129
- },
130
- 'mediaCurrentTime': currentPosition,
131
- 'mediaPlayerEvent': eventName
132
- });
133
- });
134
- };
135
-
136
- });
137
  });
1
+ var gtm4wp_soundclound_percentage_tracking = 10;
2
+ var gtm4wp_soundclound_percentage_tracking_marks = {};
3
+
4
+ jQuery(function() {
5
+ // jQuery( '[id^="soundcloudplayer_"]' ).each(function() {
6
+ jQuery( 'iframe[src*="soundcloud.com"]' ).each(function() {
7
+ var iframe = this,
8
+ widget = SC.Widget( this ),
9
+ jqframe = jQuery( iframe ),
10
+ sound = {};
11
+
12
+ widget.bind( SC.Widget.Events.READY, function() {
13
+ widget.getCurrentSound(function( soundData ) {
14
+
15
+ jqframe.attr( "data-player_id", soundData.id );
16
+ jqframe.attr( "data-player_author", soundData.user.username );
17
+ jqframe.attr( "data-player_title", soundData.title );
18
+ jqframe.attr( "data-player_url", soundData.permalink_url );
19
+ jqframe.attr( "data-player_duration", soundData.duration );
20
+
21
+ sound = soundData;
22
+
23
+ window[ gtm4wp_datalayer_name ].push({
24
+ 'event': 'gtm4wp.mediaPlayerReady',
25
+ 'mediaType': 'soundcloud',
26
+ 'mediaData': {
27
+ 'id': soundData.id,
28
+ 'author': soundData.user.username,
29
+ 'title': soundData.title,
30
+ 'url': soundData.permalink_url,
31
+ 'duration': soundData.duration
32
+ },
33
+ 'mediaCurrentTime': 0
34
+ });
35
+ }); // end of api call getDuration
36
+
37
+ widget.bind( SC.Widget.Events.PLAY_PROGRESS, function( eventData ) {
38
+ gtm4wp_onSoundCloudPercentageChange( eventData );
39
+ });
40
+
41
+ widget.bind( SC.Widget.Events.PLAY, function( eventData ) {
42
+ gtm4wp_onSoundCloudPlayerStateChange( eventData, 'play' );
43
+ });
44
+
45
+ widget.bind( SC.Widget.Events.PAUSE, function( eventData ) {
46
+ gtm4wp_onSoundCloudPlayerStateChange( eventData, 'pause' );
47
+ });
48
+
49
+ widget.bind( SC.Widget.Events.FINISH, function( eventData ) {
50
+ gtm4wp_onSoundCloudPlayerStateChange( eventData, 'ended' );
51
+ });
52
+
53
+ widget.bind( SC.Widget.Events.SEEK, function( eventData ) {
54
+ gtm4wp_onSoundCloudPlayerStateChange( eventData, 'seeked' );
55
+ });
56
+
57
+ widget.bind( SC.Widget.Events.CLICK_DOWNLOAD, function() {
58
+ gtm4wp_onSoundCloudPlayerEvent( 'click-download' );
59
+ });
60
+
61
+ widget.bind( SC.Widget.Events.CLICK_BUY, function() {
62
+ gtm4wp_onSoundCloudPlayerEvent( 'click-buy' );
63
+ });
64
+
65
+ widget.bind( SC.Widget.Events.OPEN_SHARE_PANEL, function() {
66
+ gtm4wp_onSoundCloudPlayerEvent( 'open-share-panel' );
67
+ });
68
+
69
+ widget.bind( SC.Widget.Events.ERROR, function() {
70
+ gtm4wp_onSoundCloudPlayerEvent( 'error' );
71
+ });
72
+ });
73
+
74
+ var gtm4wp_onSoundCloudPlayerStateChange = function( eventData, playerState ) {
75
+ window[ gtm4wp_datalayer_name ].push({
76
+ 'event': 'gtm4wp.mediaPlayerStateChange',
77
+ 'mediaType': 'soundcloud',
78
+ 'mediaData': {
79
+ 'id': sound.id,
80
+ 'author': sound.user.username,
81
+ 'title': sound.title,
82
+ 'url': sound.permalink_url,
83
+ 'duration': sound.duration
84
+ },
85
+ 'mediaCurrentTime': eventData.currentPosition,
86
+ 'mediaPlayerState': playerState
87
+ });
88
+ };
89
+
90
+ var gtm4wp_onSoundCloudPercentageChange = function( eventData ) {
91
+ var mediaPercentage = Math.floor( eventData.currentPosition / sound.duration * 100 );
92
+
93
+ if ( typeof gtm4wp_soundclound_percentage_tracking_marks[ sound.id ] == "undefined" ) {
94
+ gtm4wp_soundclound_percentage_tracking_marks[ sound.id ] = [];
95
+ }
96
+
97
+ for( var i=0; i<100; i+=gtm4wp_soundclound_percentage_tracking ) {
98
+ if ( ( mediaPercentage > i ) && ( gtm4wp_soundclound_percentage_tracking_marks[ sound.id ].indexOf( i ) == -1 ) ) {
99
+ gtm4wp_soundclound_percentage_tracking_marks[ sound.id ].push( i );
100
+
101
+ window[ gtm4wp_datalayer_name ].push({
102
+ 'event': 'gtm4wp.mediaPlaybackPercentage',
103
+ 'mediaType': 'soundcloud',
104
+ 'mediaData': {
105
+ 'id': sound.id,
106
+ 'author': sound.user.username,
107
+ 'title': sound.title,
108
+ 'url': sound.permalink_url,
109
+ 'duration': sound.duration
110
+ },
111
+ 'mediaCurrentTime': eventData.currentPosition,
112
+ 'mediaPercentage': i
113
+ });
114
+ }
115
+ }
116
+ };
117
+
118
+ var gtm4wp_onSoundCloudPlayerEvent = function( eventName ) {
119
+ widget.getPosition(function( currentPosition ) {
120
+ window[ gtm4wp_datalayer_name ].push({
121
+ 'event': 'gtm4wp.mediaPlayerEvent',
122
+ 'mediaType': 'soundcloud',
123
+ 'mediaData': {
124
+ 'id': sound.id,
125
+ 'author': sound.user.username,
126
+ 'title': sound.title,
127
+ 'url': sound.permalink_url,
128
+ 'duration': soundData.duration
129
+ },
130
+ 'mediaCurrentTime': currentPosition,
131
+ 'mediaPlayerEvent': eventName
132
+ });
133
+ });
134
+ };
135
+
136
+ });
137
  });
js/gtm4wp-users.js CHANGED
@@ -1,39 +1,39 @@
1
- function gtm4wp_set_cookie( cookiename, cookievalue, expiredays ) {
2
- var d = new Date();
3
- d.setTime(d.getTime() + (expiredays*24*60*60*1000));
4
- var expires = "expires="+ d.toUTCString();
5
-
6
- document.cookie = cookiename + "=" + cookievalue + ";" + expires + ";path=/";
7
- }
8
-
9
- function gtm4wp_get_cookie( cookiename ) {
10
- var decoded_cookie_list = decodeURIComponent(document.cookie).split(';');
11
- var onecookie = '';
12
-
13
- for( var i=0; i<decoded_cookie_list.length; i++ ) {
14
- onecookie = decoded_cookie_list[i].trim();
15
- if ( 0 == onecookie.indexOf( cookiename ) ) {
16
- return onecookie.substring( cookiename.length+1, onecookie.length );
17
- }
18
- }
19
-
20
- return "";
21
- }
22
-
23
- var gtm4wp_user_logged_in = gtm4wp_get_cookie( 'gtm4wp_user_logged_in' );
24
- if ( gtm4wp_user_logged_in === "1" ) {
25
- window[ gtm4wp_datalayer_name ].push({
26
- 'event': 'gtm4wp.userLoggedIn',
27
- });
28
-
29
- gtm4wp_set_cookie( 'gtm4wp_user_logged_in', '', -1 );
30
- }
31
-
32
- var gtm4wp_new_user_registered = gtm4wp_get_cookie( 'gtm4wp_user_registered' );
33
- if ( gtm4wp_new_user_registered === "1" ) {
34
- window[ gtm4wp_datalayer_name ].push({
35
- 'event': 'gtm4wp.userRegistered',
36
- });
37
-
38
- gtm4wp_set_cookie( 'gtm4wp_user_registered', '', -1 );
39
- }
1
+ function gtm4wp_set_cookie( cookiename, cookievalue, expiredays ) {
2
+ var d = new Date();
3
+ d.setTime(d.getTime() + (expiredays*24*60*60*1000));
4
+ var expires = "expires="+ d.toUTCString();
5
+
6
+ document.cookie = cookiename + "=" + cookievalue + ";" + expires + ";path=/";
7
+ }
8
+
9
+ function gtm4wp_get_cookie( cookiename ) {
10
+ var decoded_cookie_list = decodeURIComponent(document.cookie).split(';');
11
+ var onecookie = '';
12
+
13
+ for( var i=0; i<decoded_cookie_list.length; i++ ) {
14
+ onecookie = decoded_cookie_list[i].trim();
15
+ if ( 0 == onecookie.indexOf( cookiename ) ) {
16
+ return onecookie.substring( cookiename.length+1, onecookie.length );
17
+ }
18
+ }
19
+
20
+ return "";
21
+ }
22
+
23
+ var gtm4wp_user_logged_in = gtm4wp_get_cookie( 'gtm4wp_user_logged_in' );
24
+ if ( gtm4wp_user_logged_in === "1" ) {
25
+ window[ gtm4wp_datalayer_name ].push({
26
+ 'event': 'gtm4wp.userLoggedIn',
27
+ });
28
+
29
+ gtm4wp_set_cookie( 'gtm4wp_user_logged_in', '', -1 );
30
+ }
31
+
32
+ var gtm4wp_new_user_registered = gtm4wp_get_cookie( 'gtm4wp_user_registered' );
33
+ if ( gtm4wp_new_user_registered === "1" ) {
34
+ window[ gtm4wp_datalayer_name ].push({
35
+ 'event': 'gtm4wp.userRegistered',
36
+ });
37
+
38
+ gtm4wp_set_cookie( 'gtm4wp_user_registered', '', -1 );
39
+ }
js/gtm4wp-vimeo-froogaloop.js DELETED
@@ -1,105 +0,0 @@
1
- var gtm4wp_vimeo_percentage_tracking = 10;
2
- var gtm4wp_vimeo_percentage_tracking_marks = {};
3
-
4
- jQuery(function() {
5
- jQuery( '[id^="vimeoplayer_"]' ).each(function() {
6
- var vimeoapi = $f( this ),
7
- jqframe = jQuery( this ),
8
- videourl = jqframe
9
- .attr( "src" )
10
- .split( "?" )
11
- .shift(),
12
- videoid = videourl.split( "/" ).pop();
13
-
14
- jqframe.attr( "data-player_id", videoid );
15
- jqframe.attr( "data-player_url", videourl );
16
-
17
- vimeoapi.addEvent( 'ready', function( player_id ) {
18
- vimeoapi.api( 'getDuration', function( value, player_id ) {
19
-
20
- jqframe.attr( "data-player_duration", value );
21
-
22
- window[ gtm4wp_datalayer_name ].push({
23
- 'event': 'gtm4wp.mediaPlayerReady',
24
- 'mediaType': 'vimeo',
25
- 'mediaData': {
26
- 'id': videoid,
27
- 'author': '',
28
- 'title': jqframe.attr( "title" ),
29
- 'url': videourl,
30
- 'duration': value
31
- },
32
- 'mediaCurrentTime': 0
33
- });
34
- }); // end of api call getDuration
35
-
36
- vimeoapi.addEvent( 'playProgress', function( value, player_id ) {
37
- gtm4wp_onVimeoPercentageChange( value );
38
- });
39
-
40
- vimeoapi.addEvent( 'play', function( player_id ) {
41
- gtm4wp_onVimeoPlayerStateChange( 'play' );
42
- });
43
-
44
- vimeoapi.addEvent( 'pause', function( player_id ) {
45
- gtm4wp_onVimeoPlayerStateChange( 'pause' );
46
- });
47
-
48
- vimeoapi.addEvent( 'finish', function( player_id ) {
49
- gtm4wp_onVimeoPlayerStateChange( 'finish' );
50
- });
51
-
52
- vimeoapi.addEvent( 'seek', function( value, player_id ) {
53
- gtm4wp_onVimeoPlayerStateChange( 'seek' );
54
- });
55
-
56
- var gtm4wp_onVimeoPlayerStateChange = function( player_state ) {
57
- vimeoapi.api( 'getCurrentTime', function( value, player_id ) {
58
- window[ gtm4wp_datalayer_name ].push({
59
- 'event': 'gtm4wp.mediaPlayerStateChange',
60
- 'mediaType': 'vimeo',
61
- 'mediaData': {
62
- 'id': videoid,
63
- 'author': '',
64
- 'title': jqframe.attr( "title" ),
65
- 'url': jqframe.attr( "data-player_url" ),
66
- 'duration': parseInt( jqframe.attr( "data-player_duration" ) )
67
- },
68
- 'mediaPlayerState': player_state,
69
- 'mediaCurrentTime': value
70
- });
71
- });
72
- };
73
-
74
- var gtm4wp_onVimeoPercentageChange = function( data ) {
75
- var videoDuration = parseInt( jqframe.attr( "data-player_duration" ) );
76
- var videoPercentage = Math.floor( data.seconds / videoDuration * 100 );
77
-
78
- if ( typeof gtm4wp_vimeo_percentage_tracking_marks[ videoid ] == "undefined" ) {
79
- gtm4wp_vimeo_percentage_tracking_marks[ videoid ] = [];
80
- }
81
-
82
- for( var i=0; i<100; i+=gtm4wp_vimeo_percentage_tracking ) {
83
- if ( ( videoPercentage > i ) && ( gtm4wp_vimeo_percentage_tracking_marks[ videoid ].indexOf( i ) == -1 ) ) {
84
- gtm4wp_vimeo_percentage_tracking_marks[ videoid ].push( i );
85
-
86
- window[ gtm4wp_datalayer_name ].push({
87
- 'event': 'gtm4wp.mediaPlaybackPercentage',
88
- 'mediaType': 'vimeo',
89
- 'mediaData': {
90
- 'id': videoid,
91
- 'author': '',
92
- 'title': jqframe.attr( "title" ),
93
- 'url': jqframe.attr( "data-player_url" ),
94
- 'duration': videoDuration
95
- },
96
- 'mediaCurrentTime': data.seconds,
97
- 'mediaPercentage': i
98
- });
99
- }
100
- }
101
- };
102
-
103
- });
104
- });
105
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/gtm4wp-vimeo.js CHANGED
@@ -1,268 +1,268 @@
1
- var gtm4wp_vimeo_percentage_tracking = 10;
2
- var gtm4wp_vimeo_percentage_tracking_marks = {};
3
-
4
- jQuery(function() {
5
- jQuery( 'iframe[src*="vimeo.com"]' ).each(function() {
6
- var vimeoapi = new Vimeo.Player( this ),
7
- jqframe = jQuery( this ),
8
- videourl = jqframe
9
- .attr( "src" )
10
- .split( "?" )
11
- .shift(),
12
- videoid = videourl.split( "/" ).pop();
13
-
14
- jqframe.attr( "data-player_id", videoid );
15
- jqframe.attr( "data-player_url", videourl );
16
-
17
- vimeoapi.getVideoTitle().then( function( title ) {
18
- jqframe.attr( "data-player_title", title );
19
-
20
- vimeoapi.getDuration().then( function( duration ) {
21
-
22
- jqframe.attr( "data-player_duration", duration );
23
-
24
- window[ gtm4wp_datalayer_name ].push({
25
- 'event': 'gtm4wp.mediaPlayerReady',
26
- 'mediaType': 'vimeo',
27
- 'mediaData': {
28
- 'id': videoid,
29
- 'author': '',
30
- 'title': jqframe.attr( "data-player_title" ),
31
- 'url': videourl,
32
- 'duration': duration
33
- },
34
- 'mediaCurrentTime': 0
35
- });
36
-
37
- }).catch( function( error ) {
38
-
39
- window[ gtm4wp_datalayer_name ].push({
40
- 'event': 'gtm4wp.mediaPlayerEvent',
41
- 'mediaType': 'vimeo',
42
- 'mediaData': {
43
- 'id': videoid,
44
- 'author': '',
45
- 'title': jqframe.attr( "data-player_title" ),
46
- 'url': videourl,
47
- 'duration': 0
48
- },
49
- 'mediaCurrentTime': 0,
50
- 'mediaPlayerEvent': 'error',
51
- 'mediaPlayerEventParam': error
52
- });
53
-
54
- }); // end of api call getDuration
55
-
56
- }).catch( function( error ) {
57
-
58
- window[ gtm4wp_datalayer_name ].push({
59
- 'event': 'gtm4wp.mediaPlayerEvent',
60
- 'mediaType': 'vimeo',
61
- 'mediaData': {
62
- 'id': videoid,
63
- 'author': '',
64
- 'title': "Unknown title",
65
- 'url': videourl,
66
- 'duration': 0
67
- },
68
- 'mediaCurrentTime': 0,
69
- 'mediaPlayerEvent': 'error',
70
- 'mediaPlayerEventParam': error
71
- });
72
-
73
- }); // end of api call getVideoTitle
74
-
75
- vimeoapi.on( 'play', function( data ) {
76
- gtm4wp_onVimeoPlayerStateChange( 'play', data );
77
- });
78
-
79
- vimeoapi.on( 'pause', function( data ) {
80
- gtm4wp_onVimeoPlayerStateChange( 'pause', data );
81
- });
82
-
83
- vimeoapi.on( 'ended', function( data ) {
84
- gtm4wp_onVimeoPlayerStateChange( 'ended', data );
85
- });
86
-
87
- vimeoapi.on( 'seeked', function( data ) {
88
- gtm4wp_onVimeoPlayerStateChange( 'seeked', data );
89
- });
90
-
91
- vimeoapi.on( 'texttrackchange', function( data ) {
92
-
93
- vimeoapi.getCurrentTime().then( function( seconds ) {
94
-
95
- window[ gtm4wp_datalayer_name ].push({
96
- 'event': 'gtm4wp.mediaPlayerEvent',
97
- 'mediaType': 'vimeo',
98
- 'mediaData': {
99
- 'id': videoid,
100
- 'author': '',
101
- 'title': jqframe.attr( "data-player_title" ),
102
- 'url': jqframe.attr( "data-player_url" ),
103
- 'duration': jqframe.attr( "data-player_duration" )
104
- },
105
- 'mediaPlayerEvent': 'texttrackchange',
106
- 'mediaPlayerEventParam': data,
107
- 'mediaCurrentTime': seconds
108
- });
109
-
110
- }).catch( function( error ) {
111
-
112
- window[ gtm4wp_datalayer_name ].push({
113
- 'event': 'gtm4wp.mediaPlayerEvent',
114
- 'mediaType': 'vimeo',
115
- 'mediaData': {
116
- 'id': videoid,
117
- 'author': '',
118
- 'title': "Unknown title",
119
- 'url': videourl,
120
- 'duration': jqframe.attr( "data-player_duration" )
121
- },
122
- 'mediaCurrentTime': 0,
123
- 'mediaPlayerEvent': 'error',
124
- 'mediaPlayerEventParam': error
125
- });
126
-
127
- }); // end call api getCurrentTime()
128
-
129
- });
130
-
131
- vimeoapi.on( 'volumechange', function( data ) {
132
-
133
- vimeoapi.getCurrentTime().then( function( seconds ) {
134
-
135
- window[ gtm4wp_datalayer_name ].push({
136
- 'event': 'gtm4wp.mediaPlayerEvent',
137
- 'mediaType': 'vimeo',
138
- 'mediaData': {
139
- 'id': videoid,
140
- 'author': '',
141
- 'title': jqframe.attr( "data-player_title" ),
142
- 'url': jqframe.attr( "data-player_url" ),
143
- 'duration': jqframe.attr( "data-player_duration" )
144
- },
145
- 'mediaPlayerEvent': 'volumechange',
146
- 'mediaPlayerEventParam': data.volume,
147
- 'mediaCurrentTime': seconds
148
-
149
- });
150
-
151
- }).catch( function( error ) {
152
-
153
- window[ gtm4wp_datalayer_name ].push({
154
- 'event': 'gtm4wp.mediaPlayerEvent',
155
- 'mediaType': 'vimeo',
156
- 'mediaData': {
157
- 'id': videoid,
158
- 'author': '',
159
- 'title': "Unknown title",
160
- 'url': videourl,
161
- 'duration': jqframe.attr( "data-player_duration" )
162
- },
163
- 'mediaCurrentTime': 0,
164
- 'mediaPlayerEvent': 'error',
165
- 'mediaPlayerEventParam': error
166
- });
167
-
168
- }); // end call api getCurrentTime()
169
-
170
- });
171
-
172
- vimeoapi.on( 'error', function( data ) {
173
-
174
- vimeoapi.getCurrentTime().then( function( seconds ) {
175
-
176
- window[ gtm4wp_datalayer_name ].push({
177
- 'event': 'gtm4wp.mediaPlayerEvent',
178
- 'mediaType': 'vimeo',
179
- 'mediaData': {
180
- 'id': videoid,
181
- 'author': '',
182
- 'title': jqframe.attr( "data-player_title" ),
183
- 'url': jqframe.attr( "data-player_url" ),
184
- 'duration': jqframe.attr( "data-player_duration" )
185
- },
186
- 'mediaPlayerEvent': 'error',
187
- 'mediaPlayerEventParam': data,
188
- 'mediaCurrentTime': seconds
189
-
190
- });
191
-
192
- }).catch( function( error ) {
193
-
194
- window[ gtm4wp_datalayer_name ].push({
195
- 'event': 'gtm4wp.mediaPlayerEvent',
196
- 'mediaType': 'vimeo',
197
- 'mediaData': {
198
- 'id': videoid,
199
- 'author': '',
200
- 'title': "Unknown title",
201
- 'url': videourl,
202
- 'duration': jqframe.attr( "data-player_duration" )
203
- },
204
- 'mediaCurrentTime': 0,
205
- 'mediaPlayerEvent': 'error',
206
- 'mediaPlayerEventParam': error
207
- });
208
-
209
- }); // end call api getCurrentTime()
210
-
211
- });
212
-
213
- vimeoapi.on( 'timeupdate', function( data ) {
214
- gtm4wp_onVimeoPercentageChange( data );
215
- });
216
-
217
- var gtm4wp_onVimeoPlayerStateChange = function( player_state, data ) {
218
-
219
- window[ gtm4wp_datalayer_name ].push({
220
- 'event': 'gtm4wp.mediaPlayerStateChange',
221
- 'mediaType': 'vimeo',
222
- 'mediaData': {
223
- 'id': videoid,
224
- 'author': '',
225
- 'title': jqframe.attr( "data-player_title" ),
226
- 'url': jqframe.attr( "data-player_url" ),
227
- 'duration': data.duration
228
- },
229
- 'mediaPlayerState': player_state,
230
- 'mediaCurrentTime': data.seconds
231
- });
232
-
233
- };
234
-
235
- var gtm4wp_onVimeoPercentageChange = function( data ) {
236
-
237
- var videoDuration = data.duration;
238
- var videoPercentage = Math.floor( data.seconds / videoDuration * 100 );
239
-
240
- if ( typeof gtm4wp_vimeo_percentage_tracking_marks[ videoid ] == "undefined" ) {
241
- gtm4wp_vimeo_percentage_tracking_marks[ videoid ] = [];
242
- }
243
-
244
- for( var i=0; i<100; i+=gtm4wp_vimeo_percentage_tracking ) {
245
- if ( ( videoPercentage > i ) && ( gtm4wp_vimeo_percentage_tracking_marks[ videoid ].indexOf( i ) == -1 ) ) {
246
-
247
- gtm4wp_vimeo_percentage_tracking_marks[ videoid ].push( i );
248
-
249
- window[ gtm4wp_datalayer_name ].push({
250
- 'event': 'gtm4wp.mediaPlaybackPercentage',
251
- 'mediaType': 'vimeo',
252
- 'mediaData': {
253
- 'id': videoid,
254
- 'author': '',
255
- 'title': jqframe.attr( "data-player_title" ),
256
- 'url': jqframe.attr( "data-player_url" ),
257
- 'duration': videoDuration
258
- },
259
- 'mediaCurrentTime': data.seconds,
260
- 'mediaPercentage': i
261
- });
262
-
263
- }
264
- }
265
- };
266
-
267
- });
268
- });
1
+ var gtm4wp_vimeo_percentage_tracking = 10;
2
+ var gtm4wp_vimeo_percentage_tracking_marks = {};
3
+
4
+ jQuery(function() {
5
+ jQuery( 'iframe[src*="vimeo.com"]' ).each(function() {
6
+ var vimeoapi = new Vimeo.Player( this ),
7
+ jqframe = jQuery( this ),
8
+ videourl = jqframe
9
+ .attr( "src" )
10
+ .split( "?" )
11
+ .shift(),
12
+ videoid = videourl.split( "/" ).pop();
13
+
14
+ jqframe.attr( "data-player_id", videoid );
15
+ jqframe.attr( "data-player_url", videourl );
16
+
17
+ vimeoapi.getVideoTitle().then( function( title ) {
18
+ jqframe.attr( "data-player_title", title );
19
+
20
+ vimeoapi.getDuration().then( function( duration ) {
21
+
22
+ jqframe.attr( "data-player_duration", duration );
23
+
24
+ window[ gtm4wp_datalayer_name ].push({
25
+ 'event': 'gtm4wp.mediaPlayerReady',
26
+ 'mediaType': 'vimeo',
27
+ 'mediaData': {
28
+ 'id': videoid,
29
+ 'author': '',
30
+ 'title': jqframe.attr( "data-player_title" ),
31
+ 'url': videourl,
32
+ 'duration': duration
33
+ },
34
+ 'mediaCurrentTime': 0
35
+ });
36
+
37
+ }).catch( function( error ) {
38
+
39
+ window[ gtm4wp_datalayer_name ].push({
40
+ 'event': 'gtm4wp.mediaPlayerEvent',
41
+ 'mediaType': 'vimeo',
42
+ 'mediaData': {
43
+ 'id': videoid,
44
+ 'author': '',
45
+ 'title': jqframe.attr( "data-player_title" ),
46
+ 'url': videourl,
47
+ 'duration': 0
48
+ },
49
+ 'mediaCurrentTime': 0,
50
+ 'mediaPlayerEvent': 'error',
51
+ 'mediaPlayerEventParam': error
52
+ });
53
+
54
+ }); // end of api call getDuration
55
+
56
+ }).catch( function( error ) {
57
+
58
+ window[ gtm4wp_datalayer_name ].push({
59
+ 'event': 'gtm4wp.mediaPlayerEvent',
60
+ 'mediaType': 'vimeo',
61
+ 'mediaData': {
62
+ 'id': videoid,
63
+ 'author': '',
64
+ 'title': "Unknown title",
65
+ 'url': videourl,
66
+ 'duration': 0
67
+ },
68
+ 'mediaCurrentTime': 0,
69
+ 'mediaPlayerEvent': 'error',
70
+ 'mediaPlayerEventParam': error
71
+ });
72
+
73
+ }); // end of api call getVideoTitle
74
+
75
+ vimeoapi.on( 'play', function( data ) {
76
+ gtm4wp_onVimeoPlayerStateChange( 'play', data );
77
+ });
78
+
79
+ vimeoapi.on( 'pause', function( data ) {
80
+ gtm4wp_onVimeoPlayerStateChange( 'pause', data );
81
+ });
82
+
83
+ vimeoapi.on( 'ended', function( data ) {
84
+ gtm4wp_onVimeoPlayerStateChange( 'ended', data );
85
+ });
86
+
87
+ vimeoapi.on( 'seeked', function( data ) {
88
+ gtm4wp_onVimeoPlayerStateChange( 'seeked', data );
89
+ });
90
+
91
+ vimeoapi.on( 'texttrackchange', function( data ) {
92
+
93
+ vimeoapi.getCurrentTime().then( function( seconds ) {
94
+
95
+ window[ gtm4wp_datalayer_name ].push({
96
+ 'event': 'gtm4wp.mediaPlayerEvent',
97
+ 'mediaType': 'vimeo',
98
+ 'mediaData': {
99
+ 'id': videoid,
100
+ 'author': '',
101
+ 'title': jqframe.attr( "data-player_title" ),
102
+ 'url': jqframe.attr( "data-player_url" ),
103
+ 'duration': jqframe.attr( "data-player_duration" )
104
+ },
105
+ 'mediaPlayerEvent': 'texttrackchange',
106
+ 'mediaPlayerEventParam': data,
107
+ 'mediaCurrentTime': seconds
108
+ });
109
+
110
+ }).catch( function( error ) {
111
+
112
+ window[ gtm4wp_datalayer_name ].push({
113
+ 'event': 'gtm4wp.mediaPlayerEvent',
114
+ 'mediaType': 'vimeo',
115
+ 'mediaData': {
116
+ 'id': videoid,
117
+ 'author': '',
118
+ 'title': "Unknown title",
119
+ 'url': videourl,
120
+ 'duration': jqframe.attr( "data-player_duration" )
121
+ },
122
+ 'mediaCurrentTime': 0,
123
+ 'mediaPlayerEvent': 'error',
124
+ 'mediaPlayerEventParam': error
125
+ });
126
+
127
+ }); // end call api getCurrentTime()
128
+
129
+ });
130
+
131
+ vimeoapi.on( 'volumechange', function( data ) {
132
+
133
+ vimeoapi.getCurrentTime().then( function( seconds ) {
134
+
135
+ window[ gtm4wp_datalayer_name ].push({
136
+ 'event': 'gtm4wp.mediaPlayerEvent',
137
+ 'mediaType': 'vimeo',
138
+ 'mediaData': {
139
+ 'id': videoid,
140
+ 'author': '',
141
+ 'title': jqframe.attr( "data-player_title" ),
142
+ 'url': jqframe.attr( "data-player_url" ),
143
+ 'duration': jqframe.attr( "data-player_duration" )
144
+ },
145
+ 'mediaPlayerEvent': 'volumechange',
146
+ 'mediaPlayerEventParam': data.volume,
147
+ 'mediaCurrentTime': seconds
148
+
149
+ });
150
+
151
+ }).catch( function( error ) {
152
+
153
+ window[ gtm4wp_datalayer_name ].push({
154
+ 'event': 'gtm4wp.mediaPlayerEvent',
155
+ 'mediaType': 'vimeo',
156
+ 'mediaData': {
157
+ 'id': videoid,
158
+ 'author': '',
159
+ 'title': "Unknown title",
160
+ 'url': videourl,
161
+ 'duration': jqframe.attr( "data-player_duration" )
162
+ },
163
+ 'mediaCurrentTime': 0,
164
+ 'mediaPlayerEvent': 'error',
165
+ 'mediaPlayerEventParam': error
166
+ });
167
+
168
+ }); // end call api getCurrentTime()
169
+
170
+ });
171
+
172
+ vimeoapi.on( 'error', function( data ) {
173
+
174
+ vimeoapi.getCurrentTime().then( function( seconds ) {
175
+
176
+ window[ gtm4wp_datalayer_name ].push({
177
+ 'event': 'gtm4wp.mediaPlayerEvent',
178
+ 'mediaType': 'vimeo',
179
+ 'mediaData': {
180
+ 'id': videoid,
181
+ 'author': '',
182
+ 'title': jqframe.attr( "data-player_title" ),
183
+ 'url': jqframe.attr( "data-player_url" ),
184
+ 'duration': jqframe.attr( "data-player_duration" )
185
+ },
186
+ 'mediaPlayerEvent': 'error',
187
+ 'mediaPlayerEventParam': data,
188
+ 'mediaCurrentTime': seconds
189
+
190
+ });
191
+
192
+ }).catch( function( error ) {
193
+
194
+ window[ gtm4wp_datalayer_name ].push({
195
+ 'event': 'gtm4wp.mediaPlayerEvent',
196
+ 'mediaType': 'vimeo',
197
+ 'mediaData': {
198
+ 'id': videoid,
199
+ 'author': '',
200
+ 'title': "Unknown title",
201
+ 'url': videourl,
202
+ 'duration': jqframe.attr( "data-player_duration" )
203
+ },
204
+ 'mediaCurrentTime': 0,
205
+ 'mediaPlayerEvent': 'error',
206
+ 'mediaPlayerEventParam': error
207
+ });
208
+
209
+ }); // end call api getCurrentTime()
210
+
211
+ });
212
+
213
+ vimeoapi.on( 'timeupdate', function( data ) {
214
+ gtm4wp_onVimeoPercentageChange( data );
215
+ });
216
+
217
+ var gtm4wp_onVimeoPlayerStateChange = function( player_state, data ) {
218
+
219
+ window[ gtm4wp_datalayer_name ].push({
220
+ 'event': 'gtm4wp.mediaPlayerStateChange',
221
+ 'mediaType': 'vimeo',
222
+ 'mediaData': {
223
+ 'id': videoid,
224
+ 'author': '',
225
+ 'title': jqframe.attr( "data-player_title" ),
226
+ 'url': jqframe.attr( "data-player_url" ),
227
+ 'duration': data.duration
228
+ },
229
+ 'mediaPlayerState': player_state,
230
+ 'mediaCurrentTime': data.seconds
231
+ });
232
+
233
+ };
234
+
235
+ var gtm4wp_onVimeoPercentageChange = function( data ) {
236
+
237
+ var videoDuration = data.duration;
238
+ var videoPercentage = Math.floor( data.seconds / videoDuration * 100 );
239
+
240
+ if ( typeof gtm4wp_vimeo_percentage_tracking_marks[ videoid ] == "undefined" ) {
241
+ gtm4wp_vimeo_percentage_tracking_marks[ videoid ] = [];
242
+ }
243
+
244
+ for( var i=0; i<100; i+=gtm4wp_vimeo_percentage_tracking ) {
245
+ if ( ( videoPercentage > i ) && ( gtm4wp_vimeo_percentage_tracking_marks[ videoid ].indexOf( i ) == -1 ) ) {
246
+
247
+ gtm4wp_vimeo_percentage_tracking_marks[ videoid ].push( i );
248
+
249
+ window[ gtm4wp_datalayer_name ].push({
250
+ 'event': 'gtm4wp.mediaPlaybackPercentage',
251
+ 'mediaType': 'vimeo',
252
+ 'mediaData': {
253
+ 'id': videoid,
254
+ 'author': '',
255
+ 'title': jqframe.attr( "data-player_title" ),
256
+ 'url': jqframe.attr( "data-player_url" ),
257
+ 'duration': videoDuration
258
+ },
259
+ 'mediaCurrentTime': data.seconds,
260
+ 'mediaPercentage': i
261
+ });
262
+
263
+ }
264
+ }
265
+ };
266
+
267
+ });
268
+ });
js/gtm4wp-woocommerce-classic.js CHANGED
@@ -1,29 +1,29 @@
1
- jQuery(function() {
2
- jQuery( document ).on( 'click', '.add_to_cart_button:not(.product_type_variable, .product_type_grouped, .single_add_to_cart_button)', function() {
3
- var productdata = jQuery( this ).closest( '.product' ).find( '.gtm4wp_productdata' );
4
-
5
- window[ gtm4wp_datalayer_name ].push({
6
- 'event': 'gtm4wp.addProductToCart',
7
- 'productName': productdata.data( 'gtm4wp_product_name' ),
8
- 'productSKU': jQuery( this ).data( 'product_sku' ),
9
- 'productID': jQuery( this ).data( 'product_id' ),
10
- });
11
- });
12
-
13
- jQuery( document ).on( 'click', '.single_add_to_cart_button', function() {
14
- var _product_form = jQuery( this ).closest( 'form.cart' );
15
- var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
16
- var _product_name = jQuery( '[name=gtm4wp_name]', _product_form ).val();
17
- var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
18
- var _product_is_grouped = jQuery( _product_form ).hasClass( 'grouped_form' );
19
-
20
- if ( ! _product_is_grouped ) {
21
- window[ gtm4wp_datalayer_name ].push({
22
- 'event': 'gtm4wp.addProductToCart',
23
- 'productName': _product_name,
24
- 'productSKU': _product_sku,
25
- 'productID': _product_id
26
- });
27
- }
28
- });
29
- });
1
+ jQuery(function() {
2
+ jQuery( document ).on( 'click', '.add_to_cart_button:not(.product_type_variable, .product_type_grouped, .single_add_to_cart_button)', function() {
3
+ var productdata = jQuery( this ).closest( '.product' ).find( '.gtm4wp_productdata' );
4
+
5
+ window[ gtm4wp_datalayer_name ].push({
6
+ 'event': 'gtm4wp.addProductToCart',
7
+ 'productName': productdata.data( 'gtm4wp_product_name' ),
8
+ 'productSKU': jQuery( this ).data( 'product_sku' ),
9
+ 'productID': jQuery( this ).data( 'product_id' ),
10
+ });
11
+ });
12
+
13
+ jQuery( document ).on( 'click', '.single_add_to_cart_button', function() {
14
+ var _product_form = jQuery( this ).closest( 'form.cart' );
15
+ var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
16
+ var _product_name = jQuery( '[name=gtm4wp_name]', _product_form ).val();
17
+ var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
18
+ var _product_is_grouped = jQuery( _product_form ).hasClass( 'grouped_form' );
19
+
20
+ if ( ! _product_is_grouped ) {
21
+ window[ gtm4wp_datalayer_name ].push({
22
+ 'event': 'gtm4wp.addProductToCart',
23
+ 'productName': _product_name,
24
+ 'productSKU': _product_sku,
25
+ 'productID': _product_id
26
+ });
27
+ }
28
+ });
29
+ });
js/gtm4wp-woocommerce-enhanced.js CHANGED
@@ -1,6 +1,52 @@
1
  var gtm4wp_last_selected_product_variation;
2
  var gtm4wp_changedetail_fired_during_pageload=false;
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  function gtm4wp_handle_cart_qty_change() {
5
  jQuery( '.product-quantity input.qty' ).each(function() {
6
  var _original_value = jQuery( this ).prop( 'defaultValue' );
@@ -24,43 +70,69 @@ function gtm4wp_handle_cart_qty_change() {
24
  }
25
 
26
  if ( _original_value < _current_value ) {
 
 
 
 
 
 
 
 
 
 
 
 
27
  window[ gtm4wp_datalayer_name ].push({
28
  'event': 'gtm4wp.addProductToCartEEC',
29
  'ecommerce': {
30
  'currencyCode': gtm4wp_currency,
31
  'add': {
32
- 'products': [{
33
- 'name': productdata.data( 'gtm4wp_product_name' ),
34
- 'id': productdata.data( 'gtm4wp_product_id' ),
35
- 'price': productprice.toFixed(2),
36
- 'category': productdata.data( 'gtm4wp_product_cat' ),
37
- 'variant': productdata.data( 'gtm4wp_product_variant' ),
38
- 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
39
- 'brand': productdata.data( 'gtm4wp_product_brand' ),
40
- 'quantity': _current_value - _original_value
41
- }]
42
  }
43
  }
44
  });
 
 
 
 
 
 
 
 
 
 
45
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
46
  window[ gtm4wp_datalayer_name ].push({
47
  'event': 'gtm4wp.removeFromCartEEC',
48
  'ecommerce': {
49
  'currencyCode': gtm4wp_currency,
50
  'remove': {
51
- 'products': [{
52
- 'name': productdata.data( 'gtm4wp_product_name' ),
53
- 'id': productdata.data( 'gtm4wp_product_id' ),
54
- 'price': productprice.toFixed(2),
55
- 'category': productdata.data( 'gtm4wp_product_cat' ),
56
- 'variant': productdata.data( 'gtm4wp_product_variant' ),
57
- 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
58
- 'brand': productdata.data( 'gtm4wp_product_brand' ),
59
- 'quantity': _original_value - _current_value
60
- }]
61
  }
62
  }
63
  });
 
 
 
 
 
 
 
 
 
 
64
  }
65
  } // end if qty changed
66
  }); // end each qty field
@@ -73,7 +145,10 @@ jQuery(function() {
73
  // track impressions of products in product lists
74
  if ( jQuery( '.gtm4wp_productdata,.widget-product-item' ).length > 0 ) {
75
  var products = [];
 
76
  var productdata, productprice=0;
 
 
77
  jQuery( '.gtm4wp_productdata,.widget-product-item' ).each( function() {
78
  productdata = jQuery( this );
79
  productprice = productdata.data( 'gtm4wp_product_price' );
@@ -87,7 +162,7 @@ jQuery(function() {
87
  productprice = 0;
88
  }
89
 
90
- products.push({
91
  'name': productdata.data( 'gtm4wp_product_name' ),
92
  'id': productdata.data( 'gtm4wp_product_id' ),
93
  'price': productprice.toFixed(2),
@@ -96,16 +171,19 @@ jQuery(function() {
96
  'list': productdata.data( 'gtm4wp_productlist_name' ),
97
  'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
98
  'brand': productdata.data( 'gtm4wp_product_brand' )
99
- });
100
-
 
101
  });
102
 
103
  if ( gtm4wp_product_per_impression > 0 ) {
104
  // Need to split the product submissions up into chunks in order to avoid the GA 8kb submission limit
105
- var chunk;
106
  while ( products.length ) {
107
  chunk = products.splice( 0, gtm4wp_product_per_impression );
 
108
 
 
109
  window[ gtm4wp_datalayer_name ].push({
110
  'event': 'gtm4wp.productImpressionEEC',
111
  'ecommerce': {
@@ -113,6 +191,15 @@ jQuery(function() {
113
  'impressions': chunk
114
  }
115
  });
 
 
 
 
 
 
 
 
 
116
  }
117
  } else {
118
  for( var i=0; i<window[ gtm4wp_datalayer_name ].length; i++ ) {
@@ -136,7 +223,6 @@ jQuery(function() {
136
  }
137
 
138
  window[ gtm4wp_datalayer_name ][ i ][ 'ecommerce' ][ 'currencyCode' ] = gtm4wp_currency;
139
-
140
  }
141
  }
142
 
@@ -154,35 +240,49 @@ jQuery(function() {
154
  productprice = 0;
155
  }
156
 
 
 
 
 
 
 
 
 
 
 
 
157
  window[ gtm4wp_datalayer_name ].push({
158
  'event': 'gtm4wp.addProductToCartEEC',
159
  'ecommerce': {
160
  'currencyCode': gtm4wp_currency,
161
  'add': {
162
- 'products': [{
163
- 'name': productdata.data( 'gtm4wp_product_name' ),
164
- 'id': productdata.data( 'gtm4wp_product_id' ),
165
- 'price': productprice.toFixed(2),
166
- 'category': productdata.data( 'gtm4wp_product_cat' ),
167
- 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
168
- 'brand': productdata.data( 'gtm4wp_product_brand' ),
169
- 'quantity': 1
170
- }]
171
  }
172
  }
173
  });
 
 
 
 
 
 
 
 
 
 
174
  });
175
 
176
  // track add to cart events for products on product detail pages
177
  jQuery( document ).on( 'click', '.single_add_to_cart_button:not(.disabled)', function() {
178
- var _product_form = jQuery( this ).closest( 'form.cart' );
179
- var _product_var_id = jQuery( '[name=variation_id]', _product_form );
180
- var _product_is_grouped = jQuery( _product_form ).hasClass( 'grouped_form' );
181
 
182
- if ( _product_var_id.length > 0 ) {
183
  if ( gtm4wp_last_selected_product_variation ) {
184
- gtm4wp_last_selected_product_variation.quantity = jQuery( 'form.cart:first input[name=quantity]' ).val();
185
 
 
186
  window[ gtm4wp_datalayer_name ].push({
187
  'event': 'gtm4wp.addProductToCartEEC',
188
  'ecommerce': {
@@ -192,12 +292,24 @@ jQuery(function() {
192
  }
193
  }
194
  });
 
 
 
 
 
 
 
 
 
 
195
  }
196
- } else if ( _product_is_grouped ) {
197
- var _products_in_group = jQuery( '.grouped_form .gtm4wp_productdata' );
198
- var _products_eec = [];
 
 
199
 
200
- _products_in_group.each( function() {
201
  var productdata = jQuery( this );
202
 
203
  var product_qty_input = jQuery( 'input[name=quantity\\[' + productdata.data( 'gtm4wp_product_id' ) + '\\]]' );
@@ -211,7 +323,7 @@ jQuery(function() {
211
  return;
212
  }
213
 
214
- _products_eec.push({
215
  'id': gtm4wp_use_sku_instead ? productdata.data( 'gtm4wp_product_sku' ) : productdata.data( 'gtm4wp_product_id' ),
216
  'name': productdata.data( 'gtm4wp_product_name' ),
217
  'price': productdata.data( 'gtm4wp_product_price' ),
@@ -219,40 +331,68 @@ jQuery(function() {
219
  'quantity': product_qty,
220
  'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
221
  'brand': productdata.data( 'gtm4wp_product_brand' )
222
- });
 
 
 
 
223
  });
224
 
225
- if ( 0 == _products_eec.length ) {
226
  return;
227
  }
228
 
 
229
  window[ gtm4wp_datalayer_name ].push({
230
  'event': 'gtm4wp.addProductToCartEEC',
231
  'ecommerce': {
232
  'currencyCode': gtm4wp_currency,
233
  'add': {
234
- 'products': _products_eec
235
  }
236
  }
237
  });
 
 
 
 
 
 
 
 
 
 
238
  } else {
 
 
 
 
 
 
 
 
 
 
 
239
  window[ gtm4wp_datalayer_name ].push({
240
  'event': 'gtm4wp.addProductToCartEEC',
241
  'ecommerce': {
242
  'currencyCode': gtm4wp_currency,
243
  'add': {
244
- 'products': [{
245
- 'id': gtm4wp_use_sku_instead ? jQuery( '[name=gtm4wp_sku]', _product_form ).val() : jQuery( '[name=gtm4wp_id]', _product_form ).val(),
246
- 'name': jQuery( '[name=gtm4wp_name]', _product_form ).val(),
247
- 'price': jQuery( '[name=gtm4wp_price]', _product_form ).val(),
248
- 'category': jQuery( '[name=gtm4wp_category]', _product_form ).val(),
249
- 'quantity': jQuery( 'form.cart:first input[name=quantity]' ).val(),
250
- 'stocklevel': jQuery( '[name=gtm4wp_stocklevel]', _product_form ).val(),
251
- 'brand': jQuery( '[name=gtm4wp_brand]', _product_form ).val()
252
- }]
253
  }
254
  }
255
  });
 
 
 
 
 
 
 
 
 
 
256
  }
257
  });
258
 
@@ -279,23 +419,37 @@ jQuery(function() {
279
  return true;
280
  }
281
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  window[ gtm4wp_datalayer_name ].push({
283
  'event': 'gtm4wp.removeFromCartEEC',
284
  'ecommerce': {
 
285
  'remove': {
286
- 'products': [{
287
- 'name': productdata.data( 'gtm4wp_product_name' ),
288
- 'id': productdata.data( 'gtm4wp_product_id' ),
289
- 'price': productdata.data( 'gtm4wp_product_price' ),
290
- 'category': productdata.data( 'gtm4wp_product_cat' ),
291
- 'variant': productdata.data( 'gtm4wp_product_variant' ),
292
- 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
293
- 'brand': productdata.data( 'gtm4wp_product_brand' ),
294
- 'quantity': qty
295
- }]
296
  }
297
  }
298
  });
 
 
 
 
 
 
 
 
 
 
299
  });
300
 
301
  // track clicks in product lists
@@ -305,42 +459,42 @@ jQuery(function() {
305
  return true;
306
  }
307
 
308
- var _productdata = jQuery( this ).closest( '.product' );
309
- var productdata = '';
310
 
311
- if ( _productdata.length > 0 ) {
312
- productdata = _productdata.find( '.gtm4wp_productdata' );
313
 
314
  } else {
315
- _productdata = jQuery( this ).closest( '.products li' );
316
 
317
- if ( _productdata.length > 0 ) {
318
- productdata = _productdata.find( '.gtm4wp_productdata' );
319
 
320
  } else {
321
- _productdata = jQuery( this ).closest( '.products>div' );
322
 
323
- if ( _productdata.length > 0 ) {
324
- productdata = _productdata.find( '.gtm4wp_productdata' );
325
 
326
  } else {
327
- _productdata = jQuery( this ).closest( '.woocommerce-grouped-product-list-item__label' );
328
 
329
- if ( _productdata.length > 0 ) {
330
- productdata = _productdata.find( '.gtm4wp_productdata' );
331
  } else {
332
- productdata = jQuery( this );
333
  }
334
  }
335
  }
336
  }
337
 
338
- if ( ( 'undefined' == typeof productdata.data( 'gtm4wp_product_id' ) ) || ( '' == productdata.data( 'gtm4wp_product_id' ) ) ) {
339
  return true;
340
  }
341
 
342
  // only act on links pointing to the product detail page
343
- if ( productdata.data( 'gtm4wp_product_url' ) != jQuery( this ).attr( 'href' ) ) {
344
  return true;
345
  }
346
 
@@ -349,32 +503,50 @@ jQuery(function() {
349
  event.preventDefault();
350
  if ( ctrl_key_pressed ) {
351
  // we need to open the new tab/page here so that popup blocker of the browser doesn't block our code
352
- var _productpage = window.open( 'about:blank', '_blank' );
353
  }
354
 
 
 
 
 
 
 
 
 
 
 
 
355
  window[ gtm4wp_datalayer_name ].push({
356
  'event': 'gtm4wp.productClickEEC',
357
  'ecommerce': {
358
  'currencyCode': gtm4wp_currency,
359
  'click': {
360
- 'actionField': {'list': productdata.data( 'gtm4wp_productlist_name' )},
361
- 'products': [{
362
- 'id': productdata.data( 'gtm4wp_product_id' ),
363
- 'name': productdata.data( 'gtm4wp_product_name' ),
364
- 'price': productdata.data( 'gtm4wp_product_price' ),
365
- 'category': productdata.data( 'gtm4wp_product_cat' ),
366
- 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
367
- 'brand': productdata.data( 'gtm4wp_product_brand' ),
368
- 'position': productdata.data( 'gtm4wp_product_listposition' )
369
- }]
370
  }
371
  },
372
  'eventCallback': function() {
373
- if ( ctrl_key_pressed && _productpage ) {
374
- _productpage.location.href= productdata.data( 'gtm4wp_product_url' );
375
- } else {
376
- document.location.href = productdata.data( 'gtm4wp_product_url' );
377
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  },
379
  'eventTimeout': 2000
380
  });
@@ -392,23 +564,23 @@ jQuery(function() {
392
  return;
393
  }
394
 
395
- var _product_form = event.target;
396
- var _product_var_id = jQuery( '[name=variation_id]', _product_form );
397
- var _product_id = jQuery( '[name=gtm4wp_id]', _product_form ).val();
398
- var _product_name = jQuery( '[name=gtm4wp_name]', _product_form ).val();
399
- var _product_sku = jQuery( '[name=gtm4wp_sku]', _product_form ).val();
400
- var _product_category = jQuery( '[name=gtm4wp_category]', _product_form ).val();
401
- var _product_price = jQuery( '[name=gtm4wp_price]', _product_form ).val();
402
- var _product_stocklevel = jQuery( '[name=gtm4wp_stocklevel]', _product_form ).val();
403
- var _product_brand = jQuery( '[name=gtm4wp_brand]', _product_form ).val();
404
-
405
- var current_product_detail_data = {
406
- name: _product_name,
407
  id: 0,
408
  price: 0,
409
- category: _product_category,
410
- stocklevel: _product_stocklevel,
411
- brand: _product_brand,
412
  variant: ''
413
  };
414
 
@@ -425,19 +597,29 @@ jQuery(function() {
425
  current_product_detail_data.variant = _tmp.join(',');
426
  gtm4wp_last_selected_product_variation = current_product_detail_data;
427
 
 
428
  window[ gtm4wp_datalayer_name ].push({
429
  'event': 'gtm4wp.changeDetailViewEEC',
430
  'ecommerce': {
431
  'currencyCode': gtm4wp_currency,
432
  'detail': {
433
- 'products': [current_product_detail_data]
434
- },
435
  },
436
  'ecomm_prodid': gtm4wp_id_prefix + current_product_detail_data.id,
437
  'ecomm_pagetype': 'product',
438
  'ecomm_totalvalue': current_product_detail_data.price,
439
  });
440
 
 
 
 
 
 
 
 
 
 
441
  if ( document.readyState === "interactive" ) {
442
  gtm4wp_changedetail_fired_during_pageload = true;
443
  }
@@ -470,11 +652,15 @@ jQuery(function() {
470
 
471
  // codes for enhanced ecommerce events on checkout page
472
  if ( is_checkout ) {
473
- window.gtm4wp_checkout_step_offset = window.gtm4wp_checkout_step_offset || 0;
474
- window.gtm4wp_checkout_products = window.gtm4wp_checkout_products || [];
 
 
 
475
  var gtm4wp_shipping_payment_method_step_offset = window.gtm4wp_needs_shipping_address ? 0 : -1;
476
- var gtm4wp_checkout_step_fired = []; // step 1 will be the billing section which is reported during pageload, no need to handle here
477
 
 
478
  jQuery( document ).on( 'blur', 'input[name^=shipping_]:not(input[name^=shipping_method])', function() {
479
  // do not report checkout step if already reported
480
  if ( gtm4wp_checkout_step_fired.indexOf( 'shipping' ) > -1 ) {
@@ -489,6 +675,7 @@ jQuery(function() {
489
  window[ gtm4wp_datalayer_name ].push({
490
  'event': 'gtm4wp.checkoutStepEEC',
491
  'ecommerce': {
 
492
  'checkout': {
493
  'actionField': {
494
  'step': 2 + window.gtm4wp_checkout_step_offset
@@ -512,9 +699,20 @@ jQuery(function() {
512
  return;
513
  }
514
 
 
 
 
 
 
 
 
 
 
 
515
  window[ gtm4wp_datalayer_name ].push({
516
  'event': 'gtm4wp.checkoutStepEEC',
517
  'ecommerce': {
 
518
  'checkout': {
519
  'actionField': {
520
  'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset
@@ -524,6 +722,17 @@ jQuery(function() {
524
  }
525
  });
526
 
 
 
 
 
 
 
 
 
 
 
 
527
  gtm4wp_checkout_step_fired.push( 'shipping_method' );
528
  });
529
 
@@ -538,9 +747,20 @@ jQuery(function() {
538
  return;
539
  }
540
 
 
 
 
 
 
 
 
 
 
 
541
  window[ gtm4wp_datalayer_name ].push({
542
  'event': 'gtm4wp.checkoutStepEEC',
543
  'ecommerce': {
 
544
  'checkout': {
545
  'actionField': {
546
  'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset
@@ -550,6 +770,17 @@ jQuery(function() {
550
  }
551
  });
552
 
 
 
 
 
 
 
 
 
 
 
 
553
  gtm4wp_checkout_step_fired.push( 'payment_method' );
554
  });
555
 
@@ -571,33 +802,36 @@ jQuery(function() {
571
  jQuery( 'input[name=payment_method]:checked' ).trigger( 'change' );
572
  }
573
 
574
- var _shipping_el = jQuery( 'input[name^=shipping_method]:checked' );
575
- if ( _shipping_el.length == 0 ) {
576
- _shipping_el = jQuery( 'input[name^=shipping_method]:first' );
577
  }
578
- if ( _shipping_el.length > 0 ) {
579
  window[ gtm4wp_datalayer_name ].push({
580
  'event': 'gtm4wp.checkoutOptionEEC',
581
  'ecommerce': {
582
  'checkout_option': {
583
  'actionField': {
584
  'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset,
585
- 'option': 'Shipping: ' + _shipping_el.val()
586
  }
587
  }
588
  }
589
  });
590
  }
591
 
592
- var _payment_el = jQuery( '.payment_methods input:checked' );
593
- if ( _payment_el.length > 0 ) {
 
 
 
594
  window[ gtm4wp_datalayer_name ].push({
595
  'event': 'gtm4wp.checkoutOptionEEC',
596
  'ecommerce': {
597
  'checkout_option': {
598
  'actionField': {
599
  'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset,
600
- 'option': 'Payment: ' + _payment_el.val()
601
  }
602
  }
603
  }
@@ -621,16 +855,110 @@ jQuery(function() {
621
  window[ gtm4wp_datalayer_name ][ i ][ 'ecomm_prodid' ] = [];
622
  }
623
 
624
- if ( 'undefined' == typeof window[ gtm4wp_datalayer_name ][ i ][ 'ecomm_prodid' ].push ) {
625
- return false;
 
 
 
 
 
626
  }
 
 
627
 
628
- var productdata;
629
- jQuery( '.gtm4wp_productdata' ).each( function() {
630
- productdata = jQuery( this );
631
 
632
- window[ gtm4wp_datalayer_name ][ i ][ 'ecomm_prodid' ].push( gtm4wp_id_prefix + productdata.data( 'gtm4wp_product_id' ) );
633
- });
634
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
635
  }
636
  });
1
  var gtm4wp_last_selected_product_variation;
2
  var gtm4wp_changedetail_fired_during_pageload=false;
3
 
4
+ function gtm4wp_map_eec_to_ga4( productdata ) {
5
+ if (!productdata) {
6
+ return;
7
+ }
8
+
9
+ var category_path = productdata.category ? productdata.category : '';
10
+ var category_parts = category_path.split('/');
11
+
12
+ // default, required parameters
13
+ var ga4_product = {
14
+ 'item_id': productdata.id ? productdata.id : '',
15
+ 'item_name': productdata.name ? productdata.name : '',
16
+ 'item_brand': productdata.brand ? productdata.brand : '',
17
+ 'price': productdata.price ? productdata.price : ""
18
+ };
19
+
20
+ // category, also handle category path
21
+ if ( 1 == category_parts.length ) {
22
+ ga4_product.item_category = category_parts[0];
23
+ } else if ( category_parts.length > 1 ) {
24
+ ga4_product.item_category = category_parts[0];
25
+ for( var i=1; i < Math.min( 5, category_parts.length ); i++ ) {
26
+ ga4_product[ 'item_category_' + (i+1) ] = category_parts[i];
27
+ }
28
+ }
29
+
30
+ // optional parameters which should not be included in the array if not set
31
+ if ( productdata.variant ) {
32
+ ga4_product.item_variant = productdata.variant;
33
+ }
34
+ if ( productdata.list ) {
35
+ ga4_product.item_list_name = productdata.list;
36
+ }
37
+ if ( productdata.position ) {
38
+ ga4_product.index = productdata.position;
39
+ }
40
+ if ( productdata.quantity ) {
41
+ ga4_product.quantity = productdata.quantity;
42
+ }
43
+ if ( productdata.coupon ) {
44
+ ga4_product.coupon = productdata.coupon;
45
+ }
46
+
47
+ return ga4_product;
48
+ }
49
+
50
  function gtm4wp_handle_cart_qty_change() {
51
  jQuery( '.product-quantity input.qty' ).each(function() {
52
  var _original_value = jQuery( this ).prop( 'defaultValue' );
70
  }
71
 
72
  if ( _original_value < _current_value ) {
73
+ var product_data = {
74
+ 'name': productdata.data( 'gtm4wp_product_name' ),
75
+ 'id': productdata.data( 'gtm4wp_product_id' ),
76
+ 'price': productprice.toFixed(2),
77
+ 'category': productdata.data( 'gtm4wp_product_cat' ),
78
+ 'variant': productdata.data( 'gtm4wp_product_variant' ),
79
+ 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
80
+ 'brand': productdata.data( 'gtm4wp_product_brand' ),
81
+ 'quantity': _current_value - _original_value
82
+ };
83
+
84
+ // fire ga3 version
85
  window[ gtm4wp_datalayer_name ].push({
86
  'event': 'gtm4wp.addProductToCartEEC',
87
  'ecommerce': {
88
  'currencyCode': gtm4wp_currency,
89
  'add': {
90
+ 'products': [ product_data ]
 
 
 
 
 
 
 
 
 
91
  }
92
  }
93
  });
94
+
95
+ // fire ga4 version
96
+ window[ gtm4wp_datalayer_name ].push({
97
+ 'event': 'add_to_cart',
98
+ 'ecommerce': {
99
+ 'currency': gtm4wp_currency, // ga4 version
100
+ 'value': productprice.toFixed(2) * (_current_value - _original_value),
101
+ 'items': [ gtm4wp_map_eec_to_ga4( product_data ) ]
102
+ }
103
+ });
104
  } else {
105
+ var product_data = {
106
+ 'name': productdata.data( 'gtm4wp_product_name' ),
107
+ 'id': productdata.data( 'gtm4wp_product_id' ),
108
+ 'price': productprice.toFixed(2),
109
+ 'category': productdata.data( 'gtm4wp_product_cat' ),
110
+ 'variant': productdata.data( 'gtm4wp_product_variant' ),
111
+ 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
112
+ 'brand': productdata.data( 'gtm4wp_product_brand' ),
113
+ 'quantity': _original_value - _current_value
114
+ };
115
+
116
+ // fire ga3 version
117
  window[ gtm4wp_datalayer_name ].push({
118
  'event': 'gtm4wp.removeFromCartEEC',
119
  'ecommerce': {
120
  'currencyCode': gtm4wp_currency,
121
  'remove': {
122
+ 'products': [ product_data ]
 
 
 
 
 
 
 
 
 
123
  }
124
  }
125
  });
126
+
127
+ // fire ga4 version
128
+ window[ gtm4wp_datalayer_name ].push({
129
+ 'event': 'remove_from_cart',
130
+ 'ecommerce': {
131
+ 'currency': gtm4wp_currency,
132
+ 'value': productprice.toFixed(2) * (_original_value - _current_value),
133
+ 'items': [ gtm4wp_map_eec_to_ga4( product_data ) ]
134
+ }
135
+ });
136
  }
137
  } // end if qty changed
138
  }); // end each qty field
145
  // track impressions of products in product lists
146
  if ( jQuery( '.gtm4wp_productdata,.widget-product-item' ).length > 0 ) {
147
  var products = [];
148
+ var ga4_products = [];
149
  var productdata, productprice=0;
150
+ var product_data;
151
+
152
  jQuery( '.gtm4wp_productdata,.widget-product-item' ).each( function() {
153
  productdata = jQuery( this );
154
  productprice = productdata.data( 'gtm4wp_product_price' );
162
  productprice = 0;
163
  }
164
 
165
+ product_data = {
166
  'name': productdata.data( 'gtm4wp_product_name' ),
167
  'id': productdata.data( 'gtm4wp_product_id' ),
168
  'price': productprice.toFixed(2),
171
  'list': productdata.data( 'gtm4wp_productlist_name' ),
172
  'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
173
  'brand': productdata.data( 'gtm4wp_product_brand' )
174
+ };
175
+ products.push(product_data);
176
+ ga4_products.push( gtm4wp_map_eec_to_ga4( product_data ) );
177
  });
178
 
179
  if ( gtm4wp_product_per_impression > 0 ) {
180
  // Need to split the product submissions up into chunks in order to avoid the GA 8kb submission limit
181
+ var chunk, ga4_chunk;
182
  while ( products.length ) {
183
  chunk = products.splice( 0, gtm4wp_product_per_impression );
184
+ ga4_chunk = ga4_products.splice( 0, gtm4wp_product_per_impression );
185
 
186
+ // fire ga3 version
187
  window[ gtm4wp_datalayer_name ].push({
188
  'event': 'gtm4wp.productImpressionEEC',
189
  'ecommerce': {
191
  'impressions': chunk
192
  }
193
  });
194
+
195
+ // fire ga4 version
196
+ window[ gtm4wp_datalayer_name ].push({
197
+ 'event': 'view_item_list',
198
+ 'ecommerce': {
199
+ 'currency': gtm4wp_currency,
200
+ 'items': ga4_chunk
201
+ }
202
+ });
203
  }
204
  } else {
205
  for( var i=0; i<window[ gtm4wp_datalayer_name ].length; i++ ) {
223
  }
224
 
225
  window[ gtm4wp_datalayer_name ][ i ][ 'ecommerce' ][ 'currencyCode' ] = gtm4wp_currency;
 
226
  }
227
  }
228
 
240
  productprice = 0;
241
  }
242
 
243
+ var product_data = {
244
+ 'name': productdata.data( 'gtm4wp_product_name' ),
245
+ 'id': productdata.data( 'gtm4wp_product_id' ),
246
+ 'price': productprice.toFixed(2),
247
+ 'category': productdata.data( 'gtm4wp_product_cat' ),
248
+ 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
249
+ 'brand': productdata.data( 'gtm4wp_product_brand' ),
250
+ 'quantity': 1
251
+ };
252
+
253
+ // fire ga3 version
254
  window[ gtm4wp_datalayer_name ].push({
255
  'event': 'gtm4wp.addProductToCartEEC',
256
  'ecommerce': {
257
  'currencyCode': gtm4wp_currency,
258
  'add': {
259
+ 'products': [ product_data ]
 
 
 
 
 
 
 
 
260
  }
261
  }
262
  });
263
+
264
+ // fire ga4 version
265
+ window[ gtm4wp_datalayer_name ].push({
266
+ 'event': 'add_to_cart',
267
+ 'ecommerce': {
268
+ 'currency': gtm4wp_currency,
269
+ 'value': productprice.toFixed(2),
270
+ 'items': [ gtm4wp_map_eec_to_ga4( product_data ) ]
271
+ }
272
+ });
273
  });
274
 
275
  // track add to cart events for products on product detail pages
276
  jQuery( document ).on( 'click', '.single_add_to_cart_button:not(.disabled)', function() {
277
+ var product_form = jQuery( this ).closest( 'form.cart' );
278
+ var product_variant_id = jQuery( '[name=variation_id]', product_form );
279
+ var product_is_grouped = jQuery( product_form ).hasClass( 'grouped_form' );
280
 
281
+ if ( product_variant_id.length > 0 ) {
282
  if ( gtm4wp_last_selected_product_variation ) {
283
+ gtm4wp_last_selected_product_variation.quantity = jQuery( '[name=quantity]', product_form ).val();
284
 
285
+ // fire ga3 version
286
  window[ gtm4wp_datalayer_name ].push({
287
  'event': 'gtm4wp.addProductToCartEEC',
288
  'ecommerce': {
292
  }
293
  }
294
  });
295
+
296
+ // fire ga4 version
297
+ window[ gtm4wp_datalayer_name ].push({
298
+ 'event': 'add_to_cart',
299
+ 'ecommerce': {
300
+ 'currency': gtm4wp_currency,
301
+ 'value': gtm4wp_last_selected_product_variation.price * gtm4wp_last_selected_product_variation.quantity,
302
+ 'items': [ gtm4wp_map_eec_to_ga4( gtm4wp_last_selected_product_variation ) ]
303
+ }
304
+ });
305
  }
306
+ } else if ( product_is_grouped ) {
307
+ var products_in_group = jQuery( '.grouped_form .gtm4wp_productdata' );
308
+ var products = [];
309
+ var ga4_products = [];
310
+ var sum_value = 0;
311
 
312
+ products_in_group.each( function() {
313
  var productdata = jQuery( this );
314
 
315
  var product_qty_input = jQuery( 'input[name=quantity\\[' + productdata.data( 'gtm4wp_product_id' ) + '\\]]' );
323
  return;
324
  }
325
 
326
+ var product_data = {
327
  'id': gtm4wp_use_sku_instead ? productdata.data( 'gtm4wp_product_sku' ) : productdata.data( 'gtm4wp_product_id' ),
328
  'name': productdata.data( 'gtm4wp_product_name' ),
329
  'price': productdata.data( 'gtm4wp_product_price' ),
331
  'quantity': product_qty,
332
  'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
333
  'brand': productdata.data( 'gtm4wp_product_brand' )
334
+ };
335
+
336
+ products.push( product_data );
337
+ ga4_products.push( gtm4wp_map_eec_to_ga4( product_data ) );
338
+ sum_value += product_data.price * product_data.quantity;
339
  });
340
 
341
+ if ( 0 == products.length ) {
342
  return;
343
  }
344
 
345
+ // fire ga3 version
346
  window[ gtm4wp_datalayer_name ].push({
347
  'event': 'gtm4wp.addProductToCartEEC',
348
  'ecommerce': {
349
  'currencyCode': gtm4wp_currency,
350
  'add': {
351
+ 'products': products
352
  }
353
  }
354
  });
355
+
356
+ // fire ga4 version
357
+ window[ gtm4wp_datalayer_name ].push({
358
+ 'event': 'add_to_cart',
359
+ 'ecommerce': {
360
+ 'currency': gtm4wp_currency,
361
+ 'value': sum_value,
362
+ 'items': ga4_products
363
+ }
364
+ });
365
  } else {
366
+ var product_data = {
367
+ 'id': gtm4wp_use_sku_instead ? jQuery( '[name=gtm4wp_sku]', product_form ).val() : jQuery( '[name=gtm4wp_id]', product_form ).val(),
368
+ 'name': jQuery( '[name=gtm4wp_name]', product_form ).val(),
369
+ 'price': jQuery( '[name=gtm4wp_price]', product_form ).val(),
370
+ 'category': jQuery( '[name=gtm4wp_category]', product_form ).val(),
371
+ 'quantity': jQuery( '[name=quantity]', product_form ).val(),
372
+ 'stocklevel': jQuery( '[name=gtm4wp_stocklevel]', product_form ).val(),
373
+ 'brand': jQuery( '[name=gtm4wp_brand]', product_form ).val()
374
+ };
375
+
376
+ // fire ga3 version
377
  window[ gtm4wp_datalayer_name ].push({
378
  'event': 'gtm4wp.addProductToCartEEC',
379
  'ecommerce': {
380
  'currencyCode': gtm4wp_currency,
381
  'add': {
382
+ 'products': [ product_data ]
 
 
 
 
 
 
 
 
383
  }
384
  }
385
  });
386
+
387
+ // fire ga4 version
388
+ window[ gtm4wp_datalayer_name ].push({
389
+ 'event': 'add_to_cart',
390
+ 'ecommerce': {
391
+ 'currency': gtm4wp_currency,
392
+ 'value': product_data.price * product_data.quantity,
393
+ 'items': [ gtm4wp_map_eec_to_ga4( product_data ) ]
394
+ }
395
+ });
396
  }
397
  });
398
 
419
  return true;
420
  }
421
 
422
+ var product_data = {
423
+ 'name': productdata.data( 'gtm4wp_product_name' ),
424
+ 'id': productdata.data( 'gtm4wp_product_id' ),
425
+ 'price': productdata.data( 'gtm4wp_product_price' ),
426
+ 'category': productdata.data( 'gtm4wp_product_cat' ),
427
+ 'variant': productdata.data( 'gtm4wp_product_variant' ),
428
+ 'stocklevel': productdata.data( 'gtm4wp_product_stocklevel' ),
429
+ 'brand': productdata.data( 'gtm4wp_product_brand' ),
430
+ 'quantity': qty
431
+ };
432
+
433
+ // fire ga3 version
434
  window[ gtm4wp_datalayer_name ].push({
435
  'event': 'gtm4wp.removeFromCartEEC',
436
  'ecommerce': {
437
+ 'currencyCode': gtm4wp_currency,
438
  'remove': {
439
+ 'products': [ product_data ]
 
 
 
 
 
 
 
 
 
440
  }
441
  }
442
  });
443
+
444
+ // fire ga4 version
445
+ window[ gtm4wp_datalayer_name ].push({
446
+ 'event': 'remove_from_cart',
447
+ 'ecommerce': {
448
+ 'currency': gtm4wp_currency,
449
+ 'value': product_data.price * product_data.quantity,
450
+ 'items': [ gtm4wp_map_eec_to_ga4( product_data ) ]
451
+ }
452
+ });
453
  });
454
 
455
  // track clicks in product lists
459
  return true;
460
  }
461
 
462
+ var temp_selector = jQuery( this ).closest( '.product' );
463
+ var dom_productdata = '';
464
 
465
+ if ( temp_selector.length > 0 ) {
466
+ dom_productdata = temp_selector.find( '.gtm4wp_productdata' );
467
 
468
  } else {
469
+ temp_selector = jQuery( this ).closest( '.products li' );
470
 
471
+ if ( temp_selector.length > 0 ) {
472
+ dom_productdata = temp_selector.find( '.gtm4wp_productdata' );
473
 
474
  } else {
475
+ temp_selector = jQuery( this ).closest( '.products>div' );
476
 
477
+ if ( temp_selector.length > 0 ) {
478
+ dom_productdata = temp_selector.find( '.gtm4wp_productdata' );
479
 
480
  } else {
481
+ temp_selector = jQuery( this ).closest( '.woocommerce-grouped-product-list-item__label' );
482
 
483
+ if ( temp_selector.length > 0 ) {
484
+ dom_productdata = temp_selector.find( '.gtm4wp_productdata' );
485
  } else {
486
+ dom_productdata = jQuery( this );
487
  }
488
  }
489
  }
490
  }
491
 
492
+ if ( ( 'undefined' == typeof dom_productdata.data( 'gtm4wp_product_id' ) ) || ( '' == dom_productdata.data( 'gtm4wp_product_id' ) ) ) {
493
  return true;
494
  }
495
 
496
  // only act on links pointing to the product detail page
497
+ if ( dom_productdata.data( 'gtm4wp_product_url' ) != jQuery( this ).attr( 'href' ) ) {
498
  return true;
499
  }
500
 
503
  event.preventDefault();
504
  if ( ctrl_key_pressed ) {
505
  // we need to open the new tab/page here so that popup blocker of the browser doesn't block our code
506
+ var productpage_window = window.open( 'about:blank', '_blank' );
507
  }
508
 
509
+ var product_data = {
510
+ 'id': dom_productdata.data( 'gtm4wp_product_id' ),
511
+ 'name': dom_productdata.data( 'gtm4wp_product_name' ),
512
+ 'price': dom_productdata.data( 'gtm4wp_product_price' ),
513
+ 'category': dom_productdata.data( 'gtm4wp_product_cat' ),
514
+ 'stocklevel': dom_productdata.data( 'gtm4wp_product_stocklevel' ),
515
+ 'brand': dom_productdata.data( 'gtm4wp_product_brand' ),
516
+ 'position': dom_productdata.data( 'gtm4wp_product_listposition' )
517
+ };
518
+
519
+ // fire ga3 version
520
  window[ gtm4wp_datalayer_name ].push({
521
  'event': 'gtm4wp.productClickEEC',
522
  'ecommerce': {
523
  'currencyCode': gtm4wp_currency,
524
  'click': {
525
+ 'actionField': {'list': dom_productdata.data( 'gtm4wp_productlist_name' )},
526
+ 'products': [ product_data ]
 
 
 
 
 
 
 
 
527
  }
528
  },
529
  'eventCallback': function() {
530
+
531
+ // fire ga4 version
532
+ window[ gtm4wp_datalayer_name ].push({
533
+ 'event': 'select_item',
534
+ 'ecommerce': {
535
+ 'currency': gtm4wp_currency,
536
+ 'items': [ gtm4wp_map_eec_to_ga4( product_data ) ]
537
+ },
538
+ 'eventCallback': function() {
539
+
540
+ if ( ctrl_key_pressed && productpage_window ) {
541
+ productpage_window.location.href= dom_productdata.data( 'gtm4wp_product_url' );
542
+ } else {
543
+ document.location.href = dom_productdata.data( 'gtm4wp_product_url' );
544
+ }
545
+
546
+ },
547
+ 'eventTimeout': 2000
548
+ });
549
+
550
  },
551
  'eventTimeout': 2000
552
  });
564
  return;
565
  }
566
 
567
+ var product_form = event.target;
568
+ var product_variant_id = jQuery( '[name=variation_id]', product_form );
569
+ var product_id = jQuery( '[name=gtm4wp_id]', product_form ).val();
570
+ var product_name = jQuery( '[name=gtm4wp_name]', product_form ).val();
571
+ var product_sku = jQuery( '[name=gtm4wp_sku]', product_form ).val();
572
+ var product_category = jQuery( '[name=gtm4wp_category]', product_form ).val();
573
+ var product_price = jQuery( '[name=gtm4wp_price]', product_form ).val();
574
+ var product_stocklevel = jQuery( '[name=gtm4wp_stocklevel]', product_form ).val();
575
+ var product_brand = jQuery( '[name=gtm4wp_brand]', product_form ).val();
576
+
577
+ var current_product_detail_data = {
578
+ name: product_name,
579
  id: 0,
580
  price: 0,
581
+ category: product_category,
582
+ stocklevel: product_stocklevel,
583
+ brand: product_brand,
584
  variant: ''
585
  };
586
 
597
  current_product_detail_data.variant = _tmp.join(',');
598
  gtm4wp_last_selected_product_variation = current_product_detail_data;
599
 
600
+ // fire ga3 version
601
  window[ gtm4wp_datalayer_name ].push({
602
  'event': 'gtm4wp.changeDetailViewEEC',
603
  'ecommerce': {
604
  'currencyCode': gtm4wp_currency,
605
  'detail': {
606
+ 'products': [ current_product_detail_data ]
607
+ }
608
  },
609
  'ecomm_prodid': gtm4wp_id_prefix + current_product_detail_data.id,
610
  'ecomm_pagetype': 'product',
611
  'ecomm_totalvalue': current_product_detail_data.price,
612
  });
613
 
614
+ // fire ga4 version
615
+ window[ gtm4wp_datalayer_name ].push({
616
+ 'event': 'view_item',
617
+ 'ecommerce': {
618
+ 'currency': gtm4wp_currency,
619
+ 'items': [ gtm4wp_map_eec_to_ga4( current_product_detail_data ) ]
620
+ }
621
+ });
622
+
623
  if ( document.readyState === "interactive" ) {
624
  gtm4wp_changedetail_fired_during_pageload = true;
625
  }
652
 
653
  // codes for enhanced ecommerce events on checkout page
654
  if ( is_checkout ) {
655
+ window.gtm4wp_checkout_step_offset = window.gtm4wp_checkout_step_offset || 0;
656
+ window.gtm4wp_checkout_value = window.gtm4wp_checkout_value || 0;
657
+ window.gtm4wp_checkout_products = window.gtm4wp_checkout_products || [];
658
+ window.gtm4wp_checkout_products_ga4 = window.gtm4wp_checkout_products_ga4 || [];
659
+
660
  var gtm4wp_shipping_payment_method_step_offset = window.gtm4wp_needs_shipping_address ? 0 : -1;
661
+ var gtm4wp_checkout_step_fired = []; // step 1 will be the billing section which is reported during pageload, no need to handle here
662
 
663
+ // this checkout step is not reported to GA4 as currently there is no option to report in-between custom steps
664
  jQuery( document ).on( 'blur', 'input[name^=shipping_]:not(input[name^=shipping_method])', function() {
665
  // do not report checkout step if already reported
666
  if ( gtm4wp_checkout_step_fired.indexOf( 'shipping' ) > -1 ) {
675
  window[ gtm4wp_datalayer_name ].push({
676
  'event': 'gtm4wp.checkoutStepEEC',
677
  'ecommerce': {
678
+ 'currencyCode': gtm4wp_currency, // ga3 version
679
  'checkout': {
680
  'actionField': {
681
  'step': 2 + window.gtm4wp_checkout_step_offset
699
  return;
700
  }
701
 
702
+ var shipping_tier = '(shipping tier not found)';
703
+ var shipping_el = jQuery( 'input[name^=shipping_method]:checked' );
704
+ if ( shipping_el.length == 0 ) {
705
+ shipping_el = jQuery( 'input[name^=shipping_method]:first' );
706
+ }
707
+ if ( shipping_el.length > 0 ) {
708
+ shipping_tier = shipping_el.val();
709
+ }
710
+
711
+ // fire ga3 version
712
  window[ gtm4wp_datalayer_name ].push({
713
  'event': 'gtm4wp.checkoutStepEEC',
714
  'ecommerce': {
715
+ 'currencyCode': gtm4wp_currency,
716
  'checkout': {
717
  'actionField': {
718
  'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset
722
  }
723
  });
724
 
725
+ // fire ga4 version
726
+ window[ gtm4wp_datalayer_name ].push({
727
+ 'event': 'add_shipping_info',
728
+ 'ecommerce': {
729
+ 'currency': gtm4wp_currency,
730
+ 'shipping_tier': shipping_tier,
731
+ 'value': window.gtm4wp_checkout_value,
732
+ 'items': window.gtm4wp_checkout_products_ga4
733
+ }
734
+ });
735
+
736
  gtm4wp_checkout_step_fired.push( 'shipping_method' );
737
  });
738
 
747
  return;
748
  }
749
 
750
+ var payment_type = '(payment type not found)';
751
+ var payment_el = jQuery( '.payment_methods input:checked' );
752
+ if ( payment_el.length == 0 ) {
753
+ payment_el = jQuery( 'input[name^=payment_method]:first' );
754
+ }
755
+ if ( payment_el.length > 0 ) {
756
+ payment_type = payment_el.val();
757
+ }
758
+
759
+ // fire ga3 version
760
  window[ gtm4wp_datalayer_name ].push({
761
  'event': 'gtm4wp.checkoutStepEEC',
762
  'ecommerce': {
763
+ 'currencyCode': gtm4wp_currency,
764
  'checkout': {
765
  'actionField': {
766
  'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset
770
  }
771
  });
772
 
773
+ // fire ga4 version
774
+ window[ gtm4wp_datalayer_name ].push({
775
+ 'event': 'add_payment_info',
776
+ 'ecommerce': {
777
+ 'currency': gtm4wp_currency,
778
+ 'payment_type': payment_type,
779
+ 'value': window.gtm4wp_checkout_value,
780
+ 'items': window.gtm4wp_checkout_products_ga4
781
+ }
782
+ });
783
+
784
  gtm4wp_checkout_step_fired.push( 'payment_method' );
785
  });
786
 
802
  jQuery( 'input[name=payment_method]:checked' ).trigger( 'change' );
803
  }
804
 
805
+ var shipping_el = jQuery( 'input[name^=shipping_method]:checked' );
806
+ if ( shipping_el.length == 0 ) {
807
+ shipping_el = jQuery( 'input[name^=shipping_method]:first' );
808
  }
809
+ if ( shipping_el.length > 0 ) {
810
  window[ gtm4wp_datalayer_name ].push({
811
  'event': 'gtm4wp.checkoutOptionEEC',
812
  'ecommerce': {
813
  'checkout_option': {
814
  'actionField': {
815
  'step': 3 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset,
816
+ 'option': 'Shipping: ' + shipping_el.val()
817
  }
818
  }
819
  }
820
  });
821
  }
822
 
823
+ var payment_el = jQuery( '.payment_methods input:checked' );
824
+ if ( payment_el.length == 0 ) {
825
+ payment_el = jQuery( 'input[name^=payment_method]:first' );
826
+ }
827
+ if ( payment_el.length > 0 ) {
828
  window[ gtm4wp_datalayer_name ].push({
829
  'event': 'gtm4wp.checkoutOptionEEC',
830
  'ecommerce': {
831
  'checkout_option': {
832
  'actionField': {
833
  'step': 4 + window.gtm4wp_checkout_step_offset + gtm4wp_shipping_payment_method_step_offset,
834
+ 'option': 'Payment: ' + payment_el.val()
835
  }
836
  }
837
  }
855
  window[ gtm4wp_datalayer_name ][ i ][ 'ecomm_prodid' ] = [];
856
  }
857
 
858
+ if ( 'undefined' !== typeof window[ gtm4wp_datalayer_name ][ i ][ 'ecomm_prodid' ].push ) {
859
+ var productdata;
860
+ jQuery( '.gtm4wp_productdata' ).each( function() {
861
+ productdata = jQuery( this );
862
+
863
+ window[ gtm4wp_datalayer_name ][ i ][ 'ecomm_prodid' ].push( gtm4wp_id_prefix + productdata.data( 'gtm4wp_product_id' ) );
864
+ });
865
  }
866
+ }
867
+ }
868
 
869
+ // loop through datalayer and fire GA4 version of EEC events
870
+ if ( window[ gtm4wp_datalayer_name ] && window[ gtm4wp_datalayer_name ].forEach ) {
871
+ window[ gtm4wp_datalayer_name ].forEach(function( item ) {
872
 
873
+ if ( item && item.ecommerce && item.ecommerce.detail ) {
874
+ window[ gtm4wp_datalayer_name ].push({
875
+ 'event': 'view_item',
876
+ 'ecommerce': {
877
+ 'currency': gtm4wp_currency,
878
+ 'items': [ gtm4wp_map_eec_to_ga4( item.ecommerce.detail.products[0] ) ]
879
+ }
880
+ });
881
+ }
882
+
883
+ if ( item && item.ecommerce && ( item.ecommerce.cart || (item.ecommerce.checkout && is_cart) ) ) {
884
+ var source_products = item.ecommerce.cart || item.ecommerce.checkout;
885
+ var ga4_products = [];
886
+ var sum_value = 0;
887
+
888
+ source_products.forEach(function( product ) {
889
+ ga4_products.push( gtm4wp_map_eec_to_ga4( product ) );
890
+ sum_value += product.price * product.quantity;
891
+ });
892
+
893
+ window[ gtm4wp_datalayer_name ].push({
894
+ 'event': 'view_cart',
895
+ 'ecommerce': {
896
+ 'currency': gtm4wp_currency,
897
+ 'value': sum_value,
898
+ 'items': ga4_products
899
+ }
900
+ });
901
+ }
902
+
903
+ if ( item && item.ecommerce && item.ecommerce.checkout && !is_cart ) {
904
+ var ga4_products = [];
905
+ var sum_value = 0;
906
+
907
+ item.ecommerce.checkout.products.forEach(function( product ) {
908
+ ga4_products.push( gtm4wp_map_eec_to_ga4( product ) );
909
+ sum_value += product.price * product.quantity;
910
+ });
911
+
912
+ window[ gtm4wp_datalayer_name ].push({
913
+ 'event': 'begin_checkout',
914
+ 'ecommerce': {
915
+ 'currency': gtm4wp_currency,
916
+ 'value': sum_value,
917
+ 'items': ga4_products
918
+ }
919
+ });
920
+ }
921
+
922
+ // present if product is readded into cart just after removel
923
+ if ( item && item.ecommerce && item.ecommerce.add ) {
924
+ var ga4_products = [];
925
+ var sum_value = 0;
926
+
927
+ item.ecommerce.add.products.forEach(function( product ) {
928
+ ga4_products.push( gtm4wp_map_eec_to_ga4( product ) );
929
+ sum_value += product.price * product.quantity;
930
+ });
931
+
932
+ window[ gtm4wp_datalayer_name ].push({
933
+ 'event': 'add_to_cart',
934
+ 'ecommerce': {
935
+ 'currency': gtm4wp_currency,
936
+ 'value': sum_value,
937
+ 'items': ga4_products
938
+ }
939
+ });
940
+ }
941
+
942
+ if ( item && item.ecommerce && item.ecommerce.purchase ) {
943
+ var ga4_products = [];
944
+ item.ecommerce.purchase.products.forEach(function( product ) {
945
+ ga4_products.push( gtm4wp_map_eec_to_ga4( product ) );
946
+ });
947
+
948
+ window[ gtm4wp_datalayer_name ].push({
949
+ 'event': 'purchase',
950
+ 'ecommerce': {
951
+ 'currency': gtm4wp_currency,
952
+ 'items': ga4_products,
953
+ 'transaction_id': item.ecommerce.purchase.actionField.id,
954
+ 'affiliation': item.ecommerce.purchase.actionField.affiliation,
955
+ 'value': item.ecommerce.purchase.actionField.revenue,
956
+ 'tax': item.ecommerce.purchase.actionField.tax,
957
+ 'shipping': item.ecommerce.purchase.actionField.shipping,
958
+ 'coupon': item.ecommerce.purchase.actionField.coupon
959
+ }
960
+ });
961
+ }
962
+ });
963
  }
964
  });
js/gtm4wp-youtube.js CHANGED
@@ -1,221 +1,221 @@
1
- var gtm4wp_youtube_percentage_tracking = 10;
2
- var gtm4wp_youtube_percentage_tracking_timeouts = {};
3
- var gtm4wp_youtube_percentage_tracking_marks = {};
4
-
5
- if ( typeof onYouTubeIframeAPIReady === "undefined" ) {
6
- window.onYouTubeIframeAPIReady = function() {
7
- window[ gtm4wp_datalayer_name ].push({
8
- 'event': 'gtm4wp.mediaApiReady',
9
- 'mediaType': 'youtube'
10
- });
11
-
12
- jQuery( "iframe[src^='https://www.youtube.com/embed']" ).each( function() {
13
- var gtm4wp_jqthis = jQuery( this );
14
- var playerID = gtm4wp_jqthis.attr( "id" );
15
-
16
- if ( ( playerID === undefined ) || ( playerID === "" ) ) {
17
- var _gtm4wp_temp = gtm4wp_jqthis.attr( "src" ).split( "?" );
18
- var _gtm4wp_temp2 = _gtm4wp_temp[ 0 ].split( "/" );
19
-
20
- playerID = "youtubeplayer_" + _gtm4wp_temp2[ _gtm4wp_temp2.length-1 ];
21
- gtm4wp_jqthis.attr( "id", playerID );
22
- }
23
-
24
- var gtm4wp_yturl = gtm4wp_jqthis.attr( "src" );
25
- if ( gtm4wp_yturl.indexOf( "enablejsapi=1" ) == -1 ) {
26
- if ( gtm4wp_yturl.indexOf( "?" ) == -1 ) {
27
- gtm4wp_yturl += "?";
28
- }
29
-
30
- gtm4wp_yturl += "&enablejsapi=1&origin=" + document.location.protocol + "//" + document.location.hostname;
31
-
32
- gtm4wp_jqthis.attr( "src", gtm4wp_yturl );
33
- }
34
-
35
- player = new YT.Player( playerID, {
36
- events: {
37
- 'onReady': gtm4wp_onYouTubePlayerReady,
38
- 'onStateChange': gtm4wp_onYouTubePlayerStateChange,
39
- 'onPlaybackQualityChange': gtm4wp_onYouTubePlaybackQualityChange,
40
- 'onPlaybackRateChange': gtm4wp_onYouTubePlaybackRateChange,
41
- 'onError': gtm4wp_onYouTubeError,
42
- 'onApiChange': gtm4wp_onYouTubeApiChange
43
- }
44
- });
45
- });
46
- };
47
-
48
- var tag = document.createElement( 'script' );
49
- tag.src = "//www.youtube.com/iframe_api";
50
- var firstScriptTag = document.getElementsByTagName( 'script' )[0];
51
- firstScriptTag.parentNode.insertBefore( tag, firstScriptTag );
52
- } else {
53
- var gtm4wp_err = new Error( "Another code is already utilizing YouTube API, GTM4WP plugin can not load YouTube tracking!" );
54
- throw gtm4wp_err;
55
- }
56
-
57
- function gtm4wp_onYouTubePlayerReady( event ) {
58
- var videodata = event.target.getVideoData();
59
-
60
- window[ gtm4wp_datalayer_name ].push({
61
- 'event': 'gtm4wp.mediaPlayerReady',
62
- 'mediaType': 'youtube',
63
- 'mediaData': {
64
- 'id': videodata.video_id,
65
- 'author': videodata.author,
66
- 'title': videodata.title,
67
- 'url': event.target.getVideoUrl(),
68
- 'duration': event.target.getDuration()
69
- },
70
- 'mediaCurrentTime': event.target.getCurrentTime()
71
- });
72
- }
73
-
74
- function gtm4wp_onYouTubePlayerStateChange( event ) {
75
- var playerState = "unknown";
76
- switch( event.data ) {
77
- case -1: playerState = "unstarted"; break;
78
- case YT.PlayerState.ENDED: playerState = "ended"; break;
79
- case YT.PlayerState.PLAYING: playerState = "play"; break;
80
- case YT.PlayerState.PAUSED: playerState = "pause"; break;
81
- case YT.PlayerState.BUFFERING: playerState = "buffering"; break;
82
- case YT.PlayerState.CUED: playerState = "cued"; break;
83
- }
84
-
85
- var videoId = event.target.getVideoData().video_id;
86
-
87
- if ( ( YT.PlayerState.PLAYING == event.data ) && ( gtm4wp_youtube_percentage_tracking > 0 ) ) {
88
- gtm4wp_youtube_percentage_tracking_timeouts[ videoId ] = setInterval(function() {
89
- gtm4wp_onYouTubePercentageChange( event );
90
- }, 1000);
91
- } else {
92
- if ( gtm4wp_youtube_percentage_tracking_timeouts[ videoId ] ) {
93
- clearInterval( gtm4wp_youtube_percentage_tracking_timeouts[ videoId ] );
94
- }
95
- }
96
-
97
- var videodata = event.target.getVideoData();
98
-
99
- window[ gtm4wp_datalayer_name ].push({
100
- 'event': 'gtm4wp.mediaPlayerStateChange',
101
- 'mediaType': 'youtube',
102
- 'mediaData': {
103
- 'id': videodata.video_id,
104
- 'author': videodata.author,
105
- 'title': videodata.title,
106
- 'url': event.target.getVideoUrl(),
107
- 'duration': event.target.getDuration()
108
- },
109
- 'mediaPlayerState': playerState,
110
- 'mediaCurrentTime': event.target.getCurrentTime()
111
- });
112
- }
113
-
114
- function gtm4wp_onYouTubePlaybackQualityChange( event ) {
115
- var videodata = event.target.getVideoData();
116
-
117
- window[ gtm4wp_datalayer_name ].push({
118
- 'event': 'gtm4wp.mediaPlayerEvent',
119
- 'mediaType': 'youtube',
120
- 'mediaData': {
121
- 'id': videodata.video_id,
122
- 'author': videodata.author,
123
- 'title': videodata.title,
124
- 'url': event.target.getVideoUrl(),
125
- 'duration': event.target.getDuration()
126
- },
127
- 'mediaCurrentTime': event.target.getCurrentTime(),
128
- 'mediaPlayerEvent': 'quality-change',
129
- 'mediaPlayerEventParam': event.data
130
- });
131
- }
132
-
133
- function gtm4wp_onYouTubePlaybackRateChange( event ) {
134
- var videodata = event.target.getVideoData();
135
-
136
- window[ gtm4wp_datalayer_name ].push({
137
- 'event': 'gtm4wp.mediaPlayerEvent',
138
- 'mediaType': 'youtube',
139
- 'mediaData': {
140
- 'id': videodata.video_id,
141
- 'author': videodata.author,
142
- 'title': videodata.title,
143
- 'url': event.target.getVideoUrl(),
144
- 'duration': event.target.getDuration()
145
- },
146
- 'mediaCurrentTime': event.target.getCurrentTime(),
147
- 'mediaPlayerEvent': 'ratechange',
148
- 'mediaPlayerEventParam': event.data
149
- });
150
- }
151
-
152
- function gtm4wp_onYouTubeError( event ) {
153
- var videodata = event.target.getVideoData();
154
-
155
- window[ gtm4wp_datalayer_name ].push({
156
- 'event': 'gtm4wp.mediaPlayerEvent',
157
- 'mediaType': 'youtube',
158
- 'mediaData': {
159
- 'id': videodata.video_id,
160
- 'author': videodata.author,
161
- 'title': videodata.title,
162
- 'url': event.target.getVideoUrl(),
163
- 'duration': event.target.getDuration()
164
- },
165
- 'mediaCurrentTime': event.target.getCurrentTime(),
166
- 'mediaPlayerEvent': 'error',
167
- 'mediaPlayerEventParam': event.data
168
- });
169
- }
170
-
171
- function gtm4wp_onYouTubeApiChange( event ) {
172
- var videodata = event.target.getVideoData();
173
-
174
- window[ gtm4wp_datalayer_name ].push({
175
- 'event': 'gtm4wp.mediaPlayerEvent',
176
- 'mediaType': 'youtube',
177
- 'mediaData': {
178
- 'id': videodata.video_id,
179
- 'author': videodata.author,
180
- 'title': videodata.title,
181
- 'url': event.target.getVideoUrl(),
182
- 'duration': event.target.getDuration()
183
- },
184
- 'mediaCurrentTime': event.target.getCurrentTime(),
185
- 'mediaPlayerEvent': 'api-change',
186
- 'mediaPlayerEventParam': event.data
187
- });
188
- }
189
-
190
- function gtm4wp_onYouTubePercentageChange( event ) {
191
- var videoId = event.target.getVideoData().video_id;
192
- var videoCurrentTime = event.target.getCurrentTime();
193
- var videoDuration = event.target.getDuration();
194
- var videoPercentage = Math.floor( videoCurrentTime / videoDuration * 100 );
195
-
196
- if ( typeof gtm4wp_youtube_percentage_tracking_marks[ videoId ] == "undefined" ) {
197
- gtm4wp_youtube_percentage_tracking_marks[ videoId ] = [];
198
- }
199
-
200
- var videodata = event.target.getVideoData();
201
-
202
- for( var i=0; i<100; i+=gtm4wp_youtube_percentage_tracking ) {
203
- if ( ( videoPercentage > i ) && ( gtm4wp_youtube_percentage_tracking_marks[ videoId ].indexOf( i ) == -1 ) ) {
204
- gtm4wp_youtube_percentage_tracking_marks[ videoId ].push( i );
205
-
206
- window[ gtm4wp_datalayer_name ].push({
207
- 'event': 'gtm4wp.mediaPlaybackPercentage',
208
- 'mediaType': 'youtube',
209
- 'mediaData': {
210
- 'id': videodata.video_id,
211
- 'author': videodata.author,
212
- 'title': videodata.title,
213
- 'url': event.target.getVideoUrl(),
214
- 'duration': event.target.getDuration()
215
- },
216
- 'mediaCurrentTime': event.target.getCurrentTime(),
217
- 'mediaPercentage': i
218
- });
219
- }
220
- }
221
  }
1
+ var gtm4wp_youtube_percentage_tracking = 10;
2
+ var gtm4wp_youtube_percentage_tracking_timeouts = {};
3
+ var gtm4wp_youtube_percentage_tracking_marks = {};
4
+
5
+ if ( typeof onYouTubeIframeAPIReady === "undefined" ) {
6
+ window.onYouTubeIframeAPIReady = function() {
7
+ window[ gtm4wp_datalayer_name ].push({
8
+ 'event': 'gtm4wp.mediaApiReady',
9
+ 'mediaType': 'youtube'
10
+ });
11
+
12
+ jQuery( "iframe[src^='https://www.youtube.com/embed']" ).each( function() {
13
+ var gtm4wp_jqthis = jQuery( this );
14
+ var playerID = gtm4wp_jqthis.attr( "id" );
15
+
16
+ if ( ( playerID === undefined ) || ( playerID === "" ) ) {
17
+ var _gtm4wp_temp = gtm4wp_jqthis.attr( "src" ).split( "?" );
18
+ var _gtm4wp_temp2 = _gtm4wp_temp[ 0 ].split( "/" );
19
+
20
+ playerID = "youtubeplayer_" + _gtm4wp_temp2[ _gtm4wp_temp2.length-1 ];
21
+ gtm4wp_jqthis.attr( "id", playerID );
22
+ }
23
+
24
+ var gtm4wp_yturl = gtm4wp_jqthis.attr( "src" );
25
+ if ( gtm4wp_yturl.indexOf( "enablejsapi=1" ) == -1 ) {
26
+ if ( gtm4wp_yturl.indexOf( "?" ) == -1 ) {
27
+ gtm4wp_yturl += "?";
28
+ }
29
+
30
+ gtm4wp_yturl += "&enablejsapi=1&origin=" + document.location.protocol + "//" + document.location.hostname;
31
+
32
+ gtm4wp_jqthis.attr( "src", gtm4wp_yturl );
33
+ }
34
+
35
+ player = new YT.Player( playerID, {
36
+ events: {
37
+ 'onReady': gtm4wp_onYouTubePlayerReady,
38
+ 'onStateChange': gtm4wp_onYouTubePlayerStateChange,
39
+ 'onPlaybackQualityChange': gtm4wp_onYouTubePlaybackQualityChange,
40
+ 'onPlaybackRateChange': gtm4wp_onYouTubePlaybackRateChange,
41
+ 'onError': gtm4wp_onYouTubeError,
42
+ 'onApiChange': gtm4wp_onYouTubeApiChange
43
+ }
44
+ });
45
+ });
46
+ };
47
+
48
+ var tag = document.createElement( 'script' );
49
+ tag.src = "//www.youtube.com/iframe_api";
50
+ var firstScriptTag = document.getElementsByTagName( 'script' )[0];
51
+ firstScriptTag.parentNode.insertBefore( tag, firstScriptTag );
52
+ } else {
53
+ var gtm4wp_err = new Error( "Another code is already utilizing YouTube API, GTM4WP plugin can not load YouTube tracking!" );
54
+ throw gtm4wp_err;
55
+ }
56
+
57
+ function gtm4wp_onYouTubePlayerReady( event ) {
58
+ var videodata = event.target.getVideoData();
59
+
60
+ window[ gtm4wp_datalayer_name ].push({
61
+ 'event': 'gtm4wp.mediaPlayerReady',
62
+ 'mediaType': 'youtube',
63
+ 'mediaData': {
64
+ 'id': videodata.video_id,
65
+ 'author': videodata.author,
66
+ 'title': videodata.title,
67
+ 'url': event.target.getVideoUrl(),
68
+ 'duration': event.target.getDuration()
69
+ },
70
+ 'mediaCurrentTime': event.target.getCurrentTime()
71
+ });
72
+ }
73
+
74
+ function gtm4wp_onYouTubePlayerStateChange( event ) {
75
+ var playerState = "unknown";
76
+ switch( event.data ) {
77
+ case -1: playerState = "unstarted"; break;
78
+ case YT.PlayerState.ENDED: playerState = "ended"; break;
79
+ case YT.PlayerState.PLAYING: playerState = "play"; break;
80
+ case YT.PlayerState.PAUSED: playerState = "pause"; break;
81
+ case YT.PlayerState.BUFFERING: playerState = "buffering"; break;
82
+ case YT.PlayerState.CUED: playerState = "cued"; break;
83
+ }
84
+
85
+ var videoId = event.target.getVideoData().video_id;
86
+
87
+ if ( ( YT.PlayerState.PLAYING == event.data ) && ( gtm4wp_youtube_percentage_tracking > 0 ) ) {
88
+ gtm4wp_youtube_percentage_tracking_timeouts[ videoId ] = setInterval(function() {
89
+ gtm4wp_onYouTubePercentageChange( event );
90
+ }, 1000);
91
+ } else {
92
+ if ( gtm4wp_youtube_percentage_tracking_timeouts[ videoId ] ) {
93
+ clearInterval( gtm4wp_youtube_percentage_tracking_timeouts[ videoId ] );
94
+ }
95
+ }
96
+
97
+ var videodata = event.target.getVideoData();
98
+
99
+ window[ gtm4wp_datalayer_name ].push({
100
+ 'event': 'gtm4wp.mediaPlayerStateChange',
101
+ 'mediaType': 'youtube',
102
+ 'mediaData': {
103
+ 'id': videodata.video_id,
104
+ 'author': videodata.author,
105
+ 'title': videodata.title,
106
+ 'url': event.target.getVideoUrl(),
107
+ 'duration': event.target.getDuration()
108
+ },
109
+ 'mediaPlayerState': playerState,
110
+ 'mediaCurrentTime': event.target.getCurrentTime()
111
+ });
112
+ }
113
+
114
+ function gtm4wp_onYouTubePlaybackQualityChange( event ) {
115
+ var videodata = event.target.getVideoData();
116
+
117
+ window[ gtm4wp_datalayer_name ].push({
118
+ 'event': 'gtm4wp.mediaPlayerEvent',
119
+ 'mediaType': 'youtube',
120
+ 'mediaData': {
121
+ 'id': videodata.video_id,
122
+ 'author': videodata.author,
123
+ 'title': videodata.title,
124
+ 'url': event.target.getVideoUrl(),
125
+ 'duration': event.target.getDuration()
126
+ },
127
+ 'mediaCurrentTime': event.target.getCurrentTime(),
128
+ 'mediaPlayerEvent': 'quality-change',
129
+ 'mediaPlayerEventParam': event.data
130
+ });
131
+ }
132
+
133
+ function gtm4wp_onYouTubePlaybackRateChange( event ) {
134
+ var videodata = event.target.getVideoData();
135
+
136
+ window[ gtm4wp_datalayer_name ].push({
137
+ 'event': 'gtm4wp.mediaPlayerEvent',
138
+ 'mediaType': 'youtube',
139
+ 'mediaData': {
140
+ 'id': videodata.video_id,
141
+ 'author': videodata.author,
142
+ 'title': videodata.title,
143
+ 'url': event.target.getVideoUrl(),
144
+ 'duration': event.target.getDuration()
145
+ },
146
+ 'mediaCurrentTime': event.target.getCurrentTime(),
147
+ 'mediaPlayerEvent': 'ratechange',
148
+ 'mediaPlayerEventParam': event.data
149
+ });
150
+ }
151
+
152
+ function gtm4wp_onYouTubeError( event ) {
153
+ var videodata = event.target.getVideoData();
154
+
155
+ window[ gtm4wp_datalayer_name ].push({
156
+ 'event': 'gtm4wp.mediaPlayerEvent',
157
+ 'mediaType': 'youtube',
158
+ 'mediaData': {
159
+ 'id': videodata.video_id,
160
+ 'author': videodata.author,
161
+ 'title': videodata.title,
162
+ 'url': event.target.getVideoUrl(),
163
+ 'duration': event.target.getDuration()
164
+ },
165
+ 'mediaCurrentTime': event.target.getCurrentTime(),
166
+ 'mediaPlayerEvent': 'error',
167
+ 'mediaPlayerEventParam': event.data
168
+ });
169
+ }
170
+
171
+ function gtm4wp_onYouTubeApiChange( event ) {
172
+ var videodata = event.target.getVideoData();
173
+
174
+ window[ gtm4wp_datalayer_name ].push({
175
+ 'event': 'gtm4wp.mediaPlayerEvent',
176
+ 'mediaType': 'youtube',
177
+ 'mediaData': {
178
+ 'id': videodata.video_id,
179
+ 'author': videodata.author,
180
+ 'title': videodata.title,
181
+ 'url': event.target.getVideoUrl(),
182
+ 'duration': event.target.getDuration()
183
+ },
184
+ 'mediaCurrentTime': event.target.getCurrentTime(),
185
+ 'mediaPlayerEvent': 'api-change',
186
+ 'mediaPlayerEventParam': event.data
187
+ });
188
+ }
189
+
190
+ function gtm4wp_onYouTubePercentageChange( event ) {
191
+ var videoId = event.target.getVideoData().video_id;
192
+ var videoCurrentTime = event.target.getCurrentTime();
193
+ var videoDuration = event.target.getDuration();
194
+ var videoPercentage = Math.floor( videoCurrentTime / videoDuration * 100 );
195
+
196
+ if ( typeof gtm4wp_youtube_percentage_tracking_marks[ videoId ] == "undefined" ) {
197
+ gtm4wp_youtube_percentage_tracking_marks[ videoId ] = [];
198
+ }
199
+
200
+ var videodata = event.target.getVideoData();
201
+
202
+ for( var i=0; i<100; i+=gtm4wp_youtube_percentage_tracking ) {
203
+ if ( ( videoPercentage > i ) && ( gtm4wp_youtube_percentage_tracking_marks[ videoId ].indexOf( i ) == -1 ) ) {
204
+ gtm4wp_youtube_percentage_tracking_marks[ videoId ].push( i );
205
+
206
+ window[ gtm4wp_datalayer_name ].push({
207
+ 'event': 'gtm4wp.mediaPlaybackPercentage',
208
+ 'mediaType': 'youtube',
209
+ 'mediaData': {
210
+ 'id': videodata.video_id,
211
+ 'author': videodata.author,
212
+ 'title': videodata.title,
213
+ 'url': event.target.getVideoUrl(),
214
+ 'duration': event.target.getDuration()
215
+ },
216
+ 'mediaCurrentTime': event.target.getCurrentTime(),
217
+ 'mediaPercentage': i
218
+ });
219
+ }
220
+ }
221
  }
public/frontend.php CHANGED
@@ -1,1034 +1,904 @@
1
- <?php
2
- define( 'GTM4WP_WPFILTER_COMPILE_DATALAYER', 'gtm4wp_compile_datalayer' );
3
- define( 'GTM4WP_WPFILTER_COMPILE_REMARKTING', 'gtm4wp_compile_remarkering' );
4
- define( 'GTM4WP_WPFILTER_AFTER_DATALAYER', 'gtm4wp_after_datalayer' );
5
- define( 'GTM4WP_WPFILTER_GETTHEGTMTAG', 'gtm4wp_get_the_gtm_tag' );
6
- define( 'GTM4WP_WPACTION_ADDGLOBALVARS', 'gtm4wp_add_global_vars' );
7
-
8
- $GLOBALS['gtm4wp_container_code_written'] = false;
9
-
10
- // check for empty is needed to prevent error in WP CLI
11
- // bugfix by Patrick Holberg Hesselberg
12
- if ( empty( $GLOBALS['gtm4wp_options'] ) || ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ] == '' ) ) {
13
- $GLOBALS['gtm4wp_datalayer_name'] = 'dataLayer';
14
- } else {
15
- $GLOBALS['gtm4wp_datalayer_name'] = $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ];
16
- }
17
-
18
- // Setting Global Variable to Store JSON based Datalayer for Intergrations
19
- $GLOBALS['gtm4wp_datalayer_json'] = '';
20
- $GLOBALS['gtm4wp_datalayer_globalvars'] = '';
21
-
22
- // Moving include to top due to hierarchy of includes
23
- if ( isset( $GLOBALS['gtm4wp_options'] ) && ( '' != $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_AMPID ] ) ) {
24
- require_once dirname( __FILE__ ) . '/../integration/amp.php';
25
- }
26
- if ( ! function_exists( 'gtm4wp_amp_running' ) ) {
27
- function gtm4wp_amp_running() {
28
- return false;
29
- }
30
- }
31
-
32
- /**
33
- * Converts bool false to string false for JS
34
- *
35
- * @author Vincent Koc <https://github.com/koconder/>
36
- * @return mixed Returs object or string false
37
- */
38
- function gtm4wp_escjs_boolean( $obj ) {
39
- if ( empty( $obj ) || is_null( $obj ) || ! $obj ) {
40
- return 'false';
41
- } else {
42
- return $obj;
43
- }
44
- }
45
-
46
- function gtm4wp_is_assoc( $arr ) {
47
- // borrowed from
48
- // http://stackoverflow.com/questions/173400/php-arrays-a-good-way-to-check-if-an-array-is-associative-or-sequential
49
- return array_keys( $arr ) !== range( 0, count( $arr ) - 1 );
50
- }
51
-
52
- /**
53
- * Original copyright:
54
- * By Grant Burton @ BURTONTECH.COM (11-30-2008): IP-Proxy-Cluster Fix
55
- *
56
- * Code improved by Thomas Geiger
57
- */
58
- function gtm4wp_ip_is_private( $ip ) {
59
- $int_ip = ip2long( $ip );
60
- if ( ! empty( $ip ) && $int_ip != -1 && $int_ip !== false ) {
61
- $private_ips = array(
62
- array( '0.0.0.0', '2.255.255.255' ),
63
- array( '10.0.0.0', '10.255.255.255' ),
64
- array( '127.0.0.0', '127.255.255.255' ),
65
- array( '169.254.0.0', '169.254.255.255' ),
66
- array( '172.16.0.0', '172.31.255.255' ),
67
- array( '192.0.2.0', '192.0.2.255' ),
68
- array( '192.168.0.0', '192.168.255.255' ),
69
- array( '255.255.255.0', '255.255.255.255' ),
70
- );
71
-
72
- foreach ( $private_ips as $private_ip ) {
73
- $min_int_ip = ip2long( $private_ip[0] );
74
- $max_int_ip = ip2long( $private_ip[1] );
75
- if ( ( $int_ip >= $min_int_ip ) && ( $int_ip <= $max_int_ip ) ) {
76
- return true;
77
- }
78
- }
79
-
80
- return false;
81
- } else {
82
- return true;
83
- }
84
- }
85
-
86
- /**
87
- * Original copyright:
88
- * By Grant Burton @ BURTONTECH.COM
89
- *
90
- * Code improved by Thomas Geiger
91
- */
92
- function gtm4wp_get_user_ip() {
93
- if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) && ! gtm4wp_ip_is_private( $_SERVER['HTTP_CLIENT_IP'] ) ) {
94
- return $_SERVER['HTTP_CLIENT_IP'];
95
- }
96
-
97
- if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
98
- foreach ( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) as $ip ) {
99
- if ( ! gtm4wp_ip_is_private( trim( $ip ) ) ) {
100
- return $ip;
101
- }
102
- }
103
- }
104
-
105
- if ( ! empty( $_SERVER['HTTP_X_FORWARDED'] ) && ! gtm4wp_ip_is_private( $_SERVER['HTTP_X_FORWARDED'] ) ) {
106
- return $_SERVER['HTTP_X_FORWARDED'];
107
- } elseif ( ! empty( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] ) && ! gtm4wp_ip_is_private( $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'] ) ) {
108
- return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
109
- } elseif ( ! empty( $_SERVER['HTTP_FORWARDED_FOR'] ) && ! gtm4wp_ip_is_private( $_SERVER['HTTP_FORWARDED_FOR'] ) ) {
110
- return $_SERVER['HTTP_FORWARDED_FOR'];
111
- } elseif ( ! empty( $_SERVER['HTTP_FORWARDED'] ) && ! gtm4wp_ip_is_private( $_SERVER['HTTP_FORWARDED'] ) ) {
112
- return $_SERVER['HTTP_FORWARDED'];
113
- } else {
114
- return $_SERVER['REMOTE_ADDR'];
115
- }
116
- }
117
-
118
- if ( ! function_exists( 'getallheaders' ) ) {
119
- function getallheaders() {
120
- $headers = array();
121
- foreach ( $_SERVER as $name => $value ) {
122
- if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
123
- $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
124
- }
125
- }
126
-
127
- return $headers;
128
- }
129
- }
130
-
131
- function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
132
- global $wp_query, $gtm4wp_options;
133
-
134
- if ( $gtm4wp_options[ GTM4WP_OPTION_DONOTTRACK ] ) {
135
- if ( ! empty( $_SERVER['HTTP_DNT'] ) ) {
136
- $dataLayer['visitorDoNotTrack'] = (int) ( $_SERVER['HTTP_DNT'] );
137
- } else {
138
- $dataLayer['visitorDoNotTrack'] = 0;
139
- }
140
- }
141
-
142
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_SITEID ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_SITENAME ] ) {
143
- $dataLayer['siteID'] = 0;
144
- $dataLayer['siteName'] = '';
145
-
146
- if ( function_exists( 'get_blog_details' ) ) {
147
- $gtm4wp_blogdetails = get_blog_details();
148
-
149
- $dataLayer['siteID'] = $gtm4wp_blogdetails->blog_id;
150
- $dataLayer['siteName'] = $gtm4wp_blogdetails->blogname;
151
- }
152
- }
153
-
154
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_LOGGEDIN ] ) {
155
- if ( is_user_logged_in() ) {
156
- $dataLayer['visitorLoginState'] = 'logged-in';
157
- } else {
158
- $dataLayer['visitorLoginState'] = 'logged-out';
159
- }
160
- }
161
-
162
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERREGDATE ] ) {
163
- $current_user = wp_get_current_user();
164
-
165
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] ) {
166
- $dataLayer['visitorType'] = ( empty( $current_user->roles[0] ) ? 'visitor-logged-out' : $current_user->roles[0] );
167
- }
168
-
169
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] ) {
170
- $dataLayer['visitorEmail'] = ( empty( $current_user->user_email ) ? '' : $current_user->user_email );
171
- }
172
-
173
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERREGDATE ] ) {
174
- $dataLayer['visitorRegistrationDate'] = ( empty( $current_user->user_registered ) ? '' : strtotime( $current_user->user_registered ) );
175
- }
176
-
177
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERNAME ] ) {
178
- $dataLayer['visitorUsername'] = ( empty( $current_user->user_login ) ? '' : $current_user->user_login );
179
- }
180
- }
181
-
182
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERID ] ) {
183
- $_gtm4wp_userid = get_current_user_id();
184
- if ( $_gtm4wp_userid > 0 ) {
185
- $dataLayer['visitorId'] = $_gtm4wp_userid;
186
- }
187
- }
188
-
189
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_VISITOR_IP ] ) {
190
- $dataLayer['visitorIP'] = esc_js( gtm4wp_get_user_ip() );
191
- }
192
-
193
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTITLE ] ) {
194
- $dataLayer['pageTitle'] = strip_tags( wp_title( '|', false, 'right' ) );
195
- }
196
-
197
- if ( is_singular() ) {
198
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
199
- $dataLayer['pagePostType'] = get_post_type();
200
- $dataLayer['pagePostType2'] = 'single-' . get_post_type();
201
- }
202
-
203
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_CATEGORIES ] ) {
204
- $_post_cats = get_the_category();
205
- if ( $_post_cats ) {
206
- $dataLayer['pageCategory'] = array();
207
- foreach ( $_post_cats as $_one_cat ) {
208
- $dataLayer['pageCategory'][] = $_one_cat->slug;
209
- }
210
- }
211
- }
212
-
213
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_TAGS ] ) {
214
- $_post_tags = get_the_tags();
215
- if ( $_post_tags ) {
216
- $dataLayer['pageAttributes'] = array();
217
- foreach ( $_post_tags as $_one_tag ) {
218
- $dataLayer['pageAttributes'][] = $_one_tag->slug;
219
- }
220
- }
221
- }
222
-
223
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHORID ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHOR ] ) {
224
- $postuser = get_userdata( $GLOBALS['post']->post_author );
225
-
226
- if ( false !== $postuser ) {
227
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHORID ] ) {
228
- $dataLayer['pagePostAuthorID'] = $postuser->ID;
229
- }
230
-
231
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHOR ] ) {
232
- $dataLayer['pagePostAuthor'] = $postuser->display_name;
233
- }
234
- }
235
- }
236
-
237
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
238
- $dataLayer['pagePostDate'] = get_the_date();
239
- $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
240
- $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
241
- $dataLayer['pagePostDateDay'] = get_the_date( 'd' );
242
- }
243
-
244
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTERMLIST ] ) {
245
- $dataLayer["pagePostTerms"] = array();
246
- $object_taxonomies = get_object_taxonomies( get_post_type() );
247
- foreach( $object_taxonomies as $one_object_taxonomy ) {
248
- $post_taxonomy_values = get_the_terms( $GLOBALS[ "post" ]->ID, $one_object_taxonomy );
249
- if ( is_array( $post_taxonomy_values ) ) {
250
- $dataLayer["pagePostTerms"][$one_object_taxonomy] = array();
251
- foreach( $post_taxonomy_values as $one_taxonomy_value ) {
252
- $dataLayer["pagePostTerms"][$one_object_taxonomy][] = $one_taxonomy_value->name;
253
- }
254
- }
255
- }
256
- }
257
- }
258
-
259
- if ( is_archive() || is_post_type_archive() ) {
260
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
261
- $dataLayer['pagePostType'] = get_post_type();
262
-
263
- if ( is_category() ) {
264
- $dataLayer['pagePostType2'] = 'category-' . get_post_type();
265
- } elseif ( is_tag() ) {
266
- $dataLayer['pagePostType2'] = 'tag-' . get_post_type();
267
- } elseif ( is_tax() ) {
268
- $dataLayer['pagePostType2'] = 'tax-' . get_post_type();
269
- } elseif ( is_author() ) {
270
- $dataLayer['pagePostType2'] = 'author-' . get_post_type();
271
- } elseif ( is_year() ) {
272
- $dataLayer['pagePostType2'] = 'year-' . get_post_type();
273
-
274
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
275
- $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
276
- }
277
- } elseif ( is_month() ) {
278
- $dataLayer['pagePostType2'] = 'month-' . get_post_type();
279
-
280
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
281
- $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
282
- $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
283
- }
284
- } elseif ( is_day() ) {
285
- $dataLayer['pagePostType2'] = 'day-' . get_post_type();
286
-
287
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
288
- $dataLayer['pagePostDate'] = get_the_date();
289
- $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
290
- $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
291
- $dataLayer['pagePostDateDay'] = get_the_date( 'd' );
292
- }
293
- } elseif ( is_time() ) {
294
- $dataLayer['pagePostType2'] = 'time-' . get_post_type();
295
- } elseif ( is_date() ) {
296
- $dataLayer['pagePostType2'] = 'date-' . get_post_type();
297
-
298
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
299
- $dataLayer['pagePostDate'] = get_the_date();
300
- $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
301
- $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
302
- $dataLayer['pagePostDateDay'] = get_the_date( 'd' );
303
- }
304
- }
305
- }
306
-
307
- if ( ( is_tax() || is_category() ) && $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_CATEGORIES ] ) {
308
- $_post_cats = get_the_category();
309
- $dataLayer['pageCategory'] = array();
310
- foreach ( $_post_cats as $_one_cat ) {
311
- $dataLayer['pageCategory'][] = $_one_cat->slug;
312
- }
313
- }
314
-
315
- if ( ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHORID ] ) && ( is_author() ) ) {
316
- global $authordata;
317
- $dataLayer['pagePostAuthorID'] = isset( $authordata->ID ) ? $authordata->ID : 0;
318
- }
319
-
320
- if ( ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHOR ] ) && ( is_author() ) ) {
321
- $dataLayer['pagePostAuthor'] = get_the_author();
322
- }
323
- }
324
-
325
- if ( is_search() ) {
326
- $dataLayer['siteSearchTerm'] = get_search_query();
327
- $dataLayer['siteSearchFrom'] = '';
328
- if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
329
- $referer_url_parts = explode( '?', $_SERVER['HTTP_REFERER'] );
330
- if ( count( $referer_url_parts ) > 1 ) {
331
- $dataLayer['siteSearchFrom'] = $referer_url_parts[0] . '?' . rawurlencode( $referer_url_parts[1] );
332
- } else {
333
- $dataLayer['siteSearchFrom'] = $referer_url_parts[0];
334
- }
335
- }
336
- $dataLayer['siteSearchResults'] = $wp_query->post_count;
337
- }
338
-
339
- if ( is_front_page() && $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
340
- $dataLayer['pagePostType'] = 'frontpage';
341
- }
342
-
343
- if ( ! is_front_page() && is_home() && $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
344
- $dataLayer['pagePostType'] = 'bloghome';
345
- }
346
-
347
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_BROWSERDATA ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_OSDATA ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_DEVICEDATA ] ) {
348
- spl_autoload_register(
349
- function( $class ) {
350
- $class_parts = explode( '\\', $class );
351
- if ( 'WhichBrowser' == $class_parts[0] ) {
352
- include dirname( __FILE__ ) . '/../integration/whichbrowser/' . str_replace( array( 'WhichBrowser', '\\' ), array( 'src', '/' ), $class ) . '.php';
353
- }
354
- }
355
- );
356
-
357
- require_once dirname( __FILE__ ) . '/../integration/whichbrowser/src/Parser.php';
358
-
359
- $gtp4wp_headers = getallheaders();
360
- if ( ( false === $gtp4wp_headers ) && isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
361
- $gtp4wp_headers = $_SERVER['HTTP_USER_AGENT'];
362
- }
363
- if ( false !== $gtp4wp_headers ) {
364
- $detected = new WhichBrowser\Parser( $gtp4wp_headers );
365
-
366
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_BROWSERDATA ] ) {
367
- $dataLayer['browserName'] = isset( $detected->browser->name ) ? $detected->browser->name : '';
368
- $dataLayer['browserVersion'] = isset( $detected->browser->version->value ) ? $detected->browser->version->value : '';
369
-
370
- $dataLayer['browserEngineName'] = isset( $detected->engine->name ) ? $detected->engine->name : '';
371
- $dataLayer['browserEngineVersion'] = isset( $detected->engine->version->value ) ? $detected->engine->version->value : '';
372
- }
373
-
374
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_OSDATA ] ) {
375
- $dataLayer['osName'] = isset( $detected->os->name ) ? $detected->os->name : '';
376
- $dataLayer['osVersion'] = isset( $detected->os->version->value ) ? $detected->os->version->value : '';
377
- }
378
-
379
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_DEVICEDATA ] ) {
380
- $dataLayer['deviceType'] = isset( $detected->device->type ) ? $detected->device->type : '';
381
- $dataLayer['deviceManufacturer'] = isset( $detected->device->manufacturer ) ? $detected->device->manufacturer : '';
382
- $dataLayer['deviceModel'] = isset( $detected->device->model ) ? $detected->device->model : '';
383
- }
384
- }
385
- }
386
-
387
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTCOUNT ] ) {
388
- $dataLayer['postCountOnPage'] = (int) $wp_query->post_count;
389
- $dataLayer['postCountTotal'] = (int) $wp_query->found_posts;
390
- }
391
-
392
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTID ] && is_singular() === true ) {
393
- $dataLayer['postID'] = (int) get_the_ID();
394
- }
395
-
396
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTFORMAT ] && is_singular() === true ) {
397
- $dataLayer['postFormat'] = get_post_format() ?: 'standard';
398
- }
399
-
400
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] > 0 ) {
401
- $_gtmrestrictlistitems = array();
402
-
403
- // IDs from https://developers.google.com/tag-manager/devguide#security
404
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ADADVISOR ] ) {
405
- $_gtmrestrictlistitems[] = 'ta';
406
- }
407
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ADROLL ] ) {
408
- $_gtmrestrictlistitems[] = 'asp';
409
- }
410
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_AWCONV ] ) {
411
- $_gtmrestrictlistitems[] = 'awct';
412
- }
413
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_AWREMARKET ] ) {
414
- $_gtmrestrictlistitems[] = 'sp';
415
- }
416
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_BIZO ] ) {
417
- $_gtmrestrictlistitems[] = 'bzi';
418
- }
419
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_CLICKTALE ] ) {
420
- $_gtmrestrictlistitems[] = 'cts';
421
- }
422
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_COMSCORE ] ) {
423
- $_gtmrestrictlistitems[] = 'csm';
424
- }
425
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_CUSTOMHTML ] ) {
426
- $_gtmrestrictlistitems[] = 'html';
427
- }
428
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_CUSTOMIMG ] ) {
429
- $_gtmrestrictlistitems[] = 'img';
430
- }
431
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_DBLCLKCOUNT ] ) {
432
- $_gtmrestrictlistitems[] = 'flc';
433
- }
434
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_DBLCLKSALES ] ) {
435
- $_gtmrestrictlistitems[] = 'fls';
436
- }
437
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_GACLASSIC ] ) {
438
- $_gtmrestrictlistitems[] = 'ga';
439
- }
440
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MARIN ] ) {
441
- $_gtmrestrictlistitems[] = 'ms';
442
- }
443
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MPLEXIFRAME ] ) {
444
- $_gtmrestrictlistitems[] = 'mpm';
445
- }
446
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MPLEXROI ] ) {
447
- $_gtmrestrictlistitems[] = 'mpr';
448
- }
449
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MEDIA6DEG ] ) {
450
- $_gtmrestrictlistitems[] = 'm6d';
451
- }
452
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_TURNCONV ] ) {
453
- $_gtmrestrictlistitems[] = 'tc';
454
- }
455
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_TURNDATA ] ) {
456
- $_gtmrestrictlistitems[] = 'tdc';
457
- }
458
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_UA ] ) {
459
- $_gtmrestrictlistitems[] = 'ua';
460
- }
461
-
462
- $_gtmwhitelist = array();
463
- $_gtmblacklist = array();
464
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 1 ) {
465
- $_gtmblacklist = array_merge( $_gtmblacklist, $_gtmrestrictlistitems );
466
- } else {
467
- $_gtmwhitelist = array_merge( $_gtmwhitelist, $_gtmrestrictlistitems );
468
- }
469
-
470
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_DOMELEMENT ] ) {
471
- $_gtmwhitelist[] = 'd';
472
- }
473
-
474
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_CUSTOMJS ] ) {
475
- $_gtmwhitelist[] = 'jsm';
476
- }
477
-
478
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_CONSTANT ] ) {
479
- $_gtmwhitelist[] = 'c';
480
- }
481
-
482
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_1STCOOKIE ] ) {
483
- $_gtmwhitelist[] = 'k';
484
- }
485
-
486
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_EVENTNAME ] ) {
487
- $_gtmwhitelist[] = 'e';
488
- }
489
-
490
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_JSVAR ] ) {
491
- $_gtmwhitelist[] = 'j';
492
- }
493
-
494
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_DLAYERVAR ] ) {
495
- $_gtmwhitelist[] = 'v';
496
- }
497
-
498
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_RANDOMNUM ] ) {
499
- $_gtmwhitelist[] = 'r';
500
- }
501
-
502
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_REFERRER ] ) {
503
- $_gtmwhitelist[] = 'f';
504
- }
505
-
506
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_URL ] ) {
507
- $_gtmwhitelist[] = 'u';
508
- }
509
-
510
- if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_MACRO_AUTOEVENT ] ) {
511
- $_gtmwhitelist[] = 'v';
512
- }
513
-
514
- $dataLayer['gtm.whitelist'] = $_gtmwhitelist;
515
- $dataLayer['gtm.blacklist'] = $_gtmblacklist;
516
- }
517
-
518
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOCF ] && isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) {
519
- $dataLayer['geoCloudflareCountryCode'] = $_SERVER['HTTP_CF_IPCOUNTRY'];
520
- }
521
-
522
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
523
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) {
524
- $dataLayer['weatherCategory'] = __( '(no weather data available)', 'duracelltomi-google-tag-manager' );
525
- $dataLayer['weatherDescription'] = __( '(no weather data available)', 'duracelltomi-google-tag-manager' );
526
- $dataLayer['weatherTemp'] = 0;
527
- $dataLayer['weatherPressure'] = 0;
528
- $dataLayer['weatherWindSpeed'] = 0;
529
- $dataLayer['weatherWindDeg'] = 0;
530
- $dataLayer['weatherDataStatus'] = 'Initialized with empty data';
531
- }
532
-
533
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
534
- $dataLayer['geoCountryCode'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
535
- $dataLayer['geoCountryName'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
536
- $dataLayer['geoRegionCode'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
537
- $dataLayer['geoRegionName'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
538
- $dataLayer['geoCity'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
539
- $dataLayer['geoZipcode'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
540
- $dataLayer['geoLatitude'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
541
- $dataLayer['geoLongitude'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
542
- }
543
-
544
- $client_ip = gtm4wp_get_user_ip();
545
-
546
- if ( '' !== $client_ip ) {
547
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) {
548
- $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) );
549
-
550
- if ( false !== $weatherdata ) {
551
- $dataLayer['weatherCategory'] = $weatherdata->weather[0]->main;
552
- $dataLayer['weatherDescription'] = $weatherdata->weather[0]->description;
553
- $dataLayer['weatherTemp'] = $weatherdata->main->temp;
554
- $dataLayer['weatherPressure'] = $weatherdata->main->pressure;
555
- $dataLayer['weatherWindSpeed'] = $weatherdata->wind->speed;
556
- $dataLayer['weatherWindDeg'] = ( isset($weatherdata->wind->deg) ? $weatherdata->wind->deg : '' );
557
- $dataLayer['weatherFullWeatherData'] = $weatherdata;
558
- $dataLayer['weatherDataStatus'] = 'Read from cache';
559
- } else {
560
- $dataLayer['weatherDataStatus'] = 'No weather data in cache (' . esc_attr( $client_ip ) . ')';
561
- }
562
- }
563
-
564
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
565
- $geodata = get_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ) );
566
-
567
- if ( false !== $geodata ) {
568
- $dataLayer['geoFullGeoData'] = $geodata;
569
-
570
- if ( isset( $geodata->latitude ) ) {
571
- $dataLayer['geoCountryCode'] = $geodata->country_code;
572
- $dataLayer['geoCountryName'] = $geodata->country_name;
573
- $dataLayer['geoRegionCode'] = $geodata->region_code;
574
- $dataLayer['geoRegionName'] = $geodata->region_name;
575
- $dataLayer['geoCity'] = $geodata->city;
576
- $dataLayer['geoZipcode'] = $geodata->zip;
577
- $dataLayer['geoLatitude'] = $geodata->latitude;
578
- $dataLayer['geoLongitude'] = $geodata->longitude;
579
- }
580
- }
581
- }
582
- }
583
- }
584
-
585
- return $dataLayer;
586
- }
587
-
588
- function gtm4wp_wp_loaded() {
589
- global $gtm4wp_options;
590
-
591
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
592
- $client_ip = gtm4wp_get_user_ip();
593
- $geodata = get_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ) );
594
-
595
- if ( false === $geodata ) {
596
- $gtm4wp_geodata = @wp_remote_get( sprintf( 'http://api.ipstack.com/%s?access_key=%s&format=1', urlencode( $client_ip ), $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOAPI ] ) );
597
-
598
- if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata['response']['code'] ) ) {
599
- $gtm4wp_geodata = @json_decode( $gtm4wp_geodata['body'] );
600
-
601
- if ( is_object( $gtm4wp_geodata ) ) {
602
- set_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ), $gtm4wp_geodata, 60 * 60 );
603
-
604
- $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) );
605
- if ( false === $weatherdata && isset( $gtm4wp_geodata->latitude ) ) {
606
-
607
- $weatherdata = wp_remote_get( 'http://api.openweathermap.org/data/2.5/weather?appid=' . $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI ] . '&lat=' . $gtm4wp_geodata->latitude . '&lon=' . $gtm4wp_geodata->longitude . '&units=' . ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] == 0 ? 'metric' : 'imperial' ) );
608
-
609
- if ( is_array( $weatherdata ) && ( 200 == $weatherdata['response']['code'] ) ) {
610
- $weatherdata = @json_decode( $weatherdata['body'] );
611
-
612
- if ( is_object( $weatherdata ) ) {
613
- set_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ), $weatherdata, 60 * 60 );
614
- setcookie( 'gtm4wp_last_weatherstatus', 'Weather data loaded.' );
615
- } else {
616
- setcookie( 'gtm4wp_last_weatherstatus', 'Openweathermap.org did not return processable data: ' . var_export( $weatherdata, true ) );
617
- }
618
- } else {
619
- if ( is_wp_error( $weatherdata ) ) {
620
- setcookie( 'gtm4wp_last_weatherstatus', 'Openweathermap.org request error: ' . $weatherdata->get_error_message() );
621
- } else {
622
- setcookie( 'gtm4wp_last_weatherstatus', 'Openweathermap.org returned status code: ' . $weatherdata['response']['code'] );
623
- }
624
- }
625
- }
626
- } else {
627
- setcookie( 'gtm4wp_last_weatherstatus', 'ipstack.com did not return lat-lng data: ' . var_export( $gtm4wp_geodata, true ) );
628
- }
629
- } else {
630
- if ( is_wp_error( $gtm4wp_geodata ) ) {
631
- setcookie( 'gtm4wp_last_weatherstatus', 'ipstack.com request error: ' . $gtm4wp_geodata->get_error_message() );
632
- } else {
633
- setcookie( 'gtm4wp_last_weatherstatus', 'ipstack.com returned status code: ' . $gtm4wp_geodata['response']['code'] );
634
- }
635
- }
636
- }
637
- }
638
- }
639
-
640
- function gtm4wp_get_the_gtm_tag() {
641
- global $gtm4wp_options, $gtm4wp_datalayer_name, $gtm4wp_container_code_written;
642
-
643
- $_gtm_tag = '
644
- <!-- Google Tag Manager (noscript) -->';
645
-
646
- if ( GTM4WP_PLACEMENT_OFF == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
647
- $gtm4wp_container_code_written = true;
648
- }
649
-
650
- if ( ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != '' ) && ( ! $gtm4wp_container_code_written ) ) {
651
- $_gtm_codes = explode( ',', str_replace( array( ';', ' ' ), array( ',', '' ), $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) );
652
-
653
- if ( ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] ) && ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] ) ) {
654
- $_gtm_env = '&gtm_auth=' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] . '&gtm_preview=' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] . '&gtm_cookies_win=x';
655
- } else {
656
- $_gtm_env = '';
657
- }
658
-
659
- foreach ( $_gtm_codes as $one_gtm_code ) {
660
- $_gtm_tag .= '
661
- <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=' . $one_gtm_code . $_gtm_env . '"
662
- height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
663
- }
664
-
665
- $_gtm_tag .= '
666
- <!-- End Google Tag Manager (noscript) -->';
667
-
668
- $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
669
- $gtm4wp_container_code_written = true;
670
- }
671
-
672
- return $_gtm_tag;
673
- }
674
-
675
- function gtm4wp_the_gtm_tag() {
676
- echo gtm4wp_get_the_gtm_tag();
677
- }
678
-
679
- function gtm4wp_enqueue_scripts() {
680
- global $gtm4wp_options, $gtp4wp_plugin_url;
681
-
682
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_OUTBOUND ] ) {
683
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_EVENTS_OUTBOUND, false );
684
- wp_enqueue_script( 'gtm4wp-outbound-click-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-outbound-click-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
685
- }
686
-
687
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DOWNLOADS ] ) {
688
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_EVENTS_DOWNLOADS, false );
689
- wp_enqueue_script( 'gtm4wp-download-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-download-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
690
- }
691
-
692
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_EMAILCLICKS ] ) {
693
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_EVENTS_EMAILCLICKS, false );
694
- wp_enqueue_script( 'gtm4wp-email-link-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-email-link-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
695
- }
696
-
697
- if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WPCF7 ] ) {
698
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_INTEGRATE_WPCF7, false );
699
- wp_enqueue_script( 'gtm4wp-contact-form-7-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-contact-form-7-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
700
- }
701
-
702
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_FORMMOVE ] ) {
703
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_EVENTS_FORMMOVE, false );
704
- wp_enqueue_script( 'gtm4wp-form-move-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-form-move-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
705
- }
706
-
707
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_SOCIAL ] ) {
708
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_EVENTS_SOCIAL, false );
709
- wp_enqueue_script( 'gtm4wp-social-actions', $gtp4wp_plugin_url . 'js/gtm4wp-social-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
710
- }
711
-
712
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_YOUTUBE ] ) {
713
- require_once dirname( __FILE__ ) . '/../integration/youtube.php';
714
- }
715
-
716
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_VIMEO ] ) {
717
- require_once dirname( __FILE__ ) . '/../integration/vimeo.php';
718
- }
719
-
720
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_SOUNDCLOUD ] ) {
721
- require_once dirname( __FILE__ ) . '/../integration/soundcloud.php';
722
- }
723
-
724
- if ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_ENABLED ] ) {
725
- $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_SCROLLER_ENABLED, false );
726
- wp_enqueue_script( 'gtm4wp-scroll-tracking', $gtp4wp_plugin_url . 'js/analytics-talk-content-tracking.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
727
- }
728
- }
729
-
730
- function gtm4wp_wp_footer() {
731
- global $gtm4wp_options;
732
-
733
- if ( GTM4WP_PLACEMENT_FOOTER == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
734
- gtm4wp_the_gtm_tag();
735
- }
736
- }
737
-
738
- function gtm4wp_wp_body_open() {
739
- global $gtm4wp_options;
740
-
741
- if ( ( GTM4WP_PLACEMENT_BODYOPEN == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) || ( GTM4WP_PLACEMENT_BODYOPEN_AUTO == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) ) {
742
- gtm4wp_the_gtm_tag();
743
- }
744
- }
745
-
746
- function gtm4wp_filter_visitor_keys( $dataLayer ) {
747
- foreach ( $dataLayer as $dl_key => $dl_value ) {
748
- if ( strpos( $dl_key, 'visitor' ) !== false ) {
749
- unset( $dataLayer[ $dl_key ] );
750
- }
751
- }
752
-
753
- return $dataLayer;
754
- }
755
-
756
- /**
757
- * GTM4WP global JS variables WordPress filter
758
- *
759
- * @author Vincent Koc <https://github.com/koconder/>
760
- * @link https://github.com/duracelltomi/gtm4wp/issues/34
761
- * @return mixed returns the
762
- */
763
- function gtm4wp_add_global_vars( $vars, $return = false ) {
764
- if ( ! $return ) {
765
- if ( function_exists( $vars ) ) {
766
- $vars = $vars();
767
- }
768
- $GLOBALS['gtm4wp_datalayer_globalvars'] = $GLOBALS['gtm4wp_datalayer_globalvars'] . ' ' . $vars;
769
- }
770
- return $GLOBALS['gtm4wp_datalayer_globalvars'];
771
- }
772
-
773
- function gtm4wp_wp_header_top( $echo = true ) {
774
- global $gtm4wp_options, $gtm4wp_datalayer_name;
775
-
776
- $has_html5_support = current_theme_supports( 'html5' );
777
-
778
- $_gtm_top_content = '
779
- <!-- Google Tag Manager for WordPress by gtm4wp.com -->
780
- <script data-cfasync="false" data-pagespeed-no-defer' . ( $has_html5_support ? ' type="text/javascript"' : '' ) . '>//<![CDATA[
781
- var gtm4wp_datalayer_name = "' . $gtm4wp_datalayer_name . '";
782
- var ' . $gtm4wp_datalayer_name . ' = ' . $gtm4wp_datalayer_name . ' || [];';
783
-
784
- // Load in the global variables from gtm4wp_add_global_vars / GTM4WP_WPACTION_ADDGLOBALVARS filter
785
- $_gtm_top_content .= apply_filters( GTM4WP_WPACTION_ADDGLOBALVARS, '', true );
786
-
787
- if ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_ENABLED ] ) {
788
- $_gtm_top_content .= '
789
-
790
- var gtm4wp_scrollerscript_debugmode = ' . ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_DEBUGMODE ] ? 'true' : 'false' ) . ';
791
- var gtm4wp_scrollerscript_callbacktime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_CALLBACKTIME ] . ';
792
- var gtm4wp_scrollerscript_readerlocation = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_DISTANCE ] . ';
793
- var gtm4wp_scrollerscript_contentelementid = "' . $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_CONTENTID ] . '";
794
- var gtm4wp_scrollerscript_scannertime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_READERTIME ] . ';';
795
- }
796
-
797
- $_gtm_top_content .= '
798
- //]]>
799
- </script>
800
- <!-- End Google Tag Manager for WordPress by gtm4wp.com -->';
801
-
802
- if ( ! gtm4wp_amp_running() ) {
803
- if ( $echo ) {
804
- echo $_gtm_top_content;
805
- } else {
806
- return $_gtm_top_content;
807
- }
808
- }
809
- }
810
-
811
- function gtm4wp_wp_header_begin( $echo = true ) {
812
- global $gtm4wp_datalayer_name, $gtm4wp_datalayer_json, $gtm4wp_options, $woocommerce;
813
-
814
- $has_html5_support = current_theme_supports( 'html5' );
815
-
816
- $_gtm_header_content = '
817
- <!-- Google Tag Manager for WordPress by gtm4wp.com -->
818
- <script data-cfasync="false" data-pagespeed-no-defer' . ( $has_html5_support ? ' type="text/javascript"' : '' ) . '>//<![CDATA[';
819
-
820
- if ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != '' ) {
821
- $gtm4wp_datalayer_data = array();
822
- $gtm4wp_datalayer_data = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_DATALAYER, $gtm4wp_datalayer_data );
823
-
824
- if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_REMARKETING ] ) {
825
- // add Google Ads remarketing tags as suggested here:
826
- // https://support.google.com/tagmanager/answer/3002580?hl=en
827
- add_filter( GTM4WP_WPFILTER_COMPILE_REMARKTING, 'gtm4wp_filter_visitor_keys' );
828
- $gtm4wp_remarketing_tags = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_REMARKTING, $gtm4wp_datalayer_data );
829
-
830
- $_gtm_header_content .= "\nvar google_tag_params = ";
831
- $_gtm_header_content .= json_encode( $gtm4wp_remarketing_tags );
832
- $_gtm_header_content .= ';';
833
- $gtm4wp_datalayer_data['google_tag_params'] = '-~-window.google_tag_params-~-';
834
- }
835
-
836
- if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DOWNLOADS ] ) {
837
- $_gtm_header_content .= '
838
- jQuery( function() {
839
- gtm4wp_track_downloads( "' . str_replace( '"', '', $gtm4wp_options[ GTM4WP_OPTION_EVENTS_DWLEXT ] ) . '" );
840
- });';
841
- }
842
-
843
- if ( version_compare( PHP_VERSION, '5.4.0' ) >= 0 ) {
844
- $gtm4wp_datalayer_json = json_encode( $gtm4wp_datalayer_data, JSON_UNESCAPED_UNICODE );
845
- } else {
846
- $gtm4wp_datalayer_json = json_encode( $gtm4wp_datalayer_data );
847
- }
848
-
849
- // Clean up and then push datalayer to AMP
850
- $gtm4wp_datalayer_json = str_replace(
851
- array( '"-~-', '-~-"' ),
852
- array( '', '' ),
853
- str_replace( '–', '-', $gtm4wp_datalayer_json )
854
- );
855
-
856
- $_gtm_header_content .= '
857
- var dataLayer_content = ' . $gtm4wp_datalayer_json . ';';
858
-
859
- // fire WooCommerce order double tracking protection only if WooCommerce is active and user is on the order received page
860
- if ( isset( $gtm4wp_options ) && ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) && isset( $woocommerce ) && is_order_received_page() ) {
861
-
862
- $_gtm_header_content .= '
863
- // if dataLayer contains ecommerce purchase data, check whether it has been already tracked
864
- if ( dataLayer_content.transactionId || ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.purchase ) ) {
865
- // read order id already tracked from cookies
866
- var gtm4wp_orderid_tracked = "";
867
-
868
- if ( !window.localStorage ) {
869
- var gtm4wp_cookie = "; " + document.cookie;
870
- var gtm4wp_cookie_parts = gtm4wp_cookie.split( "; gtm4wp_orderid_tracked=" );
871
- if ( gtm4wp_cookie_parts.length == 2 ) {
872
- gtm4wp_orderid_tracked = gtm4wp_cookie_parts.pop().split(";").shift();
873
- }
874
- } else {
875
- window.localStorage.getItem( "gtm4wp_orderid_tracked" );
876
- }
877
-
878
- // check enhanced ecommerce
879
- if ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.purchase ) {
880
- if ( gtm4wp_orderid_tracked && ( dataLayer_content.ecommerce.purchase.actionField.id == gtm4wp_orderid_tracked ) ) {
881
- delete dataLayer_content.ecommerce.purchase;
882
- } else {
883
- gtm4wp_orderid_tracked = dataLayer_content.ecommerce.purchase.actionField.id;
884
- }
885
- }
886
-
887
- // check standard ecommerce
888
- if ( dataLayer_content.transactionId ) {
889
- if ( gtm4wp_orderid_tracked && ( dataLayer_content.transactionId == gtm4wp_orderid_tracked ) ) {
890
- delete dataLayer_content.transactionId;
891
- delete dataLayer_content.transactionDate;
892
- delete dataLayer_content.transactionType;
893
- delete dataLayer_content.transactionAffiliation;
894
- delete dataLayer_content.transactionTotal;
895
- delete dataLayer_content.transactionShipping;
896
- delete dataLayer_content.transactionTax;
897
- delete dataLayer_content.transactionPaymentType;
898
- delete dataLayer_content.transactionCurrency;
899
- delete dataLayer_content.transactionShippingMethod;
900
- delete dataLayer_content.transactionPromoCode;
901
- delete dataLayer_content.transactionProducts;
902
- } else {
903
- gtm4wp_orderid_tracked = dataLayer_content.transactionId;
904
- }
905
- }
906
-
907
- if ( gtm4wp_orderid_tracked ) {
908
- if ( !window.localStorage ) {
909
- var gtm4wp_orderid_cookie_expire = new Date();
910
- gtm4wp_orderid_cookie_expire.setTime( gtm4wp_orderid_cookie_expire.getTime() + (365*24*60*60*1000) );
911
- var gtm4wp_orderid_cookie_expires_part = "expires=" + gtm4wp_orderid_cookie_expire.toUTCString();
912
- document.cookie = "gtm4wp_orderid_tracked=" + gtm4wp_orderid_tracked + ";" + gtm4wp_orderid_cookie_expires_part + ";path=/";
913
- } else {
914
- window.localStorage.setItem( "gtm4wp_orderid_tracked", gtm4wp_orderid_tracked );
915
- }
916
- }
917
-
918
- }';
919
- }
920
-
921
- $_gtm_header_content .= '
922
- ' . $gtm4wp_datalayer_name . '.push( dataLayer_content );';
923
- }
924
-
925
- $_gtm_header_content .= '//]]>
926
- </script>';
927
-
928
- $_gtm_header_content .= apply_filters( GTM4WP_WPFILTER_AFTER_DATALAYER, '' );
929
-
930
- if ( ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != '' ) && ( GTM4WP_PLACEMENT_OFF != $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) ) {
931
- $_gtm_codes = explode( ',', str_replace( array( ';', ' ' ), array( ',', '' ), $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) );
932
-
933
- $_gtm_tag = '';
934
- foreach ( $_gtm_codes as $one_gtm_code ) {
935
- if ( ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] ) && ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] ) ) {
936
- $_gtm_env = "+'&gtm_auth=" . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] . '&gtm_preview=' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] . "&gtm_cookies_win=x'";
937
- } else {
938
- $_gtm_env = '';
939
- }
940
-
941
- $_gtm_tag .= '
942
- <script data-cfasync="false">//<![CDATA[
943
- (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':
944
- new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0],
945
- j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src=
946
- \'//www.googletagmanager.com/gtm.\'' . '+\'js?id=\'+i+dl' . $_gtm_env . ';f.parentNode.insertBefore(j,f);
947
- })(window,document,\'script\',\'' . $gtm4wp_datalayer_name . '\',\'' . $one_gtm_code . '\');//]]>
948
- </script>';
949
- }
950
-
951
- $_gtm_tag .= '
952
- <!-- End Google Tag Manager -->';
953
-
954
- $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
955
- $_gtm_header_content .= $_gtm_tag;
956
- }
957
-
958
- $_gtm_header_content .= '
959
- <!-- End Google Tag Manager for WordPress by gtm4wp.com -->';
960
-
961
- if ( ! gtm4wp_amp_running() ) {
962
- if ( $echo ) {
963
- echo $_gtm_header_content;
964
- } else {
965
- return $_gtm_header_content;
966
- }
967
- }
968
- }
969
-
970
- function gtm4wp_wp_login() {
971
- setcookie( 'gtm4wp_user_logged_in', '1', 0, '/' );
972
- }
973
-
974
- function gtm4wp_user_register() {
975
- setcookie( 'gtm4wp_user_registered', '1', 0, '/' );
976
- }
977
-
978
- function gtm4wp_user_reg_login_script() {
979
- global $gtp4wp_plugin_url;
980
-
981
- $in_footer = apply_filters( 'gtm4wp_user_reg_login_script', true );
982
- wp_enqueue_script( 'gtm4wp-user-reg-login-script', $gtp4wp_plugin_url . 'js/gtm4wp-users.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
983
- }
984
-
985
- function gtm4wp_rocket_excluded_inline_js_content( $pattern ) {
986
- $pattern[] = 'dataLayer';
987
- $pattern[] = 'gtm4wp';
988
-
989
- return $pattern;
990
- }
991
-
992
- add_action( 'wp_enqueue_scripts', 'gtm4wp_enqueue_scripts' );
993
- $gtm4wp_header_begin_prior = 10;
994
- if ( isset( $GLOBALS['gtm4wp_options'] ) && $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_LOADEARLY ] ) {
995
- $gtm4wp_header_begin_prior = 2;
996
- }
997
- add_action( 'wp_head', 'gtm4wp_wp_header_begin', $gtm4wp_header_begin_prior, 0 );
998
- add_action( 'wp_head', 'gtm4wp_wp_header_top', 1, 0 );
999
- add_action( 'wp_footer', 'gtm4wp_wp_footer' );
1000
- add_action( 'wp_loaded', 'gtm4wp_wp_loaded' );
1001
- add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, 'gtm4wp_add_basic_datalayer_data' );
1002
-
1003
- // to be able to easily migrate from other Google Tag Manager plugins
1004
- add_action( 'body_open', 'gtm4wp_wp_body_open' );
1005
-
1006
- // compatibility with existing themes that natively support code injection after opening body tag
1007
- add_action( 'genesis_before', 'gtm4wp_wp_body_open' ); // Genisis theme
1008
- add_action( 'generate_before_header', 'gtm4wp_wp_body_open', 0 ); // GeneratePress theme
1009
- add_action( 'elementor/page_templates/canvas/before_content', 'gtm4wp_wp_body_open' ); // Elementor
1010
- add_action( 'ct_before_builder', 'gtm4wp_wp_body_open', 0 ); // Oxygen Builder
1011
- add_action( 'fl_before_builder', 'gtm4wp_wp_body_open', 0 ); // Beaver Builder Theme
1012
-
1013
- // standard WP theme support for body open tags
1014
- add_action( 'wp_body_open', 'gtm4wp_wp_body_open' );
1015
-
1016
- add_filter( 'rocket_excluded_inline_js_content', 'gtm4wp_rocket_excluded_inline_js_content' ); // WP Rocket
1017
- if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] || $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] )
1018
- && isset( $GLOBALS['woocommerce'] ) ) {
1019
- require_once dirname( __FILE__ ) . '/../integration/woocommerce.php';
1020
- }
1021
-
1022
- if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] != '' ) ) {
1023
- require_once dirname( __FILE__ ) . '/../integration/google-optimize.php';
1024
- }
1025
-
1026
- if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_EVENTS_USERLOGIN ] ) ) {
1027
- add_action( 'wp_login', 'gtm4wp_wp_login' );
1028
- add_action( 'wp_enqueue_scripts', 'gtm4wp_user_reg_login_script' );
1029
- }
1030
-
1031
- if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_EVENTS_NEWUSERREG ] ) ) {
1032
- add_action( 'user_register', 'gtm4wp_user_register' );
1033
- add_action( 'wp_enqueue_scripts', 'gtm4wp_user_reg_login_script' );
1034
- }
1
+ <?php
2
+ define( 'GTM4WP_WPFILTER_COMPILE_DATALAYER', 'gtm4wp_compile_datalayer' );
3
+ define( 'GTM4WP_WPFILTER_COMPILE_REMARKTING', 'gtm4wp_compile_remarkering' );
4
+ define( 'GTM4WP_WPFILTER_AFTER_DATALAYER', 'gtm4wp_after_datalayer' );
5
+ define( 'GTM4WP_WPFILTER_GETTHEGTMTAG', 'gtm4wp_get_the_gtm_tag' );
6
+ define( 'GTM4WP_WPACTION_ADDGLOBALVARS', 'gtm4wp_add_global_vars' );
7
+
8
+ $GLOBALS['gtm4wp_container_code_written'] = false;
9
+
10
+ // check for empty is needed to prevent error in WP CLI
11
+ // bugfix by Patrick Holberg Hesselberg
12
+ if ( empty( $GLOBALS['gtm4wp_options'] ) || ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ] == '' ) ) {
13
+ $GLOBALS['gtm4wp_datalayer_name'] = 'dataLayer';
14
+ } else {
15
+ $GLOBALS['gtm4wp_datalayer_name'] = $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_DATALAYER_NAME ];
16
+ }
17
+
18
+ // Setting Global Variable to Store JSON based Datalayer for Intergrations
19
+ $GLOBALS['gtm4wp_datalayer_json'] = '';
20
+ $GLOBALS['gtm4wp_datalayer_globalvars'] = '';
21
+
22
+ // Moving include to top due to hierarchy of includes
23
+ if ( isset( $GLOBALS['gtm4wp_options'] ) && ( '' != $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_AMPID ] ) ) {
24
+ require_once dirname( __FILE__ ) . '/../integration/amp.php';
25
+ }
26
+ if ( ! function_exists( 'gtm4wp_amp_running' ) ) {
27
+ function gtm4wp_amp_running() {
28
+ return false;
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Converts bool false to string false for JS
34
+ *
35
+ * @author Vincent Koc <https://github.com/koconder/>
36
+ * @return mixed Returs object or string false
37
+ */
38
+ function gtm4wp_escjs_boolean( $obj ) {
39
+ if ( empty( $obj ) || is_null( $obj ) || ! $obj ) {
40
+ return 'false';
41
+ } else {
42
+ return $obj;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Original copyright:
48
+ * By Grant Burton @ BURTONTECH.COM
49
+ *
50
+ * Code improved by Thomas Geiger
51
+ */
52
+ function gtm4wp_get_user_ip() {
53
+ if ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
54
+ foreach ( explode( ',', $_SERVER['HTTP_X_FORWARDED_FOR'] ) as $ip ) {
55
+ if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) {
56
+ return $ip;
57
+ }
58
+ }
59
+ }
60
+
61
+ $possible_ip_variables = array(
62
+ 'HTTP_CLIENT_IP',
63
+ 'HTTP_X_FORWARDED',
64
+ 'HTTP_X_CLUSTER_CLIENT_IP',
65
+ 'HTTP_FORWARDED_FOR',
66
+ 'HTTP_FORWARDED',
67
+ 'REMOTE_ADDR'
68
+ );
69
+
70
+ foreach( $possible_ip_variables as $one_ip_variable ) {
71
+ if (
72
+ ! empty( $_SERVER[ $one_ip_variable ] )
73
+ && ( filter_var( $_SERVER[ $one_ip_variable ], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false )
74
+ ) {
75
+ return $_SERVER[ $one_ip_variable ];
76
+ }
77
+ }
78
+
79
+ return '';
80
+ }
81
+
82
+ if ( ! function_exists( 'getallheaders' ) ) {
83
+ function getallheaders() {
84
+ $headers = array();
85
+ foreach ( $_SERVER as $name => $value ) {
86
+ if ( substr( $name, 0, 5 ) == 'HTTP_' ) {
87
+ $headers[ str_replace( ' ', '-', ucwords( strtolower( str_replace( '_', ' ', substr( $name, 5 ) ) ) ) ) ] = $value;
88
+ }
89
+ }
90
+
91
+ return $headers;
92
+ }
93
+ }
94
+
95
+ function gtm4wp_add_basic_datalayer_data( $dataLayer ) {
96
+ global $wp_query, $gtm4wp_options, $gtm4wp_entity_ids;
97
+
98
+ if ( $gtm4wp_options[ GTM4WP_OPTION_DONOTTRACK ] ) {
99
+ if ( ! empty( $_SERVER['HTTP_DNT'] ) ) {
100
+ $dataLayer['visitorDoNotTrack'] = (int) ( $_SERVER['HTTP_DNT'] );
101
+ } else {
102
+ $dataLayer['visitorDoNotTrack'] = 0;
103
+ }
104
+ }
105
+
106
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_SITEID ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_SITENAME ] ) {
107
+ $dataLayer['siteID'] = 0;
108
+ $dataLayer['siteName'] = '';
109
+
110
+ if ( function_exists( 'get_blog_details' ) ) {
111
+ $gtm4wp_blogdetails = get_blog_details();
112
+
113
+ $dataLayer['siteID'] = $gtm4wp_blogdetails->blog_id;
114
+ $dataLayer['siteName'] = $gtm4wp_blogdetails->blogname;
115
+ }
116
+ }
117
+
118
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_LOGGEDIN ] ) {
119
+ if ( is_user_logged_in() ) {
120
+ $dataLayer['visitorLoginState'] = 'logged-in';
121
+ } else {
122
+ $dataLayer['visitorLoginState'] = 'logged-out';
123
+ }
124
+ }
125
+
126
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERREGDATE ] ) {
127
+ $current_user = wp_get_current_user();
128
+
129
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERROLE ] ) {
130
+ $dataLayer['visitorType'] = ( empty( $current_user->roles[0] ) ? 'visitor-logged-out' : $current_user->roles[0] );
131
+ }
132
+
133
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USEREMAIL ] ) {
134
+ $dataLayer['visitorEmail'] = ( empty( $current_user->user_email ) ? '' : $current_user->user_email );
135
+ }
136
+
137
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERREGDATE ] ) {
138
+ $dataLayer['visitorRegistrationDate'] = ( empty( $current_user->user_registered ) ? '' : strtotime( $current_user->user_registered ) );
139
+ }
140
+
141
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERNAME ] ) {
142
+ $dataLayer['visitorUsername'] = ( empty( $current_user->user_login ) ? '' : $current_user->user_login );
143
+ }
144
+ }
145
+
146
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_USERID ] ) {
147
+ $_gtm4wp_userid = get_current_user_id();
148
+ if ( $_gtm4wp_userid > 0 ) {
149
+ $dataLayer['visitorId'] = $_gtm4wp_userid;
150
+ }
151
+ }
152
+
153
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_VISITOR_IP ] ) {
154
+ $dataLayer['visitorIP'] = esc_js( gtm4wp_get_user_ip() );
155
+ }
156
+
157
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTITLE ] ) {
158
+ $dataLayer['pageTitle'] = strip_tags( wp_title( '|', false, 'right' ) );
159
+ }
160
+
161
+ if ( is_singular() ) {
162
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
163
+ $dataLayer['pagePostType'] = get_post_type();
164
+ $dataLayer['pagePostType2'] = 'single-' . get_post_type();
165
+ }
166
+
167
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_CATEGORIES ] ) {
168
+ $_post_cats = get_the_category();
169
+ if ( $_post_cats ) {
170
+ $dataLayer['pageCategory'] = array();
171
+ foreach ( $_post_cats as $_one_cat ) {
172
+ $dataLayer['pageCategory'][] = $_one_cat->slug;
173
+ }
174
+ }
175
+ }
176
+
177
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_TAGS ] ) {
178
+ $_post_tags = get_the_tags();
179
+ if ( $_post_tags ) {
180
+ $dataLayer['pageAttributes'] = array();
181
+ foreach ( $_post_tags as $_one_tag ) {
182
+ $dataLayer['pageAttributes'][] = $_one_tag->slug;
183
+ }
184
+ }
185
+ }
186
+
187
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHORID ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHOR ] ) {
188
+ $postuser = get_userdata( $GLOBALS['post']->post_author );
189
+
190
+ if ( false !== $postuser ) {
191
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHORID ] ) {
192
+ $dataLayer['pagePostAuthorID'] = $postuser->ID;
193
+ }
194
+
195
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHOR ] ) {
196
+ $dataLayer['pagePostAuthor'] = $postuser->display_name;
197
+ }
198
+ }
199
+ }
200
+
201
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
202
+ $dataLayer['pagePostDate'] = get_the_date();
203
+ $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
204
+ $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
205
+ $dataLayer['pagePostDateDay'] = get_the_date( 'd' );
206
+ }
207
+
208
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTERMLIST ] ) {
209
+ $dataLayer["pagePostTerms"] = array();
210
+ $object_taxonomies = get_object_taxonomies( get_post_type() );
211
+ foreach( $object_taxonomies as $one_object_taxonomy ) {
212
+ $post_taxonomy_values = get_the_terms( $GLOBALS[ "post" ]->ID, $one_object_taxonomy );
213
+ if ( is_array( $post_taxonomy_values ) ) {
214
+ $dataLayer["pagePostTerms"][$one_object_taxonomy] = array();
215
+ foreach( $post_taxonomy_values as $one_taxonomy_value ) {
216
+ $dataLayer["pagePostTerms"][$one_object_taxonomy][] = $one_taxonomy_value->name;
217
+ }
218
+ }
219
+ }
220
+ }
221
+ }
222
+
223
+ if ( is_archive() || is_post_type_archive() ) {
224
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
225
+ $dataLayer['pagePostType'] = get_post_type();
226
+
227
+ if ( is_category() ) {
228
+ $dataLayer['pagePostType2'] = 'category-' . get_post_type();
229
+ } elseif ( is_tag() ) {
230
+ $dataLayer['pagePostType2'] = 'tag-' . get_post_type();
231
+ } elseif ( is_tax() ) {
232
+ $dataLayer['pagePostType2'] = 'tax-' . get_post_type();
233
+ } elseif ( is_author() ) {
234
+ $dataLayer['pagePostType2'] = 'author-' . get_post_type();
235
+ } elseif ( is_year() ) {
236
+ $dataLayer['pagePostType2'] = 'year-' . get_post_type();
237
+
238
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
239
+ $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
240
+ }
241
+ } elseif ( is_month() ) {
242
+ $dataLayer['pagePostType2'] = 'month-' . get_post_type();
243
+
244
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
245
+ $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
246
+ $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
247
+ }
248
+ } elseif ( is_day() ) {
249
+ $dataLayer['pagePostType2'] = 'day-' . get_post_type();
250
+
251
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
252
+ $dataLayer['pagePostDate'] = get_the_date();
253
+ $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
254
+ $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
255
+ $dataLayer['pagePostDateDay'] = get_the_date( 'd' );
256
+ }
257
+ } elseif ( is_time() ) {
258
+ $dataLayer['pagePostType2'] = 'time-' . get_post_type();
259
+ } elseif ( is_date() ) {
260
+ $dataLayer['pagePostType2'] = 'date-' . get_post_type();
261
+
262
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTDATE ] ) {
263
+ $dataLayer['pagePostDate'] = get_the_date();
264
+ $dataLayer['pagePostDateYear'] = get_the_date( 'Y' );
265
+ $dataLayer['pagePostDateMonth'] = get_the_date( 'm' );
266
+ $dataLayer['pagePostDateDay'] = get_the_date( 'd' );
267
+ }
268
+ }
269
+ }
270
+
271
+ if ( ( is_tax() || is_category() ) && $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_CATEGORIES ] ) {
272
+ $_post_cats = get_the_category();
273
+ $dataLayer['pageCategory'] = array();
274
+ foreach ( $_post_cats as $_one_cat ) {
275
+ $dataLayer['pageCategory'][] = $_one_cat->slug;
276
+ }
277
+ }
278
+
279
+ if ( ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHORID ] ) && ( is_author() ) ) {
280
+ global $authordata;
281
+ $dataLayer['pagePostAuthorID'] = isset( $authordata->ID ) ? $authordata->ID : 0;
282
+ }
283
+
284
+ if ( ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_AUTHOR ] ) && ( is_author() ) ) {
285
+ $dataLayer['pagePostAuthor'] = get_the_author();
286
+ }
287
+ }
288
+
289
+ if ( is_search() ) {
290
+ $dataLayer['siteSearchTerm'] = get_search_query();
291
+ $dataLayer['siteSearchFrom'] = '';
292
+ if ( ! empty( $_SERVER['HTTP_REFERER'] ) ) {
293
+ $referer_url_parts = explode( '?', $_SERVER['HTTP_REFERER'] );
294
+ if ( count( $referer_url_parts ) > 1 ) {
295
+ $dataLayer['siteSearchFrom'] = $referer_url_parts[0] . '?' . rawurlencode( $referer_url_parts[1] );
296
+ } else {
297
+ $dataLayer['siteSearchFrom'] = $referer_url_parts[0];
298
+ }
299
+ }
300
+ $dataLayer['siteSearchResults'] = $wp_query->post_count;
301
+ }
302
+
303
+ if ( is_front_page() && $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
304
+ $dataLayer['pagePostType'] = 'frontpage';
305
+ }
306
+
307
+ if ( ! is_front_page() && is_home() && $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTTYPE ] ) {
308
+ $dataLayer['pagePostType'] = 'bloghome';
309
+ }
310
+
311
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_BROWSERDATA ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_OSDATA ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_DEVICEDATA ] ) {
312
+ spl_autoload_register(
313
+ function( $class ) {
314
+ $class_parts = explode( '\\', $class );
315
+ if ( 'WhichBrowser' == $class_parts[0] ) {
316
+ include dirname( __FILE__ ) . '/../integration/whichbrowser/' . str_replace( array( 'WhichBrowser', '\\' ), array( 'src', '/' ), $class ) . '.php';
317
+ }
318
+ }
319
+ );
320
+
321
+ require_once dirname( __FILE__ ) . '/../integration/whichbrowser/src/Parser.php';
322
+
323
+ $gtp4wp_headers = getallheaders();
324
+ if ( ( false === $gtp4wp_headers ) && isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
325
+ $gtp4wp_headers = $_SERVER['HTTP_USER_AGENT'];
326
+ }
327
+ if ( false !== $gtp4wp_headers ) {
328
+ $detected = new WhichBrowser\Parser( $gtp4wp_headers );
329
+
330
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_BROWSERDATA ] ) {
331
+ $dataLayer['browserName'] = isset( $detected->browser->name ) ? $detected->browser->name : '';
332
+ $dataLayer['browserVersion'] = isset( $detected->browser->version->value ) ? $detected->browser->version->value : '';
333
+
334
+ $dataLayer['browserEngineName'] = isset( $detected->engine->name ) ? $detected->engine->name : '';
335
+ $dataLayer['browserEngineVersion'] = isset( $detected->engine->version->value ) ? $detected->engine->version->value : '';
336
+ }
337
+
338
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_OSDATA ] ) {
339
+ $dataLayer['osName'] = isset( $detected->os->name ) ? $detected->os->name : '';
340
+ $dataLayer['osVersion'] = isset( $detected->os->version->value ) ? $detected->os->version->value : '';
341
+ }
342
+
343
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_DEVICEDATA ] ) {
344
+ $dataLayer['deviceType'] = isset( $detected->device->type ) ? $detected->device->type : '';
345
+ $dataLayer['deviceManufacturer'] = isset( $detected->device->manufacturer ) ? $detected->device->manufacturer : '';
346
+ $dataLayer['deviceModel'] = isset( $detected->device->model ) ? $detected->device->model : '';
347
+ }
348
+ }
349
+ }
350
+
351
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTCOUNT ] ) {
352
+ $dataLayer['postCountOnPage'] = (int) $wp_query->post_count;
353
+ $dataLayer['postCountTotal'] = (int) $wp_query->found_posts;
354
+ }
355
+
356
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTID ] && is_singular() === true ) {
357
+ $dataLayer['postID'] = (int) get_the_ID();
358
+ }
359
+
360
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_POSTFORMAT ] && is_singular() === true ) {
361
+ $dataLayer['postFormat'] = get_post_format() ?: 'standard';
362
+ }
363
+
364
+ if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] > 0 ) {
365
+ $_gtmrestrictlistitems = array();
366
+
367
+ // because of security reasons, we loop through each stored entity in the options and validate them
368
+ // to make sure nobody has entered some 'funny' item manually
369
+ $valid_entity_ids = array_merge(
370
+ array_keys( $gtm4wp_entity_ids[ 'tags' ] ),
371
+ array_keys( $gtm4wp_entity_ids[ 'triggers' ] ),
372
+ array_keys( $gtm4wp_entity_ids[ 'variables' ] )
373
+ );
374
+ foreach( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_STATUS ] as $listed_entity ) {
375
+ if ( in_array( $listed_entity, $valid_entity_ids ) ) {
376
+ $_gtmrestrictlistitems[] = $listed_entity;
377
+ }
378
+ }
379
+
380
+ $_gtmwhitelist = array();
381
+ $_gtmblacklist = array();
382
+ if ( $gtm4wp_options[ GTM4WP_OPTION_BLACKLIST_ENABLE ] == 1 ) {
383
+ $_gtmblacklist = array_merge( $_gtmblacklist, $_gtmrestrictlistitems );
384
+ } else {
385
+ $_gtmwhitelist = array_merge( $_gtmwhitelist, $_gtmrestrictlistitems );
386
+ }
387
+
388
+ $dataLayer['gtm.whitelist'] = $_gtmwhitelist;
389
+ $dataLayer['gtm.blacklist'] = $_gtmblacklist;
390
+ }
391
+
392
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOCF ] && isset( $_SERVER['HTTP_CF_IPCOUNTRY'] ) ) {
393
+ $dataLayer['geoCloudflareCountryCode'] = $_SERVER['HTTP_CF_IPCOUNTRY'];
394
+ }
395
+
396
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
397
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) {
398
+ $dataLayer['weatherCategory'] = __( '(no weather data available)', 'duracelltomi-google-tag-manager' );
399
+ $dataLayer['weatherDescription'] = __( '(no weather data available)', 'duracelltomi-google-tag-manager' );
400
+ $dataLayer['weatherTemp'] = 0;
401
+ $dataLayer['weatherPressure'] = 0;
402
+ $dataLayer['weatherWindSpeed'] = 0;
403
+ $dataLayer['weatherWindDeg'] = 0;
404
+ $dataLayer['weatherDataStatus'] = 'Initialized with empty data';
405
+ }
406
+
407
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
408
+ $dataLayer['geoCountryCode'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
409
+ $dataLayer['geoCountryName'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
410
+ $dataLayer['geoRegionCode'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
411
+ $dataLayer['geoRegionName'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
412
+ $dataLayer['geoCity'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
413
+ $dataLayer['geoZipcode'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
414
+ $dataLayer['geoLatitude'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
415
+ $dataLayer['geoLongitude'] = __( '(no geo data available)', 'duracelltomi-google-tag-manager' );
416
+ }
417
+
418
+ $client_ip = gtm4wp_get_user_ip();
419
+
420
+ if ( '' !== $client_ip ) {
421
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] ) {
422
+ $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) );
423
+
424
+ if ( false !== $weatherdata ) {
425
+ $dataLayer['weatherCategory'] = $weatherdata->weather[0]->main;
426
+ $dataLayer['weatherDescription'] = $weatherdata->weather[0]->description;
427
+ $dataLayer['weatherTemp'] = $weatherdata->main->temp;
428
+ $dataLayer['weatherPressure'] = $weatherdata->main->pressure;
429
+ $dataLayer['weatherWindSpeed'] = $weatherdata->wind->speed;
430
+ $dataLayer['weatherWindDeg'] = ( isset($weatherdata->wind->deg) ? $weatherdata->wind->deg : '' );
431
+ $dataLayer['weatherFullWeatherData'] = $weatherdata;
432
+ $dataLayer['weatherDataStatus'] = 'Read from cache';
433
+ } else {
434
+ $dataLayer['weatherDataStatus'] = 'No weather data in cache (' . esc_attr( $client_ip ) . ')';
435
+ }
436
+ }
437
+
438
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
439
+ $geodata = get_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ) );
440
+
441
+ if ( false !== $geodata ) {
442
+ $dataLayer['geoFullGeoData'] = $geodata;
443
+
444
+ if ( isset( $geodata->latitude ) ) {
445
+ $dataLayer['geoCountryCode'] = $geodata->country_code;
446
+ $dataLayer['geoCountryName'] = $geodata->country_name;
447
+ $dataLayer['geoRegionCode'] = $geodata->region_code;
448
+ $dataLayer['geoRegionName'] = $geodata->region_name;
449
+ $dataLayer['geoCity'] = $geodata->city;
450
+ $dataLayer['geoZipcode'] = $geodata->zip;
451
+ $dataLayer['geoLatitude'] = $geodata->latitude;
452
+ $dataLayer['geoLongitude'] = $geodata->longitude;
453
+ }
454
+ }
455
+ }
456
+ }
457
+ }
458
+
459
+ return $dataLayer;
460
+ }
461
+
462
+ function gtm4wp_wp_loaded() {
463
+ global $gtm4wp_options;
464
+
465
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHER ] || $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEO ] ) {
466
+ $client_ip = gtm4wp_get_user_ip();
467
+ $geodata = get_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ) );
468
+
469
+ if ( false === $geodata ) {
470
+ $gtm4wp_geodata = @wp_remote_get( sprintf( 'http://api.ipstack.com/%s?access_key=%s&format=1', urlencode( $client_ip ), $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_MISCGEOAPI ] ) );
471
+
472
+ if ( is_array( $gtm4wp_geodata ) && ( 200 == $gtm4wp_geodata['response']['code'] ) ) {
473
+ $gtm4wp_geodata = @json_decode( $gtm4wp_geodata['body'] );
474
+
475
+ if ( is_object( $gtm4wp_geodata ) ) {
476
+ set_transient( 'gtm4wp-geodata-' . esc_attr( $client_ip ), $gtm4wp_geodata, 60 * 60 );
477
+
478
+ $weatherdata = get_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ) );
479
+ if ( false === $weatherdata && isset( $gtm4wp_geodata->latitude ) ) {
480
+
481
+ $weatherdata = wp_remote_get( 'http://api.openweathermap.org/data/2.5/weather?appid=' . $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHEROWMAPI ] . '&lat=' . $gtm4wp_geodata->latitude . '&lon=' . $gtm4wp_geodata->longitude . '&units=' . ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_WEATHERUNITS ] == 0 ? 'metric' : 'imperial' ) );
482
+
483
+ if ( is_array( $weatherdata ) && ( 200 == $weatherdata['response']['code'] ) ) {
484
+ $weatherdata = @json_decode( $weatherdata['body'] );
485
+
486
+ if ( is_object( $weatherdata ) ) {
487
+ set_transient( 'gtm4wp-weatherdata-' . esc_attr( $client_ip ), $weatherdata, 60 * 60 );
488
+ setcookie( 'gtm4wp_last_weatherstatus', 'Weather data loaded.' );
489
+ } else {
490
+ setcookie( 'gtm4wp_last_weatherstatus', 'Openweathermap.org did not return processable data: ' . var_export( $weatherdata, true ) );
491
+ }
492
+ } else {
493
+ if ( is_wp_error( $weatherdata ) ) {
494
+ setcookie( 'gtm4wp_last_weatherstatus', 'Openweathermap.org request error: ' . $weatherdata->get_error_message() );
495
+ } else {
496
+ setcookie( 'gtm4wp_last_weatherstatus', 'Openweathermap.org returned status code: ' . $weatherdata['response']['code'] );
497
+ }
498
+ }
499
+ }
500
+ } else {
501
+ setcookie( 'gtm4wp_last_weatherstatus', 'ipstack.com did not return lat-lng data: ' . var_export( $gtm4wp_geodata, true ) );
502
+ }
503
+ } else {
504
+ if ( is_wp_error( $gtm4wp_geodata ) ) {
505
+ setcookie( 'gtm4wp_last_weatherstatus', 'ipstack.com request error: ' . $gtm4wp_geodata->get_error_message() );
506
+ } else {
507
+ setcookie( 'gtm4wp_last_weatherstatus', 'ipstack.com returned status code: ' . $gtm4wp_geodata['response']['code'] );
508
+ }
509
+ }
510
+ }
511
+ }
512
+ }
513
+
514
+ function gtm4wp_get_the_gtm_tag() {
515
+ global $gtm4wp_options, $gtm4wp_datalayer_name, $gtm4wp_container_code_written;
516
+
517
+ $_gtm_tag = '
518
+ <!-- Google Tag Manager (noscript) -->';
519
+
520
+ if ( GTM4WP_PLACEMENT_OFF == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
521
+ $gtm4wp_container_code_written = true;
522
+ }
523
+
524
+ if ( ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != '' ) && ( ! $gtm4wp_container_code_written ) ) {
525
+ $_gtm_codes = explode( ',', str_replace( array( ';', ' ' ), array( ',', '' ), $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) );
526
+
527
+ if ( ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] ) && ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] ) ) {
528
+ $_gtm_env = '&gtm_auth=' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] . '&gtm_preview=' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] . '&gtm_cookies_win=x';
529
+ } else {
530
+ $_gtm_env = '';
531
+ }
532
+
533
+ foreach ( $_gtm_codes as $one_gtm_code ) {
534
+ $_gtm_tag .= '
535
+ <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=' . $one_gtm_code . $_gtm_env . '"
536
+ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>';
537
+ }
538
+
539
+ $_gtm_tag .= '
540
+ <!-- End Google Tag Manager (noscript) -->';
541
+
542
+ $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
543
+ $gtm4wp_container_code_written = true;
544
+ }
545
+
546
+ return $_gtm_tag;
547
+ }
548
+
549
+ function gtm4wp_the_gtm_tag() {
550
+ echo gtm4wp_get_the_gtm_tag();
551
+ }
552
+
553
+ function gtm4wp_enqueue_scripts() {
554
+ global $gtm4wp_options, $gtp4wp_plugin_url;
555
+
556
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WPCF7 ] ) {
557
+ $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_INTEGRATE_WPCF7, false );
558
+ wp_enqueue_script( 'gtm4wp-contact-form-7-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-contact-form-7-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
559
+ }
560
+
561
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_FORMMOVE ] ) {
562
+ $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_EVENTS_FORMMOVE, false );
563
+ wp_enqueue_script( 'gtm4wp-form-move-tracker', $gtp4wp_plugin_url . 'js/gtm4wp-form-move-tracker.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
564
+ }
565
+
566
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_YOUTUBE ] ) {
567
+ require_once dirname( __FILE__ ) . '/../integration/youtube.php';
568
+ }
569
+
570
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_VIMEO ] ) {
571
+ require_once dirname( __FILE__ ) . '/../integration/vimeo.php';
572
+ }
573
+
574
+ if ( $gtm4wp_options[ GTM4WP_OPTION_EVENTS_SOUNDCLOUD ] ) {
575
+ require_once dirname( __FILE__ ) . '/../integration/soundcloud.php';
576
+ }
577
+
578
+ if ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_ENABLED ] ) {
579
+ $in_footer = apply_filters( 'gtm4wp_' . GTM4WP_OPTION_SCROLLER_ENABLED, false );
580
+ wp_enqueue_script( 'gtm4wp-scroll-tracking', $gtp4wp_plugin_url . 'js/analytics-talk-content-tracking.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
581
+ }
582
+ }
583
+
584
+ function gtm4wp_wp_footer() {
585
+ global $gtm4wp_options;
586
+
587
+ if ( GTM4WP_PLACEMENT_FOOTER == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) {
588
+ gtm4wp_the_gtm_tag();
589
+ }
590
+ }
591
+
592
+ function gtm4wp_wp_body_open() {
593
+ global $gtm4wp_options;
594
+
595
+ if ( ( GTM4WP_PLACEMENT_BODYOPEN == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) || ( GTM4WP_PLACEMENT_BODYOPEN_AUTO == $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) ) {
596
+ gtm4wp_the_gtm_tag();
597
+ }
598
+ }
599
+
600
+ function gtm4wp_filter_visitor_keys( $dataLayer ) {
601
+ foreach ( $dataLayer as $dl_key => $dl_value ) {
602
+ if ( strpos( $dl_key, 'visitor' ) !== false ) {
603
+ unset( $dataLayer[ $dl_key ] );
604
+ }
605
+ }
606
+
607
+ return $dataLayer;
608
+ }
609
+
610
+ /**
611
+ * GTM4WP global JS variables WordPress filter
612
+ *
613
+ * @author Vincent Koc <https://github.com/koconder/>
614
+ * @link https://github.com/duracelltomi/gtm4wp/issues/34
615
+ * @return mixed returns the
616
+ */
617
+ function gtm4wp_add_global_vars( $vars, $return = false ) {
618
+ if ( ! $return ) {
619
+ if ( function_exists( $vars ) ) {
620
+ $vars = $vars();
621
+ }
622
+ $GLOBALS['gtm4wp_datalayer_globalvars'] = $GLOBALS['gtm4wp_datalayer_globalvars'] . ' ' . $vars;
623
+ }
624
+ return $GLOBALS['gtm4wp_datalayer_globalvars'];
625
+ }
626
+
627
+ function gtm4wp_wp_header_top( $echo = true ) {
628
+ global $gtm4wp_options, $gtm4wp_datalayer_name;
629
+
630
+ $has_html5_support = current_theme_supports( 'html5' );
631
+
632
+ $_gtm_top_content = '
633
+ <!-- Google Tag Manager for WordPress by gtm4wp.com -->
634
+ <script data-cfasync="false" data-pagespeed-no-defer' . ( $has_html5_support ? ' type="text/javascript"' : '' ) . '>//<![CDATA[
635
+ var gtm4wp_datalayer_name = "' . $gtm4wp_datalayer_name . '";
636
+ var ' . $gtm4wp_datalayer_name . ' = ' . $gtm4wp_datalayer_name . ' || [];';
637
+
638
+ // Load in the global variables from gtm4wp_add_global_vars / GTM4WP_WPACTION_ADDGLOBALVARS filter
639
+ $_gtm_top_content .= apply_filters( GTM4WP_WPACTION_ADDGLOBALVARS, '', true );
640
+
641
+ if ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_ENABLED ] ) {
642
+ $_gtm_top_content .= '
643
+
644
+ var gtm4wp_scrollerscript_debugmode = ' . ( $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_DEBUGMODE ] ? 'true' : 'false' ) . ';
645
+ var gtm4wp_scrollerscript_callbacktime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_CALLBACKTIME ] . ';
646
+ var gtm4wp_scrollerscript_readerlocation = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_DISTANCE ] . ';
647
+ var gtm4wp_scrollerscript_contentelementid = "' . $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_CONTENTID ] . '";
648
+ var gtm4wp_scrollerscript_scannertime = ' . (int) $gtm4wp_options[ GTM4WP_OPTION_SCROLLER_READERTIME ] . ';';
649
+ }
650
+
651
+ $_gtm_top_content .= '
652
+ //]]>
653
+ </script>
654
+ <!-- End Google Tag Manager for WordPress by gtm4wp.com -->';
655
+
656
+ if ( ! gtm4wp_amp_running() ) {
657
+ if ( $echo ) {
658
+ echo $_gtm_top_content;
659
+ } else {
660
+ return $_gtm_top_content;
661
+ }
662
+ }
663
+ }
664
+
665
+ function gtm4wp_wp_header_begin( $echo = true ) {
666
+ global $gtm4wp_datalayer_name, $gtm4wp_datalayer_json, $gtm4wp_options, $woocommerce;
667
+
668
+ $has_html5_support = current_theme_supports( 'html5' );
669
+
670
+ $_gtm_header_content = '
671
+ <!-- Google Tag Manager for WordPress by gtm4wp.com -->
672
+ <script data-cfasync="false" data-pagespeed-no-defer' . ( $has_html5_support ? ' type="text/javascript"' : '' ) . '>//<![CDATA[';
673
+
674
+ if ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != '' ) {
675
+ $gtm4wp_datalayer_data = array();
676
+ $gtm4wp_datalayer_data = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_DATALAYER, $gtm4wp_datalayer_data );
677
+
678
+ if ( $gtm4wp_options[ GTM4WP_OPTION_INCLUDE_REMARKETING ] ) {
679
+ // add Google Ads remarketing tags as suggested here:
680
+ // https://support.google.com/tagmanager/answer/3002580?hl=en
681
+ add_filter( GTM4WP_WPFILTER_COMPILE_REMARKTING, 'gtm4wp_filter_visitor_keys' );
682
+ $gtm4wp_remarketing_tags = (array) apply_filters( GTM4WP_WPFILTER_COMPILE_REMARKTING, $gtm4wp_datalayer_data );
683
+
684
+ $_gtm_header_content .= "\nvar google_tag_params = ";
685
+ $_gtm_header_content .= json_encode( $gtm4wp_remarketing_tags );
686
+ $_gtm_header_content .= ';';
687
+ $gtm4wp_datalayer_data['google_tag_params'] = '-~-window.google_tag_params-~-';
688
+ }
689
+
690
+ if ( version_compare( PHP_VERSION, '5.4.0' ) >= 0 ) {
691
+ $gtm4wp_datalayer_json = json_encode( $gtm4wp_datalayer_data, JSON_UNESCAPED_UNICODE );
692
+ } else {
693
+ $gtm4wp_datalayer_json = json_encode( $gtm4wp_datalayer_data );
694
+ }
695
+
696
+ // Clean up and then push datalayer to AMP
697
+ $gtm4wp_datalayer_json = str_replace(
698
+ array( '"-~-', '-~-"' ),
699
+ array( '', '' ),
700
+ str_replace( '–', '-', $gtm4wp_datalayer_json )
701
+ );
702
+
703
+ $_gtm_header_content .= '
704
+ var dataLayer_content = ' . $gtm4wp_datalayer_json . ';';
705
+
706
+ // fire WooCommerce order double tracking protection only if WooCommerce is active and user is on the order received page
707
+ if ( isset( $gtm4wp_options ) && ( $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ] || $gtm4wp_options[ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ] ) && isset( $woocommerce ) && is_order_received_page() ) {
708
+
709
+ $_gtm_header_content .= '
710
+ // if dataLayer contains ecommerce purchase data, check whether it has been already tracked
711
+ if ( dataLayer_content.transactionId || ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.purchase ) ) {
712
+ // read order id already tracked from cookies
713
+ var gtm4wp_orderid_tracked = "";
714
+
715
+ if ( !window.localStorage ) {
716
+ var gtm4wp_cookie = "; " + document.cookie;
717
+ var gtm4wp_cookie_parts = gtm4wp_cookie.split( "; gtm4wp_orderid_tracked=" );
718
+ if ( gtm4wp_cookie_parts.length == 2 ) {
719
+ gtm4wp_orderid_tracked = gtm4wp_cookie_parts.pop().split(";").shift();
720
+ }
721
+ } else {
722
+ window.localStorage.getItem( "gtm4wp_orderid_tracked" );
723
+ }
724
+
725
+ // check enhanced ecommerce
726
+ if ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.purchase ) {
727
+ if ( gtm4wp_orderid_tracked && ( dataLayer_content.ecommerce.purchase.actionField.id == gtm4wp_orderid_tracked ) ) {
728
+ delete dataLayer_content.ecommerce.purchase;
729
+ } else {
730
+ gtm4wp_orderid_tracked = dataLayer_content.ecommerce.purchase.actionField.id;
731
+ }
732
+ }
733
+
734
+ // check app+web ecommerce
735
+ if ( dataLayer_content.ecommerce && dataLayer_content.ecommerce.items ) {
736
+ if ( gtm4wp_orderid_tracked && ( dataLayer_content.ecommerce.transaction_id == gtm4wp_orderid_tracked ) ) {
737
+ delete dataLayer_content.ecommerce.affiliation;
738
+ delete dataLayer_content.ecommerce.value;
739
+ delete dataLayer_content.ecommerce.currency;
740
+ delete dataLayer_content.ecommerce.tax;
741
+ delete dataLayer_content.ecommerce.shipping;
742
+ delete dataLayer_content.ecommerce.transaction_id;
743
+
744
+ delete dataLayer_content.ecommerce.items;
745
+ } else {
746
+ gtm4wp_orderid_tracked = dataLayer_content.ecommerce.purchase.actionField.id;
747
+ }
748
+ }
749
+
750
+ // check standard ecommerce
751
+ if ( dataLayer_content.transactionId ) {
752
+ if ( gtm4wp_orderid_tracked && ( dataLayer_content.transactionId == gtm4wp_orderid_tracked ) ) {
753
+ delete dataLayer_content.transactionId;
754
+ delete dataLayer_content.transactionDate;
755
+ delete dataLayer_content.transactionType;
756
+ delete dataLayer_content.transactionAffiliation;
757
+ delete dataLayer_content.transactionTotal;
758
+ delete dataLayer_content.transactionShipping;
759
+ delete dataLayer_content.transactionTax;
760
+ delete dataLayer_content.transactionPaymentType;
761
+ delete dataLayer_content.transactionCurrency;
762
+ delete dataLayer_content.transactionShippingMethod;
763
+ delete dataLayer_content.transactionPromoCode;
764
+ delete dataLayer_content.transactionProducts;
765
+ } else {
766
+ gtm4wp_orderid_tracked = dataLayer_content.transactionId;
767
+ }
768
+ }
769
+
770
+ if ( gtm4wp_orderid_tracked ) {
771
+ if ( !window.localStorage ) {
772
+ var gtm4wp_orderid_cookie_expire = new Date();
773
+ gtm4wp_orderid_cookie_expire.setTime( gtm4wp_orderid_cookie_expire.getTime() + (365*24*60*60*1000) );
774
+ var gtm4wp_orderid_cookie_expires_part = "expires=" + gtm4wp_orderid_cookie_expire.toUTCString();
775
+ document.cookie = "gtm4wp_orderid_tracked=" + gtm4wp_orderid_tracked + ";" + gtm4wp_orderid_cookie_expires_part + ";path=/";
776
+ } else {
777
+ window.localStorage.setItem( "gtm4wp_orderid_tracked", gtm4wp_orderid_tracked );
778
+ }
779
+ }
780
+
781
+ }';
782
+ }
783
+
784
+ $_gtm_header_content .= '
785
+ ' . $gtm4wp_datalayer_name . '.push( dataLayer_content );';
786
+ }
787
+
788
+ $_gtm_header_content .= '//]]>
789
+ </script>';
790
+
791
+ $_gtm_header_content .= apply_filters( GTM4WP_WPFILTER_AFTER_DATALAYER, '' );
792
+
793
+ if ( ( $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] != '' ) && ( GTM4WP_PLACEMENT_OFF != $gtm4wp_options[ GTM4WP_OPTION_GTM_PLACEMENT ] ) ) {
794
+ $_gtm_codes = explode( ',', str_replace( array( ';', ' ' ), array( ',', '' ), $gtm4wp_options[ GTM4WP_OPTION_GTM_CODE ] ) );
795
+
796
+ $_gtm_tag = '';
797
+ foreach ( $_gtm_codes as $one_gtm_code ) {
798
+ if ( ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] ) && ( '' != $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] ) ) {
799
+ $_gtm_env = "+'&gtm_auth=" . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_AUTH ] . '&gtm_preview=' . $gtm4wp_options[ GTM4WP_OPTION_ENV_GTM_PREVIEW ] . "&gtm_cookies_win=x'";
800
+ } else {
801
+ $_gtm_env = '';
802
+ }
803
+
804
+ $_gtm_tag .= '
805
+ <script data-cfasync="false">//<![CDATA[
806
+ (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({\'gtm.start\':
807
+ new Date().getTime(),event:\'gtm.js\'});var f=d.getElementsByTagName(s)[0],
808
+ j=d.createElement(s),dl=l!=\'dataLayer\'?\'&l=\'+l:\'\';j.async=true;j.src=
809
+ \'//www.googletagmanager.com/gtm.\'' . '+\'js?id=\'+i+dl' . $_gtm_env . ';f.parentNode.insertBefore(j,f);
810
+ })(window,document,\'script\',\'' . $gtm4wp_datalayer_name . '\',\'' . $one_gtm_code . '\');//]]>
811
+ </script>';
812
+ }
813
+
814
+ $_gtm_tag .= '
815
+ <!-- End Google Tag Manager -->';
816
+
817
+ $_gtm_tag = apply_filters( GTM4WP_WPFILTER_GETTHEGTMTAG, $_gtm_tag );
818
+ $_gtm_header_content .= $_gtm_tag;
819
+ }
820
+
821
+ $_gtm_header_content .= '
822
+ <!-- End Google Tag Manager for WordPress by gtm4wp.com -->';
823
+
824
+ if ( ! gtm4wp_amp_running() ) {
825
+ if ( $echo ) {
826
+ echo $_gtm_header_content;
827
+ } else {
828
+ return $_gtm_header_content;
829
+ }
830
+ }
831
+ }
832
+
833
+ function gtm4wp_wp_login() {
834
+ setcookie( 'gtm4wp_user_logged_in', '1', 0, '/' );
835
+ }
836
+
837
+ function gtm4wp_user_register() {
838
+ setcookie( 'gtm4wp_user_registered', '1', 0, '/' );
839
+ }
840
+
841
+ function gtm4wp_user_reg_login_script() {
842
+ global $gtp4wp_plugin_url;
843
+
844
+ $in_footer = apply_filters( 'gtm4wp_user_reg_login_script', true );
845
+ wp_enqueue_script( 'gtm4wp-user-reg-login-script', $gtp4wp_plugin_url . 'js/gtm4wp-users.js', array( 'jquery' ), GTM4WP_VERSION, $in_footer );
846
+ }
847
+
848
+ function gtm4wp_rocket_excluded_inline_js_content( $pattern ) {
849
+ $pattern[] = 'dataLayer';
850
+ $pattern[] = 'gtm4wp';
851
+
852
+ return $pattern;
853
+ }
854
+
855
+ add_action( 'wp_enqueue_scripts', 'gtm4wp_enqueue_scripts' );
856
+ $gtm4wp_header_begin_prior = 10;
857
+ if ( isset( $GLOBALS['gtm4wp_options'] ) && $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_LOADEARLY ] ) {
858
+ $gtm4wp_header_begin_prior = 2;
859
+ }
860
+ add_action( 'wp_head', 'gtm4wp_wp_header_begin', $gtm4wp_header_begin_prior, 0 );
861
+ add_action( 'wp_head', 'gtm4wp_wp_header_top', 1, 0 );
862
+ add_action( 'wp_footer', 'gtm4wp_wp_footer' );
863
+ add_action( 'wp_loaded', 'gtm4wp_wp_loaded' );
864
+ add_filter( GTM4WP_WPFILTER_COMPILE_DATALAYER, 'gtm4wp_add_basic_datalayer_data' );
865
+
866
+ // to be able to easily migrate from other Google Tag Manager plugins
867
+ add_action( 'body_open', 'gtm4wp_wp_body_open' );
868
+
869
+ // compatibility with existing themes that natively support code injection after opening body tag
870
+ add_action( 'genesis_before', 'gtm4wp_wp_body_open' ); // Genisis theme
871
+ add_action( 'generate_before_header', 'gtm4wp_wp_body_open', 0 ); // GeneratePress theme
872
+ add_action( 'elementor/page_templates/canvas/before_content', 'gtm4wp_wp_body_open' ); // Elementor
873
+ add_action( 'ct_before_builder', 'gtm4wp_wp_body_open', 0 ); // Oxygen Builder
874
+ add_action( 'fl_before_builder', 'gtm4wp_wp_body_open', 0 ); // Beaver Builder Theme
875
+
876
+ // standard WP theme support for body open tags
877
+ add_action( 'wp_body_open', 'gtm4wp_wp_body_open' );
878
+
879
+ add_filter( 'rocket_excluded_inline_js_content', 'gtm4wp_rocket_excluded_inline_js_content' ); // WP Rocket
880
+ if (
881
+ isset( $GLOBALS['gtm4wp_options'] )
882
+ && (
883
+ $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_WCTRACKCLASSICEC ]
884
+ || $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_WCTRACKENHANCEDEC ]
885
+ )
886
+ && isset( $GLOBALS['woocommerce'] )
887
+ && version_compare( WC()->version, '3.2', '>=' ) // only activate WooCommerce integration for minimum supported WooCommerce version
888
+ ) {
889
+ require_once dirname( __FILE__ ) . '/../integration/woocommerce.php';
890
+ }
891
+
892
+ if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_INTEGRATE_GOOGLEOPTIMIZEIDS ] != '' ) ) {
893
+ require_once dirname( __FILE__ ) . '/../integration/google-optimize.php';
894
+ }
895
+
896
+ if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_EVENTS_USERLOGIN ] ) ) {
897
+ add_action( 'wp_login', 'gtm4wp_wp_login' );
898
+ add_action( 'wp_enqueue_scripts', 'gtm4wp_user_reg_login_script' );
899
+ }
900
+
901
+ if ( isset( $GLOBALS['gtm4wp_options'] ) && ( $GLOBALS['gtm4wp_options'][ GTM4WP_OPTION_EVENTS_NEWUSERREG ] ) ) {
902
+ add_action( 'user_register', 'gtm4wp_user_register' );
903
+ add_action( 'wp_enqueue_scripts', 'gtm4wp_user_reg_login_script' );
904
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: https://gtm4wp.com/
4
  Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, google ads, adwords remarketing, google ads remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel, google optimize, personalisation
5
  Requires at least: 3.4.0
6
  Requires PHP: 5.6
7
- Tested up to: 5.6
8
- Stable tag: 1.11.6
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
@@ -27,25 +27,28 @@ You can also add your Google Optimize container with the [recommended code setup
27
  **Some parts of the plugin require PHP 5.6 newer.
28
  PHP 7.0 or newer is recommended.**
29
 
30
- Please note that PHP 5.6 is nearing its end of life cycle thus it is recommended to upgrade. If you are not sure which version you are using, please contact
31
- your hosting provider for support.
32
 
33
  = GTM container code placement =
34
 
35
- The original GTM container code is divided into two parts: The first part is a javascript code snippet that is added to the `<head>`
36
- section of every page of the website. This part is critical to enable all features of GTM, and this plugin helps to place this part
37
- correctly on your site. The second part is an iframe snippet that acts as a failsafe/fallback should users' JavaScript be disabled.
 
 
 
 
38
  Google recommends – for best performance – to place this code snippet directly after the opening `<body>` tag on each page.
 
39
  Albeit not ideal, it will work when placed lower in the code. This plugin provides a code placement option for the second code snippet.
40
- Inherently, Wordpress does not offer a straight-forward solution to achieve this, however Yaniv Friedensohn showed me a solution
41
- that works with most themes without modification:
42
 
43
- http://www.affectivia.com/blog/placing-the-google-tag-manager-in-wordpress-after-the-body-tag/
 
 
44
 
45
- I added this solution to the plugin, currently as an experimental option.
 
46
 
47
- Sites using the Genesis Framework should choose the "Custom" placement option. No theme modification is needed for this theme
48
- however, the Google Tag Manager container code will be added automatically.
49
 
50
  = Basic data included =
51
 
@@ -53,21 +56,22 @@ however, the Google Tag Manager container code will be added automatically.
53
  * post/page dates
54
  * post/page category names
55
  * post/page tag names
56
- * post/page author ID and names
57
  * post/page ID
58
  * post types
59
  * post count on the current page + in the current category/tag/taxonomy
 
60
  * logged in status
61
  * logged in user role
62
  * logged in user ID (to track cross device behaviour in Google Analytics)
63
  * logged in user email address (to comply with [GTM terms of service](https://www.google.com/analytics/tag-manager/use-policy/) do not pass this on to Google tags)
 
64
  * site search data
65
  * site name and id (for WordPress multisite instances)
 
66
 
67
  = Browser / OS / Device data =
68
 
69
- (beta)
70
-
71
  * browser data (name, version, engine)
72
  * OS data (name, version)
73
  * device data (type, manufacturer, model)
@@ -135,9 +139,11 @@ http://cutroni.com/blog/2012/02/21/advanced-content-tracking-with-google-analyti
135
  Google Tag Manager for WordPress can add each dataLayer variable as a Google Ads remarketing custom parameter list.
136
  This enables you to build sophisticated remarketing lists.
137
 
138
- = Blacklist & Whitelist Tag Manager tags and variables =
 
 
139
 
140
- To increase website security, you have the option to white- and blacklist tags/variables.
141
  You can prevent specific tags from firing or the use of certain variable types regardless of your GTM setup.
142
 
143
  If the Google account associated with your GTM account is being hacked, an attacker could easily
@@ -150,12 +156,13 @@ Google Tag Manager for WordPress integrates with several popular plugins. More i
150
 
151
  * Contact Form 7: fire an event upon successful form submission
152
  * WooCommerce:
153
- * Classic e-commerce:
154
  * fire an event when visitors add products to their cart
155
  * capture transaction data to be passed to your ad platforms and/or Analytics
156
  * capture necessary remarketing parameters for Google Ads Dynamic Remarketing
157
- * Enhanced e-commerce (beta):
158
- * implementation of [Enhanced E-commerce](https://developers.google.com/tag-manager/enhanced-ecommerce)
 
159
  * Does not support promotions since WooCommerce does not have such a feature (yet)
160
  * Does not support refunds
161
 
@@ -212,41 +219,6 @@ use the corresponding dataLayer variable (visitorType) and an exclude filter in
212
 
213
  https://gtm4wp.com/how-to-articles/how-to-exclude-admin-users-from-being-tracked/
214
 
215
- = How do I put the Google Tag Manager container code next to the opening body tag? =
216
-
217
- By default the plugin places the iframe tag in the footer of the page. To change it, go to the plugin's admin section
218
- and select "Custom" from the placement settings. Unless you use the Genesis Framework theme, you will also need to
219
- edit your template files.
220
-
221
- Go to `wp-content/plugins/themes/<your theme dir>` and edit `header.php`.
222
- In most cases you will find the opening `<body>` tag here. If you can not find it, contact the author of the theme and
223
- ask for instructions.
224
-
225
- Create a new line right below the `body` tag and insert this line of code:
226
-
227
- `<?php if ( function_exists( 'gtm4wp_the_gtm_tag' ) ) { gtm4wp_the_gtm_tag(); } ?>`
228
-
229
- Be careful not to place this line within any `<div>`, `<p>`, `<header>`, `<article>` tags.
230
- It may break your theme.
231
-
232
- There is also an option named "Codeless" which attempts to place the container code correctly
233
- without additional theme tweaks. It may or may not work, this is an experimental feature, use it accordingly.
234
-
235
- = Why can't this plugin insert the container snippet after the opening body tag automatically? =
236
-
237
- Currently WordPress has two 'commands' or 'hooks' that a programmer can use: one for the `<head>` section and
238
- one for the bottom of `<body>`. There is no way to inject any content after the opening `<body>` tag without manually
239
- editing your template files. Fortunately some theme authors already resolved this so in some cases you do not need
240
- to edit your template.
241
-
242
- I suggest that try the Custom placement (easiest) and use Google Tag Assistant Chrome browser extension to check
243
- whether the container code is placed as expected. If it shows an error, go ahead and edit your theme manually.
244
-
245
- = Facebook like/share/send button events do not fire for me, why? =
246
-
247
- It is a Facebook limitation. Click event tracking is only available for html5/xfbml buttons.
248
- If you or your social plugin inserts the Facebook buttons using IFRAMEs (like Sociable), it is not possible to track likes.
249
-
250
  == Screenshots ==
251
 
252
  1. Admin panel
@@ -258,6 +230,21 @@ If you or your social plugin inserts the Facebook buttons using IFRAMEs (like So
258
 
259
  == Changelog ==
260
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  = 1.11.6 =
262
 
263
  * Fixed: do not track hidden products in the cart in WooCommerce shops
@@ -678,6 +665,10 @@ Please report all bugs found in my plugin using the [contact form on my website]
678
 
679
  == Upgrade Notice ==
680
 
 
 
 
 
681
  = 1.11.6 =
682
 
683
  Bugfix release
4
  Tags: google tag manager, tag manager, gtm, google, adwords, google adwords, google ads, adwords remarketing, google ads remarketing, remarketing, google analytics, analytics, facebook ads, facebook remarketing, facebook pixel, google optimize, personalisation
5
  Requires at least: 3.4.0
6
  Requires PHP: 5.6
7
+ Tested up to: 5.7
8
+ Stable tag: 1.12
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl.html
11
 
27
  **Some parts of the plugin require PHP 5.6 newer.
28
  PHP 7.0 or newer is recommended.**
29
 
30
+ Please note that PHP versions 7.2 or older already reached their end of life cycle thus it is recommended to upgrade. If you are not sure which version you are using, please contact your hosting provider for support.
 
31
 
32
  = GTM container code placement =
33
 
34
+ The original GTM container code is divided into two parts:
35
+
36
+ The first part is a javascript code snippet that is added to the `<head>` section of every page of the website.
37
+ This part is critical to enable all features of GTM, and this plugin helps to place this part
38
+ correctly on your site.
39
+
40
+ The second part is an iframe snippet that acts as a failsafe/fallback should users' JavaScript be disabled.
41
  Google recommends – for best performance – to place this code snippet directly after the opening `<body>` tag on each page.
42
+
43
  Albeit not ideal, it will work when placed lower in the code. This plugin provides a code placement option for the second code snippet.
 
 
44
 
45
+ If your WordPress theme is compatible with the additions of WordPress 5.2 then this plugin will place this second code to the right place.
46
+ Users of the Genisis theme, GeneratePress theme, Elementor, Oxygen Builder and Beaver Builder Theme will also have this placed correctly.
47
+ To utilize this, use the "Codeless" placement option.
48
 
49
+ All other users can place this second code snippet using a custom PHP code ("Custom" placement option) or select the so called "Footer" option to
50
+ add the code lower in the code (it is not the recommended way but will work)
51
 
 
 
52
 
53
  = Basic data included =
54
 
56
  * post/page dates
57
  * post/page category names
58
  * post/page tag names
59
+ * post/page author ID and name
60
  * post/page ID
61
  * post types
62
  * post count on the current page + in the current category/tag/taxonomy
63
+ * custom terms associated with any post type
64
  * logged in status
65
  * logged in user role
66
  * logged in user ID (to track cross device behaviour in Google Analytics)
67
  * logged in user email address (to comply with [GTM terms of service](https://www.google.com/analytics/tag-manager/use-policy/) do not pass this on to Google tags)
68
+ * logger in user creation date
69
  * site search data
70
  * site name and id (for WordPress multisite instances)
71
+ * IP address of the visitor (please use the explicit consent of the visitor to utilize this)
72
 
73
  = Browser / OS / Device data =
74
 
 
 
75
  * browser data (name, version, engine)
76
  * OS data (name, version)
77
  * device data (type, manufacturer, model)
139
  Google Tag Manager for WordPress can add each dataLayer variable as a Google Ads remarketing custom parameter list.
140
  This enables you to build sophisticated remarketing lists.
141
 
142
+ NOTE: the current implementation can be used to populate Google ads in an old fashioned way, codes will be updated soon in this plugin.
143
+
144
+ = Blacklist & Whitelist Tag Manager tags, triggers and variables =
145
 
146
+ To increase website security, you have the option to white- and blacklist tags/triggers/variables.
147
  You can prevent specific tags from firing or the use of certain variable types regardless of your GTM setup.
148
 
149
  If the Google account associated with your GTM account is being hacked, an attacker could easily
156
 
157
  * Contact Form 7: fire an event upon successful form submission
158
  * WooCommerce:
159
+ * Classic e-commerce (deprecated):
160
  * fire an event when visitors add products to their cart
161
  * capture transaction data to be passed to your ad platforms and/or Analytics
162
  * capture necessary remarketing parameters for Google Ads Dynamic Remarketing
163
+ * Enhanced e-commerce:
164
+ * implementation of [Enhanced E-commerce GA3](https://developers.google.com/tag-manager/enhanced-ecommerce)
165
+ * implementation of [Enhanced E-commerce GA4](https://developers.google.com/tag-manager/ecommerce-ga4)
166
  * Does not support promotions since WooCommerce does not have such a feature (yet)
167
  * Does not support refunds
168
 
219
 
220
  https://gtm4wp.com/how-to-articles/how-to-exclude-admin-users-from-being-tracked/
221
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  == Screenshots ==
223
 
224
  1. Admin panel
230
 
231
  == Changelog ==
232
 
233
+ = 1.12 =
234
+
235
+ WARNING!
236
+ If you are using the blacklist/whitelist feature of the plugin, review these options after upgrade as they could break because of a fundamental rework of this feature.
237
+
238
+ * Added: support for Google Analytics 4 version of ecommerce data layer
239
+ * Fixed: safer IP address validation in geo and weather data features
240
+ * Updated: removed deprecated events: download links, email links, social links -> such can be now tracked with native Google Tag Manager triggers
241
+ * Updated: removed support for WooCommerce versions before v3.2
242
+ * Updated: 'Blacklist tags' tab renamed to 'Security'
243
+ * Updated: complete rework of blacklist/whitelist feature to use the latest tag/trigger/variable list of Google
244
+ * Deprecated: classic ecommerce tracking will be removed later this year, please upgrade to enhanced ecommerce tracking
245
+ * Deprecated: standard Google Ads remarketing variable will be removed soon as the Google Ads remarketing tag template can easily use any of your Google Tag Manager variables
246
+ * Deprecated: the old fashioned way of using Google Ads remarketing with the ecomm_ prefixed data layer variables will be removed soon. Instructions for upgrade will be published on gtm4wp.com once this feature gets updated in an upcoming plugin version
247
+
248
  = 1.11.6 =
249
 
250
  * Fixed: do not track hidden products in the cart in WooCommerce shops
665
 
666
  == Upgrade Notice ==
667
 
668
+ = 1.12 =
669
+
670
+ Removed several deprecated features, dropped support for WooCommerce versions before 3.2, introduced GA4 data layer variables, deprecated classic ecommerce and Google Ads remarketing varibale
671
+
672
  = 1.11.6 =
673
 
674
  Bugfix release