Skip to content

Commit

Permalink
- Further refinements to GoogleAnalytics Initialisation to ensure jav…
Browse files Browse the repository at this point in the history
…ascript injected correctly into head

- Removed custom AnalyticsService as this was found to be done out of the box by NgxGoogleAnalyticsRouterModule (now imported)
- Explicit setting of 1024 mb memory on fly.io deployment script
  • Loading branch information
nbarrett committed Oct 27, 2024
1 parent a5d904e commit ab0a602
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 48 deletions.
8 changes: 0 additions & 8 deletions projects/ngx-ramblers/src/app/container/container.html

This file was deleted.

20 changes: 10 additions & 10 deletions projects/ngx-ramblers/src/app/container/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ import { Component, inject, OnDestroy, OnInit } from "@angular/core";
import { Subscription } from "rxjs";
import { SystemConfig } from "../models/system.model";
import { SystemConfigService } from "../services/system/system-config.service";
import { NavigationEnd, Router } from "@angular/router";
import { AnalyticsService } from "../pages/admin/system-settings/google-analytics/analytics.service";

@Component({
selector: "app-root",
templateUrl: "./container.html",
template: `
<div class="container-fluid">
<app-header-bar *ngIf="config?.header?.headerBar?.show"/>
<app-navbar/>
</div>
<div class="container">
<router-outlet/>
</div>
<app-footer/>
`,
styleUrls: ["./container.sass"]
})
export class ContainerComponent implements OnInit, OnDestroy {
public systemConfigService: SystemConfigService = inject(SystemConfigService);
private router: Router = inject(Router);
private analyticsService: AnalyticsService = inject(AnalyticsService);
private subscriptions: Subscription[] = [];
protected config: SystemConfig;

Expand All @@ -22,11 +27,6 @@ export class ContainerComponent implements OnInit, OnDestroy {
.subscribe((config: SystemConfig) => {
this.config = config;
}));
this.subscriptions.push(this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
this.analyticsService.trackPageView(event.urlAfterRedirects);
}
}));
}

ngOnDestroy(): void {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ export function initializeGtag(systemConfigService: SystemConfigService, loggerF
const gtagScript = document.createElement("script");
gtagScript.src = `https://www.googletagmanager.com/gtag/js?id=${trackingId}`;
gtagScript.async = true;
gtagScript.onload = () => {
const inlineScript = document.createElement("script");
inlineScript.innerHTML = `
window.dataLayer = window.dataLayer || [];
window.gtag = (...args: any[]) => window.dataLayer.push(args);
window.gtag("js", new Date());
window.gtag("config", trackingId);
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${trackingId}');
`;

gtagScript.onload = () => {
document.head.appendChild(inlineScript);
logger.info("Google Analytics initialized successfully with trackingId:", trackingId);
};

Expand Down
5 changes: 3 additions & 2 deletions projects/ngx-ramblers/src/app/shared-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ import { SystemRecaptchaSettingsComponent } from "./pages/admin/system-settings/
import { initializeGtag } from "./pages/admin/system-settings/google-analytics/tag-manager";
import { SystemConfigService } from "./services/system/system-config.service";
import { LoggerFactory } from "./services/logger-factory.service";
import { NgxGoogleAnalyticsModule } from "ngx-google-analytics";
import { NgxGoogleAnalyticsModule, NgxGoogleAnalyticsRouterModule } from "ngx-google-analytics";
import {
SystemGoogleAnalyticsSettings
} from "./pages/admin/system-settings/google-analytics/system-google-analytics-settings";
Expand Down Expand Up @@ -211,7 +211,8 @@ import {
TypeaheadModule.forRoot(),
UiSwitchModule,
RecaptchaModule,
NgxGoogleAnalyticsModule
NgxGoogleAnalyticsModule,
NgxGoogleAnalyticsRouterModule
],
declarations: [
ActionButtonsComponent,
Expand Down
4 changes: 2 additions & 2 deletions server/deploy/deploy-to-environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ function deployApps(configFilePath: string, filterEnvironments: string[]): void
debugLog(`Secrets file not found: ${secretsFilePath}`);
}

runCommand(`flyctl deploy --memory 2gb --remote-only --app ${environmentConfig.appName} --image ${config.dockerImage}`);
runCommand(`flyctl deploy --remote-only --app ${environmentConfig.appName} --image ${config.dockerImage}`);
runCommand(`fly scale count 1 --app ${environmentConfig.appName}`);
runCommand(`fly scale memory 1024 --app ${environmentConfig.appName}`);
});
}

// Get environments from command line arguments (excluding the first two arguments)
const filterEnvironments = process.argv.slice(2);
const currentDir = path.resolve(__dirname);
const configFilePath = path.resolve(currentDir, "../../non-vcs/fly-io/configs.json");
Expand Down

0 comments on commit ab0a602

Please sign in to comment.