Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix google tag rendering #3978

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading