Skip to content

Commit

Permalink
Merge pull request #3978 from oat-sa/fix/TR-6036/google-tags-rendering
Browse files Browse the repository at this point in the history
fix google tag rendering
  • Loading branch information
poyuki authored Mar 13, 2024
2 parents 4405ac4 + bae51ab commit 25747b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions helpers/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ public static function getThemeStylesheet($target)
/**
* Returns the necessary analytics code.
*/
public static function getAnalyticsCode(): void
public static function printAnalyticsCode(): void
{
$gaTag = getenv('GA_TAG');
$environment = getenv('NODE_ENV') === 'production' ? 'Production' : 'Internal';
$gaTag = $_ENV['GA_TAG'] ?? '';
$environment = isset($_ENV['NODE_ENV']) && $_ENV['NODE_ENV'] === 'production' ? 'Production' : 'Internal';

if ($gaTag && method_exists(self::$templateClass, 'inc')) {
call_user_func(
Expand Down
8 changes: 4 additions & 4 deletions test/unit/helpers/LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ protected function tearDown(): void
TemplateMock::resetCalls();
}

public function testGetAnalyticsCodeWithGaTag(): void
public function testPrintAnalyticsCodeWithGaTag(): void
{
$this->setEnv('GA_TAG', 'dummy-ga-tag');

Layout::getAnalyticsCode();
Layout::printAnalyticsCode();

self::assertSame(
[
Expand All @@ -43,11 +43,11 @@ public function testGetAnalyticsCodeWithGaTag(): void
);
}

public function testGetAnalyticsCodeWithoutGaTag(): void
public function testPrintAnalyticsCodeWithoutGaTag(): void
{
$this->setEnv('GA_TAG', '');

Layout::getAnalyticsCode();
Layout::printAnalyticsCode();

self::assertSame(
[],
Expand Down
2 changes: 1 addition & 1 deletion views/templates/layout.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ $hasVersionWarning = empty($_COOKIE['versionWarning'])
<?=Layout::renderThemeTemplate(Theme::CONTEXT_BACKOFFICE, 'footer')?>

<div class="loading-bar"></div>
<? Layout::getAnalyticsCode(); ?>
<?php Layout::printAnalyticsCode(); ?>
</body>
</html>

0 comments on commit 25747b1

Please sign in to comment.