@@ -14,12 +14,12 @@ public function register(): void
14
14
15
15
public function enqueueScripts (): void
16
16
{
17
- $ apiKey = get_field ('civic_cookie_control_api_key ' , 'option ' );
18
- $ productType = get_field ('civic_cookie_control_product_type ' , 'option ' );
19
- $ googleAnalyticsId = get_field ('google_analytics_id ' , 'option ' );
20
- $ ga4Id = get_field ('ga_4_id ' , 'option ' );
21
- $ gtmId = get_field ('google_analytics_gtm ' , 'option ' );
22
- $ hotjarId = get_field ('hotjar_id ' , 'option ' );
17
+ $ apiKey = trim ( get_field ('civic_cookie_control_api_key ' , 'option ' ) );
18
+ $ productType = trim ( get_field ('civic_cookie_control_product_type ' , 'option ' ) );
19
+ $ googleAnalyticsId = trim ( get_field ('google_analytics_id ' , 'option ' ) );
20
+ $ ga4Id = trim ( get_field ('ga_4_id ' , 'option ' ) );
21
+ $ gtmId = trim ( get_field ('google_analytics_gtm ' , 'option ' ) );
22
+ $ hotjarId = trim ( get_field ('hotjar_id ' , 'option ' ) );
23
23
if ($ apiKey && $ productType ) {
24
24
wp_enqueue_script ('civicCookieControl ' , 'https://cc.cdn.civiccomputing.com/9/cookieControl-9.x.min.js ' );
25
25
wp_enqueue_script ('civicCookieControlDefaultAnalytics ' , plugins_url ('/assets/js/analytics.js ' , dirname (__FILE__ )), ['civicCookieControl ' ]);
@@ -41,19 +41,19 @@ public function enqueueStyles(): void
41
41
42
42
public function addGA4 (): void
43
43
{
44
- $ apiKey = get_field ('civic_cookie_control_api_key ' , 'option ' );
45
- $ productType = get_field ('civic_cookie_control_product_type ' , 'option ' );
46
- $ ga4Id = get_field ('ga_4_id ' , 'option ' );
44
+ $ apiKey = trim ( get_field ('civic_cookie_control_api_key ' , 'option ' ) );
45
+ $ productType = trim ( get_field ('civic_cookie_control_product_type ' , 'option ' ) );
46
+ $ ga4Id = trim ( get_field ('ga_4_id ' , 'option ' ) );
47
47
if ($ apiKey && $ productType && $ ga4Id ) {
48
48
printf ('<script async id="awc_gtag" src="https://www.googletagmanager.com/gtag/js?id=%s"></script> ' , esc_attr ($ ga4Id ));
49
49
}
50
50
}
51
51
52
52
public function addGTM (): void
53
53
{
54
- $ apiKey = get_field ('civic_cookie_control_api_key ' , 'option ' );
55
- $ productType = get_field ('civic_cookie_control_product_type ' , 'option ' );
56
- $ gtmId = get_field ('google_analytics_gtm ' , 'option ' );
54
+ $ apiKey = trim ( get_field ('civic_cookie_control_api_key ' , 'option ' ) );
55
+ $ productType = trim ( get_field ('civic_cookie_control_product_type ' , 'option ' ) );
56
+ $ gtmId = trim ( get_field ('google_analytics_gtm ' , 'option ' ) );
57
57
if ($ apiKey && $ productType && $ gtmId ) {
58
58
printf ("<script>window.dataLayer = window.dataLayer || []; (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','%s')</script> " , esc_js ($ gtmId ));
59
59
}
0 commit comments