Piwik\Plugins\CustomPiwikJs\TrackerUpdater::getUpdatedTrackerFileContent PHP Method

getUpdatedTrackerFileContent() public method

    public function getUpdatedTrackerFileContent()
    {
        $trackingCode = new PiwikJsManipulator($this->fromFile->getContent(), $this->trackerFiles);
        $newContent = $trackingCode->manipulateContent();
        return $newContent;
    }

Usage Example

Beispiel #1
0
 private static function isModifiedPathValid($path)
 {
     if ($path === 'piwik.js') {
         // we could have used a postEvent hook to enrich "\Piwik\Manifest::$files;" which would also benefit plugins
         // that want to check for file integrity but we do not want to risk to break anything right now. It is not
         // as trivial because piwik.js might be already updated, or updated on the next request. We cannot define
         // 2 or 3 different filesizes and md5 hashes for one file so we check it here.
         if (Plugin\Manager::getInstance()->isPluginActivated('CustomPiwikJs')) {
             $trackerUpdater = new TrackerUpdater();
             if ($trackerUpdater->getCurrentTrackerFileContent() === $trackerUpdater->getUpdatedTrackerFileContent()) {
                 // file was already updated, eg manually or via custom piwik.js, this is a valid piwik.js file as
                 // it was enriched by tracker plugins
                 return true;
             }
             try {
                 // the piwik.js tracker file was not updated yet, but may be updated just after the update by
                 // one of the events CustomPiwikJs is listening to or by a scheduled task.
                 // In this case, we check whether such an update will succeed later and if it will, the file is
                 // valid as well as it will be updated on the next request
                 $trackerUpdater->checkWillSucceed();
                 return true;
             } catch (AccessDeniedException $e) {
                 return false;
             }
         }
     }
     return false;
 }