diff --git a/Extension.php b/Extension.php
index 05d74c2..9fd7440 100644
--- a/Extension.php
+++ b/Extension.php
@@ -3,6 +3,9 @@
namespace Bolt\Extension\Bolt\GoogleAnalytics;
+use Bolt\Translation\Translator as Trans;
+use Symfony\Component\HttpFoundation\Response,
+ Symfony\Component\Translation\Loader as TranslationLoader;
use Bolt\Extensions\Snippets\Location as SnippetLocation;
class Extension extends \Bolt\BaseExtension
@@ -15,12 +18,62 @@ public function getName()
function initialize() {
- $this->addSnippet(SnippetLocation::END_OF_HEAD, 'insertAnalytics');
+ $this->path = $this->app['config']->get('general/branding/path') . '/extensions/google-analytics';
- $additionalhtml = '';
- $additionalhtml .= '';
+ $this->app->match($this->path, array($this, 'GoogleAnalytics'));
- if($this->config['widget']) $this->addWidget('dashboard', 'right_first', 'analyticsWidget', $additionalhtml, 3600);
+ $this->app['htmlsnippets'] = true;
+
+ if ($this->app['config']->getWhichEnd()=='frontend') {
+ $this->addSnippet('endofhead', 'insertAnalytics');
+ } else {
+ $this->app->before(array($this, 'before'));
+ }
+
+ if (isset($this->config['backend']) && $this->config['backend']) {
+ $this->addMenuOption(Trans::__('Statistics'), $this->app['paths']['bolt'] . 'extensions/google-analytics', "fa:area-chart");
+ }
+
+ }
+
+ public function before()
+ {
+ $this->translationDir = __DIR__.'/locales/' . substr($this->app['locale'], 0, 2);
+ if (is_dir($this->translationDir))
+ {
+ $iterator = new \DirectoryIterator($this->translationDir);
+ foreach ($iterator as $fileInfo)
+ {
+ if ($fileInfo->isFile())
+ {
+ $this->app['translator']->addLoader('yml', new TranslationLoader\YamlFileLoader());
+ $this->app['translator']->addResource('yml', $fileInfo->getRealPath(), $this->app['locale']);
+ }
+ }
+ }
+ }
+
+ public function GoogleAnalytics()
+ {
+
+ $this->addJavascript('assets/es6-promise.min.js', 1);
+ $this->addJavascript('assets/active-users.js', 1);
+ $this->addJavascript('assets/date-range-selector.js', 1);
+ $this->addJavascript('assets/moment-with-locales.min.js', 1);
+ $this->addJavascript('assets/Chart.min.js', 1);
+ $this->addJavascript('assets/googleanalytics.js', array('late' => true, 'priority' => 1000));
+ $this->addCss('assets/styles.css', 1);
+
+ $data = [
+ "locale" => substr($this->app['locale'], 0, 2),
+ "token" => $this->getService(),
+ "profile" => $this->config['ga_profile_id']
+ ];
+
+ $this->app['twig.loader.filesystem']->addPath(__DIR__.'/views/', 'GoogleAnalytics');
+ $html = $this->app['render']->render("@GoogleAnalytics/base.twig", $data);
+
+ return new Response($html);
}
@@ -35,7 +88,6 @@ public function insertAnalytics()
if ($this->config['universal']) {
$html = <<< EOM
-
+ {%else%}
+
Error:
+ {{token}}
+ {%endif%}
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/widget.twig b/widget.twig
deleted file mode 100644
index 80734f8..0000000
--- a/widget.twig
+++ /dev/null
@@ -1,106 +0,0 @@
-
-
-{{ caption }}
-
-
-
-
-
-
-
-
-
-
-
- Total pageviews: |
- {{ aggr.pageviews }} ({{ aggr.pageviewspervisit }} per visit) |
-
-
- Total visitors: |
- {{ aggr.visitors }} |
-
-
- Time on page: |
- {{ aggr.timeonpage }} min. |
-
-
- Bounce/Exitrate: |
- {{ aggr.bouncerate }}% / {{ aggr.exitrate }}% |
-
-
-
-
-
-
-
-
- {% for page in sources %}
-
- {{ page.visits }} |
- {% if page.link %}
- {{ page.host|trimtext(35) }} |
- {% else %}
- {{ page.host|trimtext(35) }}
- {% endif %}
-
-
-
- {% endfor %}
-
-
-
-