50479: Added google analytics support

This commit is contained in:
Kristof De Langhe
2018-03-20 15:29:05 +01:00
parent 62ff2d3454
commit 35cbedf6fe
10 changed files with 40 additions and 1 deletions

View File

@@ -27,6 +27,8 @@ module.exports = {
async: true,
time: false
},
// Google Analytics tracking id
gaTrackingId: '',
// Log directory
logDirectory: '.',
// NOTE: will log all redux actions and transfers in console

View File

@@ -87,6 +87,7 @@
"@ngx-translate/core": "9.1.1",
"@ngx-translate/http-loader": "2.0.1",
"angular-idle-preload": "2.0.4",
"angulartics2": "^5.2.0",
"body-parser": "1.18.2",
"bootstrap": "^4.0.0",
"cerialize": "0.1.18",

View File

@@ -17,6 +17,7 @@ import { MetadataService } from './core/metadata/metadata.service';
import { HostWindowResizeAction } from './shared/host-window.actions';
import { HostWindowState } from './shared/host-window.reducer';
import { NativeWindowRef, NativeWindowService } from './shared/window.service';
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
@Component({
selector: 'ds-app',
@@ -32,7 +33,8 @@ export class AppComponent implements OnInit {
@Inject(NativeWindowService) private _window: NativeWindowRef,
private translate: TranslateService,
private store: Store<HostWindowState>,
private metadata: MetadataService
private metadata: MetadataService,
private angulartics2GoogleAnalytics: Angulartics2GoogleAnalytics
) {
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');

View File

@@ -9,6 +9,7 @@ export interface GlobalConfig extends Config {
production: boolean;
cache: CacheConfig;
universal: UniversalConfig;
gaTrackingId: string;
logDirectory: string;
debug: boolean;
}

View File

@@ -10,6 +10,12 @@
</head>
<body>
<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','https://www.google-analytics.com/analytics.js','ga');
</script>
<ds-app></ds-app>
</body>

View File

@@ -10,6 +10,12 @@
</head>
<body>
<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','https://www.google-analytics.com/analytics.js','ga');
</script>
<ds-app></ds-app>
</body>

View File

@@ -25,6 +25,11 @@ export function main() {
}
});
// Add google analytics key
var script = document.createElement('script');
script.innerHTML = 'ga(\'create\', \'' + ENV_CONFIG.gaTrackingId + '\', \'auto\');';
document.body.appendChild(script);
return platformBrowserDynamic().bootstrapModule(BrowserAppModule);
}

View File

@@ -14,6 +14,8 @@ import { AppComponent } from '../../app/app.component';
import { AppModule } from '../../app/app.module';
import { DSpaceBrowserTransferStateModule } from '../transfer-state/dspace-browser-transfer-state.module';
import { DSpaceTransferState } from '../transfer-state/dspace-transfer-state.service';
import { Angulartics2Module } from 'angulartics2';
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
export function createTranslateLoader(http: HttpClient) {
return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
@@ -34,6 +36,7 @@ export function createTranslateLoader(http: HttpClient) {
preloadingStrategy:
IdlePreload
}),
Angulartics2Module.forRoot([Angulartics2GoogleAnalytics]),
BrowserAnimationsModule,
DSpaceBrowserTransferStateModule,
TranslateModule.forRoot({

View File

@@ -16,10 +16,16 @@ import { DSpaceTransferState } from '../transfer-state/dspace-transfer-state.ser
import { TranslateUniversalLoader } from '../translate-universal-loader';
import { Angulartics2GoogleAnalytics } from 'angulartics2/ga';
export function createTranslateLoader() {
return new TranslateUniversalLoader('dist/assets/i18n/', '.json');
}
class AngularticsMock {
public eventTrack(action, properties) { }
}
@NgModule({
bootstrap: [AppComponent],
imports: [
@@ -42,6 +48,7 @@ export function createTranslateLoader() {
AppModule
],
providers: [
{ provide: Angulartics2GoogleAnalytics, useClass: AngularticsMock }
]
})
export class ServerAppModule {

View File

@@ -417,6 +417,12 @@ angular2-template-loader@0.6.2:
dependencies:
loader-utils "^0.2.15"
angulartics2@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/angulartics2/-/angulartics2-5.2.0.tgz#5bac82d4b6acf798b7db906488861e70b49fe04c"
dependencies:
tslib "^1.7.1"
ansi-align@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-2.0.0.tgz#c36aeccba563b89ceb556f3690f0b1d9e3547f7f"