-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e06f86
commit 2c4c47d
Showing
11 changed files
with
325 additions
and
4 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
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,25 @@ | ||
<?php namespace Arcanedev\SeoHelper\Contracts\Entities; | ||
|
||
use Arcanedev\SeoHelper\Contracts\Renderable; | ||
|
||
/** | ||
* Interface AnalyticsInterface | ||
* | ||
* @package Arcanedev\SeoHelper\Contracts\Entities | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
interface AnalyticsInterface extends Renderable | ||
{ | ||
/* ------------------------------------------------------------------------------------------------ | ||
| Getters & Setters | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Set google analytics code. | ||
* | ||
* @param string $code | ||
* | ||
* @return self | ||
*/ | ||
public function setGoogle($code); | ||
} |
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,113 @@ | ||
<?php namespace Arcanedev\SeoHelper\Entities; | ||
|
||
use Arcanedev\SeoHelper\Contracts\Entities\AnalyticsInterface; | ||
use Arcanedev\Support\Traits\Configurable; | ||
|
||
/** | ||
* Class Analytics | ||
* | ||
* @package Arcanedev\SeoHelper\Entities | ||
* @author ARCANEDEV <[email protected]> | ||
*/ | ||
class Analytics implements AnalyticsInterface | ||
{ | ||
/* ------------------------------------------------------------------------------------------------ | ||
| Traits | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
use Configurable; | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Properties | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Google analytics code. | ||
* | ||
* @var string | ||
*/ | ||
protected $google = ''; | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Constructor | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Make an Analytics instance. | ||
* | ||
* @param array $config | ||
*/ | ||
public function __construct(array $config) | ||
{ | ||
$this->setConfigs($config); | ||
|
||
$this->setGoogle($this->getConfig('google', '')); | ||
} | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Getters & Setters | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Set google analytics code. | ||
* | ||
* @param string $code | ||
* | ||
* @return self | ||
*/ | ||
public function setGoogle($code) | ||
{ | ||
$this->google = $code; | ||
|
||
return $this; | ||
} | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Main Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Render the tag. | ||
* | ||
* @return string | ||
*/ | ||
public function render() | ||
{ | ||
return implode(PHP_EOL, array_filter([ | ||
$this->renderGoogleScript(), | ||
])); | ||
} | ||
|
||
/** | ||
* Render the tag. | ||
* | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->render(); | ||
} | ||
|
||
/* ------------------------------------------------------------------------------------------------ | ||
| Other Functions | ||
| ------------------------------------------------------------------------------------------------ | ||
*/ | ||
/** | ||
* Render the google tracking code. | ||
* | ||
* @return string | ||
*/ | ||
private function renderGoogleScript() | ||
{ | ||
return <<<EOT | ||
<script> | ||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | ||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | ||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | ||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | ||
ga('create', '$this->google', 'auto'); | ||
ga('send', 'pageview'); | ||
</script> | ||
EOT; | ||
} | ||
} |
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
Oops, something went wrong.