File Coverage

blib/lib/Mojolicious/Plugin/GoogleAnalytics.pm
Criterion Covered Total %
statement 8 15 53.3
branch 0 2 0.0
condition 0 2 0.0
subroutine 2 4 50.0
pod 1 1 100.0
total 11 24 45.8


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::GoogleAnalytics;
2             # ABSTRACT: GoogleAnalytics plugin
3             $Mojolicious::Plugin::GoogleAnalytics::VERSION = '1.005';
4              
5 1     1   1113 use Mojo::Base 'Mojolicious::Plugin';
  1         3  
  1         53  
6              
7             has 'template' => 'analytics_template';
8              
9             sub register {
10 1     1 1 88 my ($plugin, $app) = (shift, shift);
11 1         3 push @{$app->renderer->classes}, __PACKAGE__;
  1         32  
12              
13 1     0   101 $app->helper(analytics => sub {$plugin});
  0         0  
14              
15             $app->helper(
16             analytics_inc => sub {
17 0     0     my $self = shift;
18 0           my $analytics_id = shift;
19 0           my $domain_sub = shift;
20 0           my $allow_multi_top_level = shift;
21              
22 0 0         die "No analytics ID defined" unless defined $analytics_id;
23 0   0       $self->render(
24             template => $self->analytics->template,
25             partial => 1,
26             analytics_id => $analytics_id,
27             domain_sub => $domain_sub,
28             allow_multi_top_level => $allow_multi_top_level || undef,
29             );
30             }
31 1         167 );
32             }
33              
34             1;
35              
36             =pod
37              
38             =encoding UTF-8
39              
40             =head1 NAME
41              
42             Mojolicious::Plugin::GoogleAnalytics - GoogleAnalytics plugin
43              
44             =head1 VERSION
45              
46             version 1.005
47              
48             =head1 SYNOPSIS
49              
50             # Mojolicious
51             $self->plugin('GoogleAnalytics');
52              
53             # Mojolicious::Lite
54             plugin 'GoogleAnalytics';
55              
56             # In your layout template
57             <%= analytics_inc 'UA-32432-1', 'example.com', 1 %>
58            
59              
60             =head1 DESCRIPTION
61              
62             L is a L
63             plugin. Inserts Google Analytics code and associates your analytics
64             id.
65              
66             =head1 METHODS
67              
68             =head2 register
69              
70             $plugin->register(Mojolicious->new);
71              
72             Register plugin in L application.
73              
74             =head1 OPTIONS
75              
76             =head2 Track Subdomains
77              
78             Put the domain which qualifies any subdomains you wish to track,
79             eg. blog.example.com, apps.example.com will have the second arguement
80             set to 'example.com'
81              
82             =head2 Multiple top level domains
83              
84             Default is set to 1 to allow domains such as example.fr, example.cn,
85             and example.com
86              
87             =head1 AUTHOR
88              
89             Adam Stokes
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             This software is copyright (c) 2014 by Adam Stokes.
94              
95             This is free software; you can redistribute it and/or modify it under
96             the same terms as the Perl 5 programming language system itself.
97              
98             =head1 DISCLAIMER OF WARRANTY
99              
100             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
101             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT
102             WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER
103             PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND,
104             EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
105             IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
106             PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
107             SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME
108             THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
109              
110             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
111             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
112             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE
113             TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR
114             CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
115             SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
116             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
117             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
118             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
119             DAMAGES.
120              
121             =cut
122              
123             __DATA__