public function dispatchLoopShutdown()
 {
     if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled && ($code = Pimcore_Google_Analytics::getCode())) {
         // analytics
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         // search for the end <head> tag, and insert the google analytics code before
         // this method is much faster than using simple_html_dom and uses less memory
         $headEndPosition = strpos($body, "</head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, $code . "</head>", $headEndPosition, 7);
         }
         $this->getResponse()->setBody($body);
     }
 }
Beispiel #2
0
 public function dispatchLoopShutdown()
 {
     if (!Pimcore_Tool::isHtmlResponse($this->getResponse())) {
         return;
     }
     if ($this->enabled && Pimcore_Google_Analytics::isConfigured()) {
         // analytics
         include_once "simple_html_dom.php";
         $body = $this->getResponse()->getBody();
         // search for the end <head> tag, and insert the google analytics code before
         // this method is much faster than using simple_html_dom and uses less memory
         $headEndPosition = strpos($body, "</head>");
         if ($headEndPosition !== false) {
             $body = substr_replace($body, Pimcore_Google_Analytics::getCode() . "</head>", $headEndPosition, 7);
         }
         // website optimizer
         if ($this->document) {
             $top = Pimcore_Google_Analytics::getOptimizerTop($this->document);
             $bottom = Pimcore_Google_Analytics::getOptimizerBottom($this->document);
             $conversion = Pimcore_Google_Analytics::getOptimizerConversion($this->document);
             if ($top || $bottom || $conversion) {
                 $html = str_get_html($body);
                 if ($html) {
                     $body = $html->find("body", 0);
                     if ($top && $bottom) {
                         $body->innertext = $top . $body->innertext . $bottom;
                     } else {
                         if ($conversion) {
                             $body->innertext = $body->innertext . $conversion;
                         } else {
                             if ($bottom) {
                                 $body->innertext = $body->innertext . $bottom;
                             }
                         }
                     }
                     $body = $html->save();
                 }
             }
         }
         $this->getResponse()->setBody($body);
     }
 }
Beispiel #3
0
?>
,
            debug: <?php 
echo Pimcore::inDebugMode() ? "true" : "false";
?>
,
            devmode: <?php 
echo PIMCORE_DEVMODE ? "true" : "false";
?>
,
            google_analytics_enabled: <?php 
echo Zend_Json::encode((bool) Pimcore_Google_Analytics::isConfigured());
?>
,
            google_analytics_advanced: <?php 
echo Zend_Json::encode((bool) Pimcore_Google_Analytics::getSiteConfig()->advanced);
?>
,
            google_webmastertools_enabled: <?php 
echo Zend_Json::encode((bool) Pimcore_Google_Webmastertools::isConfigured());
?>
,
            customviews: <?php 
echo Zend_Json::encode($this->customview_config);
?>
,
            language: '<?php 
