GoogleAnalytics   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 35
ccs 7
cts 10
cp 0.7
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A googleAnalytics() 0 26 5
1
<?php
2
3
namespace mQueue\View\Helper;
4
5
use Zend_Application;
6
use Zend_View_Helper_Abstract;
7
8
class GoogleAnalytics extends Zend_View_Helper_Abstract
9
{
10
    /**
11
     * Returns javascript code for Google Analytics
12
     *
13
     * @param string $trackingCode
14
     *
15
     * @return string
16
     */
17 12
    public function googleAnalytics($trackingCode = null)
18
    {
19 12
        if (!is_string($trackingCode)) {
20
            global $application;
21 12
            if ($application instanceof Zend_Application) {
22 12
                $trackingCode = $application->getOption('googleAnalyticsTrackingCode');
23
            }
24
        }
25
26 12
        $trackingCode = trim($trackingCode);
27 12
        if (!is_string($trackingCode) || empty($trackingCode)) {
0 ignored issues
show
introduced by
The condition is_string($trackingCode) is always true.
Loading history...
28 12
            return '';
29
        }
30
31
        $result = <<<STRING
32
<script async src="https://www.googletagmanager.com/gtag/js?id=$trackingCode"></script>
33
<script>
34
  window.dataLayer = window.dataLayer || [];
35
  function gtag(){dataLayer.push(arguments);}
36
  gtag('js', new Date());
37
38
  gtag('config', '$trackingCode');
39
</script>
40
STRING;
41
42
        return $result;
43
    }
44
}
45