Skip to content

Commit

Permalink
Allow changing GoogleTagManager service status and id after init (#36)
Browse files Browse the repository at this point in the history
* Allow changing GoogleTagManager service status and id after initialization
This allows us to :
- Support enabling/disabling gtm service by page in same website
- Support injecting different gtm id by page in same website
- Handle multiple gtm id for one website

* Add more user friendly methods enable() and disable() to set service status (replace setEnabledStatus)
  • Loading branch information
ialvesdasilva committed Apr 22, 2020
1 parent e293357 commit e1214d8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Helper/GoogleTagManagerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ public function __construct(GoogleTagManagerInterface $service)
$this->service = $service;
}

/**
* {@inheritdoc}
*/
public function enable()
{
$this->service->enable();
}

/**
* {@inheritdoc}
*/
public function disable()
{
$this->service->disable();
}

/**
* {@inheritdoc}
*/
Expand All @@ -49,6 +65,14 @@ public function getId()
return $this->service->getId();
}

/**
* {@inheritdoc}
*/
public function setId($id)
{
$this->service->setId($id);
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions Helper/GoogleTagManagerHelperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
*/
interface GoogleTagManagerHelperInterface extends HelperInterface
{
/**
* @return void
*/
public function enable();

/**
* @return void
*/
public function disable();

/**
* @return bool
*/
Expand All @@ -29,6 +39,12 @@ public function isEnabled();
*/
public function getId();

/**
* @param string $id
* @return void
*/
public function setId($id);

/**
* @return array
*/
Expand Down
24 changes: 24 additions & 0 deletions Service/GoogleTagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ public function mergeData($key, $value)
$this->setData($key, array_merge_recursive($merge, $value));
}

/**
* {@inheritdoc}
*/
public function enable()
{
$this->enabled = true;
}

/**
* {@inheritdoc}
*/
public function disable()
{
$this->enabled = false;
}

/**
* {@inheritdoc}
*/
Expand All @@ -92,6 +108,14 @@ public function getId()
return $this->id;
}

/**
* {@inheritdoc}
*/
public function setId($id)
{
$this->id = $id;
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions Service/GoogleTagManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public function setData($key, $value);
*/
public function mergeData($key, $value);

/**
* @return void
*/
public function enable();

/**
* @return void
*/
public function disable();

/**
* @return bool
*/
Expand All @@ -48,6 +58,12 @@ public function isEnabled();
*/
public function getId();

/**
* @param string $id
* @return void
*/
public function setId($id);

/**
* @return array
*/
Expand Down

0 comments on commit e1214d8

Please sign in to comment.