GoogleAnalyticsTemplateGlobalProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_template_global_variables() 0 9 1
A getGoogleAnalyticsScript() 0 8 1
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
}