-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup browser caching, added referral parameter to the script_src,
to prevent over-caching. Added customer_session_init event tracking, which required building a separate Observer, common code between the observers was moved into a trait.
- Loading branch information
1 parent
81b8181
commit 605549e
Showing
8 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace VigilantForm\MagentoKit\Observer; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\Framework\Event\{Observer, ObserverInterface}; | ||
use Magento\Framework\Filesystem\DirectoryList; | ||
use Psr\Log\LoggerInterface; | ||
use VigilantForm\MagentoKit\Traits\TrackPage; | ||
use VigilantForm\MagentoKit\VigilantFormMagentoKit; | ||
|
||
class CustomerTracking implements ObserverInterface | ||
{ | ||
use TrackPage; | ||
|
||
/** @var DirectoryList */ | ||
protected $directory; | ||
|
||
/** @var LoggerInterface */ | ||
protected $logger; | ||
|
||
/** @var VigilantFormMagentoKit */ | ||
protected $vfmk; | ||
|
||
/** | ||
* @param DirectoryList $directory | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct(DirectoryList $directory, LoggerInterface $logger) | ||
{ | ||
$this->directory = $directory; | ||
$this->logger = $logger; | ||
$this->vfmk = null; | ||
} | ||
|
||
/** | ||
* @param Observer $observer | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
/* this allows us to work with the freshly created customer session */ | ||
$session = $observer->getData('customer_session'); | ||
if ($session instanceof Session) { | ||
$this->vfmk = new VigilantFormMagentoKit($this->directory, $session, $this->logger); | ||
$this->trackSource(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace VigilantForm\MagentoKit\Traits; | ||
|
||
use VigilantForm\MagentoKit\VigilantFormMagentoKit; | ||
|
||
trait TrackPage | ||
{ | ||
/** @var VigilantFormMagentoKit */ | ||
protected $vfmk; | ||
|
||
protected function trackSource(): void | ||
{ | ||
/* get the file extension of the uri, will be blank for extensionless filenames, such as directories */ | ||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); | ||
$extension = pathinfo($path, PATHINFO_EXTENSION); | ||
|
||
/* if extension contains "htm" or blank string (directory) */ | ||
if (stripos($extension, 'htm') !== false || $extension === '') { | ||
/* track page, if request is expected referral, flag it as such */ | ||
$this->vfmk->trackSource( | ||
strpos($path, 'vigilant_form/index/index') !== false || | ||
strpos($path, 'customer/section/load') !== false | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters