GoogleAnalytics::googleAnalytics()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.675

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 6
nop 1
dl 0
loc 26
ccs 7
cts 10
cp 0.7
crap 5.675
rs 9.5555
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