get_template_global_variables()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 1
rs 9.6666
1
<?php namespace StudioBonito\SilverStripe\GoogleAnalytics\TemplateGlobalProviders;
2
3
use Injector;
4
5
/**
6
 * GoogleAnalyticsTemplateGlobalProvider.
7
 *
8
 * @author       Tom Densham <[email protected]>
9
 * @copyright    Studio Bonito Ltd.
10
 */
11
class GoogleAnalyticsTemplateGlobalProvider implements \TemplateGlobalProvider
12
{
13 3
    public static function get_template_global_variables()
14
    {
15
        return array(
16
            'GoogleAnalytics' => array(
17 3
                'method'  => 'getGoogleAnalyticsScript',
18
                'casting' => 'HTMLText'
19 3
            )
20 3
        );
21
    }
22
23 3
    public static function getGoogleAnalyticsScript()
24
    {
25 3
        $siteConfigService = Injector::inst()->get('SiteConfig');
26
27 3
        $siteConfig = $siteConfigService->current_site_config();
28
29 3
        return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[ r ]=i[ r ]||function(){(i[ r ].q=i[ r ].q||[]).push(arguments)},i[ r ].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', '{$siteConfig->GoogleAnalyticsTrackingID}', 'auto');ga('send', 'pageview');</script>";
30
    }
31
}