echo $this->language;
?>
',
            websiteLanguages: <?php 
 public function navigationAction()
 {
     $config = Pimcore_Google_Analytics::getSiteConfig($this->getSite());
     $startDate = date("Y-m-d", time() - 86400 * 31);
     $endDate = date("Y-m-d");
     if ($this->_getParam("dateFrom") && $this->_getParam("dateTo")) {
         $startDate = date("Y-m-d", strtotime($this->_getParam("dateFrom")));
         $endDate = date("Y-m-d", strtotime($this->_getParam("dateTo")));
     }
     // all pageviews
     $query0 = $this->getQuery($this->getSite());
     $query0->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->setStartDate($startDate)->setEndDate($endDate)->setSort(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS, true)->setMaxResults(1);
     if ($config->advanced) {
         if ($this->_getParam("id") && $this->_getParam("type")) {
             $url = "/pimcoreanalytics/" . $this->_getParam("type") . "/" . $this->_getParam("id");
             $query0->setFilter(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH . "==" . $url);
         }
     } else {
         if ($this->_getParam("path")) {
             $query0->setFilter(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH . "==" . $this->_getParam("path"));
         }
     }
     $result0 = $this->getService()->getDataFeed($query0);
     $totalViews = (int) $result0[0]->getMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->getValue();
     // ENTRANCES
     $query1 = $this->getQuery($this->getSite());
     $query1->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PREV_PAGE_PATH)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->setStartDate($startDate)->setEndDate($endDate)->setSort(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS, true)->setMaxResults(10);
     if ($config->advanced) {
         if ($this->_getParam("id") && $this->_getParam("type")) {
             $url = "/pimcoreanalytics/" . $this->_getParam("type") . "/" . $this->_getParam("id");
             $query1->setFilter(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH . "==" . $url);
         }
     } else {
         if ($this->_getParam("path")) {
             $query1->setFilter(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH . "==" . $this->_getParam("path"));
         }
     }
     $result1 = $this->getService()->getDataFeed($query1);
     $prev = array();
     foreach ($result1 as $row) {
         $d = array("path" => $this->formatDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PREV_PAGE_PATH, (string) $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PREV_PAGE_PATH)), "pageviews" => (double) $row->getMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->getValue());
         $document = Document::getByPath((string) $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PREV_PAGE_PATH));
         if ($document) {
             $d["id"] = $document->getId();
         }
         $d["percent"] = round($d["pageviews"] / $totalViews * 100);
         $d["weight"] = 100;
         if ($prev[0]["weight"]) {
             $d["weight"] = round($d["percent"] / $prev[0]["percent"] * 100);
         }
         $prev[] = $d;
     }
     // EXITS
     $query2 = $this->getQuery($this->getSite());
     $query2->addDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH)->addMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->setStartDate($startDate)->setEndDate($endDate)->setSort(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS, true)->setMaxResults(10);
     if ($config->advanced) {
         if ($this->_getParam("id") && $this->_getParam("type")) {
             $url = "/pimcoreanalytics/" . $this->_getParam("type") . "/" . $this->_getParam("id");
             $query2->setFilter(Zend_Gdata_Analytics_DataQuery::DIMENSION_PREV_PAGE_PATH . "==" . $url);
         }
     } else {
         if ($this->_getParam("path")) {
             $query2->setFilter(Zend_Gdata_Analytics_DataQuery::DIMENSION_PREV_PAGE_PATH . "==" . $this->_getParam("path"));
         }
     }
     $result2 = $this->getService()->getDataFeed($query2);
     $next = array();
     foreach ($result2 as $row) {
         $d = array("path" => $this->formatDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH, (string) $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH)), "pageviews" => (double) $row->getMetric(Zend_Gdata_Analytics_DataQuery::METRIC_PAGEVIEWS)->getValue());
         $document = Document::getByPath((string) $row->getDimension(Zend_Gdata_Analytics_DataQuery::DIMENSION_PAGE_PATH));
         if ($document) {
             $d["id"] = $document->getId();
         }
         $d["percent"] = round($d["pageviews"] / $totalViews * 100);
         $d["weight"] = 100;
         if ($next[0]["weight"]) {
             $d["weight"] = round($d["percent"] / $next[0]["percent"] * 100);
         }
         $next[] = $d;
     }
     $this->view->next = $next;
     $this->view->prev = $prev;
     $this->view->path = $this->_getParam("path");
     $this->getResponse()->setHeader("Content-Type", "application/xml", true);
 }
 public function navigationAction()
 {
     $config = Pimcore_Google_Analytics::getSiteConfig($this->getSite());
     $startDate = date("Y-m-d", time() - 86400 * 31);
     $endDate = date("Y-m-d");
     if ($this->_getParam("dateFrom") && $this->_getParam("dateTo")) {
         $startDate = date("Y-m-d", strtotime($this->_getParam("dateFrom")));
         $endDate = date("Y-m-d", strtotime($this->_getParam("dateTo")));
     }
     // all pageviews
     if ($config->advanced) {
         if ($this->_getParam("id") && $this->_getParam("type")) {
             $url = "/pimcoreanalytics/" . $this->_getParam("type") . "/" . $this->_getParam("id");
             $filters[] = "ga:pagePath==" . $url;
         }
     } else {
         if ($this->_getParam("path")) {
             $filters[] = "ga:pagePath==" . $this->_getParam("path");
         }
     }
     $opts = array("dimensions" => "ga:pagePath", "max-results" => 1, "sort" => "-ga:pageViews");
     if (!empty($filters)) {
         $opts["filters"] = implode(";", $filters);
     }
     $result0 = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, "ga:pageViews", $opts);
     $totalViews = (int) $result0["totalsForAllResults"]["ga:pageviews"];
     // ENTRANCES
     $opts = array("dimensions" => "ga:previousPagePath", "max-results" => 10, "sort" => "-ga:pageViews");
     if (!empty($filters)) {
         $opts["filters"] = implode(";", $filters);
     }
     $result1 = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, "ga:pageViews", $opts);
     $prev = array();
     foreach ($result1["rows"] as $row) {
         $d = array("path" => $this->formatDimension("ga:previousPagePath", $row[0]), "pageviews" => $row[1]);
         $document = Document::getByPath($row[0]);
         if ($document) {
             $d["id"] = $document->getId();
         }
         $d["percent"] = round($d["pageviews"] / $totalViews * 100);
         $d["weight"] = 100;
         if ($prev[0]["weight"]) {
             $d["weight"] = round($d["percent"] / $prev[0]["percent"] * 100);
         }
         $prev[] = $d;
     }
     // EXITS
     $opts = array("dimensions" => "ga:pagePath", "max-results" => 10, "sort" => "-ga:pageViews");
     if (!empty($filters)) {
         $opts["filters"] = implode(";", $filters);
     }
     $result2 = $this->service->data_ga->get("ga:" . $config->profile, $startDate, $endDate, "ga:pageViews", $opts);
     $next = array();
     foreach ($result2["rows"] as $row) {
         $d = array("path" => $this->formatDimension("ga:previousPagePath", $row[0]), "pageviews" => $row[1]);
         $document = Document::getByPath($row[0]);
         if ($document) {
             $d["id"] = $document->getId();
         }
         $d["percent"] = round($d["pageviews"] / $totalViews * 100);
         $d["weight"] = 100;
         if ($next[0]["weight"]) {
             $d["weight"] = round($d["percent"] / $next[0]["percent"] * 100);
         }
         $next[] = $d;
     }
     $this->view->next = $next;
     $this->view->prev = $prev;
     $this->view->path = $this->_getParam("path");
     $this->getResponse()->setHeader("Content-Type", "application/xml", true);
 }
 public function abSaveAction()
 {
     // source-page
     $sourceDoc = Document::getById($this->_getParam("documentId"));
     $goalDoc = Document::getByPath($this->_getParam("conversionPage"));
     if (!$sourceDoc || !$goalDoc) {
         exit;
     }
     // clean properties
     $sourceDoc = $this->clearProperties($sourceDoc);
     $goalDoc = $this->clearProperties($goalDoc);
     // google stuff
     $credentials = $this->getAnalyticsCredentials();
     $config = Pimcore_Google_Analytics::getSiteConfig($site);
     $gdata = $this->getService();
     // create new experiment
     $entryResult = $gdata->insertEntry("\r\n            <entry xmlns='http://www.w3.org/2005/Atom'\r\n                   xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'\r\n                   xmlns:app='http://www.w3.org/2007/app'\r\n                   xmlns:gd='http://schemas.google.com/g/2005'>\r\n                <title>" . $this->_getParam("name") . "</title>\r\n                <gwo:analyticsAccountId>" . $config->accountid . "</gwo:analyticsAccountId>\r\n                <gwo:experimentType>AB</gwo:experimentType>\r\n                <gwo:status>Running</gwo:status>\r\n                <link rel='gwo:testUrl' type='text/html' href='http://" . Pimcore_Tool::getHostname() . $sourceDoc->getFullPath() . "' />\r\n                <link rel='gwo:goalUrl' type='text/html' href='http://" . Pimcore_Tool::getHostname() . $goalDoc->getFullPath() . "' />\r\n            </entry>\r\n        ", "https://www.google.com/analytics/feeds/websiteoptimizer/experiments");
     $e = $entryResult->getExtensionElements();
     $data = array();
     foreach ($e as $a) {
         $data[$a->rootElement] = $a->getText();
     }
     // get tracking code
     $d = preg_match("/_getTracker\\(\"(.*)\"\\)/", $data["trackingScript"], $matches);
     $trackingId = $matches[1];
     // get test id
     $d = preg_match("/_trackPageview\\(\"\\/([0-9]+)/", $data["trackingScript"], $matches);
     $testId = $matches[1];
     // set original page
     $entryResult = $gdata->insertEntry("\r\n            <entry xmlns='http://www.w3.org/2005/Atom'\r\n                   xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'\r\n                   xmlns:app='http://www.w3.org/2007/app'\r\n                   xmlns:gd='http://schemas.google.com/g/2005'>\r\n            <title>Original</title>\r\n            <content>http://" . Pimcore_Tool::getHostname() . $sourceDoc->getFullPath() . "</content>\r\n            </entry>\r\n        ", "https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"] . "/abpagevariations");
     // set testing pages
     for ($i = 1; $i < 100; $i++) {
         if ($this->_getParam("page_name_" . $i)) {
             $pageUrl = "";
             if ($this->_getParam("page_url_" . $i)) {
                 if ($variantDoc = Document::getByPath($this->_getParam("page_url_" . $i))) {
                     $pageUrl = $this->getRequest()->getScheme() . "://" . Pimcore_Tool::getHostname() . $variantDoc->getFullPath();
                     // add properties to variant page
                     $variantDoc = $this->clearProperties($variantDoc);
                     $variantDoc->setProperty("google_website_optimizer_test_id", "text", $testId);
                     $variantDoc->setProperty("google_website_optimizer_track_id", "text", $trackingId);
                     $variantDoc->save();
                 } else {
                     Logger::warn("Added a invalid URL to A/B test.");
                     exit;
                 }
             }
             /*if($this->_getParam("page_version_".$i)) {
                   $pageUrl = "http://" . Pimcore_Tool::getHostname() . $sourceDoc->getFullPath() . "?v=" . $this->_getParam("page_version_".$i);
               }
               */
             if ($pageUrl) {
                 try {
                     $entryResult = $gdata->insertEntry("\r\n                        <entry xmlns='http://www.w3.org/2005/Atom'\r\n                               xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'\r\n                               xmlns:app='http://www.w3.org/2007/app'\r\n                               xmlns:gd='http://schemas.google.com/g/2005'>\r\n                        <title>" . $this->_getParam("page_name_" . $i) . "</title>\r\n                        <content>" . $pageUrl . "</content>\r\n                        </entry>\r\n                    ", "https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"] . "/abpagevariations");
                 } catch (Exception $e) {
                     Logger::err($e);
                 }
             }
         } else {
             break;
         }
     }
     // @todo START EXPERIMENT HERE
     //$entryResult = $gdata->getEntry("https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"]);
     //$gdata->updateEntry($entryResult->getXml(),"https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"]);
     /*$gdata->updateEntry("
           <entry xmlns='http://www.w3.org/2005/Atom'
                  xmlns:gwo='http://schemas.google.com/analytics/websiteoptimizer/2009'
                  xmlns:app='http://www.w3.org/2007/app'
                  xmlns:gd='http://schemas.google.com/g/2005'>
           <gwo:status>Running</gwo:status>
           </entry>
       ","https://www.google.com/analytics/feeds/websiteoptimizer/experiments/" . $data["experimentId"]);
       */
     // source-page
     $sourceDoc->setProperty("google_website_optimizer_test_id", "text", $testId);
     $sourceDoc->setProperty("google_website_optimizer_track_id", "text", $trackingId);
     $sourceDoc->setProperty("google_website_optimizer_original_page", "bool", true);
     $sourceDoc->save();
     // conversion-page
     $goalDoc->setProperty("google_website_optimizer_test_id", "text", $testId);
     $goalDoc->setProperty("google_website_optimizer_track_id", "text", $trackingId);
     $goalDoc->setProperty("google_website_optimizer_conversion_page", "bool", true);
     $goalDoc->save();
     // clear output cache
     Pimcore_Model_Cache::clearTag("output");
     Pimcore_Model_Cache::clearTag("properties");
     $this->_helper->json(array("success" => true));
 }