Update Analytics to use Angularitics

This also supports the new Matomo setup.
This commit is contained in:
Cameron
2019-09-21 14:40:14 +00:00
parent 6d92dc4565
commit 1aa109ae52
11 changed files with 29 additions and 94 deletions

View File

@@ -1,12 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { AnalyticsService } from './analytics.service';
describe('AnalyticsService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: AnalyticsService = TestBed.get(AnalyticsService);
expect(service).toBeTruthy();
});
});

View File

@@ -1,17 +0,0 @@
import {Injectable} from '@angular/core';
declare var OWATracker;
@Injectable({
providedIn: 'root'
})
export class AnalyticsService {
constructor() {
}
public trackPageHit(pageName: String) {
OWATracker.setPageTitle(pageName);
OWATracker.trackPageView();
}
}

View File

@@ -1,7 +1,7 @@
import {Component} from '@angular/core';
import {RouterOutlet} from '@angular/router';
import {MatomoInjector} from 'ngx-matomo';
import {animate, query, style, transition, trigger} from '@angular/animations';
import { Angulartics2Piwik } from 'angulartics2/piwik';
export const routerTransition = trigger('routerTransition', [
transition('* <=> *', [
@@ -46,9 +46,9 @@ export const routerTransition = trigger('routerTransition', [
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(private matomoInjector: MatomoInjector) {
this.matomoInjector.init('https://cameroncordes.me/piwik/', 1);
}
constructor(private matomo: Angulartics2Piwik) {
matomo.startTracking()
}
getState(outlet: RouterOutlet) {
return outlet.activatedRouteData.state;

View File

@@ -11,7 +11,9 @@ import {HomeComponent} from './home/home.component';
import {ProjectsComponent} from './projects/projects.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {ProjectKeywordPipe} from './project-keyword.pipe';
import {MatomoModule} from 'ngx-matomo';
import { Angulartics2Module } from 'angulartics2';
import { Angulartics2Piwik } from 'angulartics2/piwik';
const appRoutes: Routes = [
{path: 'resume', component: ResumeComponent, data: {state: 'resume'}},
@@ -38,7 +40,7 @@ const appRoutes: Routes = [
MatToolbarModule,
MatSidenavModule,
RouterModule,
MatomoModule,
Angulartics2Module.forRoot(),
],
providers: [],
bootstrap: [AppComponent]

View File

@@ -1,5 +1,4 @@
import {AfterContentInit, Component, OnInit} from '@angular/core';
import {AnalyticsService} from '../analytics.service';
@Component({
selector: 'app-contact',
@@ -8,11 +7,10 @@ import {AnalyticsService} from '../analytics.service';
})
export class ContactComponent implements AfterContentInit {
constructor(private analytics: AnalyticsService) {
constructor() {
}
ngAfterContentInit(): void {
this.analytics.trackPageHit('Contact');
}
linkedInClicked() {

View File

@@ -1,5 +1,4 @@
import {AfterContentInit, Component, OnInit} from '@angular/core';
import {AnalyticsService} from '../analytics.service';
@Component({
selector: 'app-home',
@@ -8,10 +7,9 @@ import {AnalyticsService} from '../analytics.service';
})
export class HomeComponent implements AfterContentInit {
constructor(private analytics: AnalyticsService) { }
constructor() { }
ngAfterContentInit(): void {
this.analytics.trackPageHit('Home');
}
}

View File

@@ -1,17 +1,16 @@
import {AfterContentInit, Component, OnInit} from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {ProjectService} from './project.service';
import {ProjectItem} from './project-item';
import {AnalyticsService} from '../analytics.service';
@Component({
selector: 'app-projects',
templateUrl: './projects.component.html',
styleUrls: ['./projects.component.css'],
})
export class ProjectsComponent implements OnInit, AfterContentInit {
export class ProjectsComponent implements OnInit {
projects: Array<ProjectItem>;
constructor(private projectService: ProjectService, private analytics: AnalyticsService) {
constructor(private projectService: ProjectService) {
}
ngOnInit(): void {
@@ -22,8 +21,4 @@ export class ProjectsComponent implements OnInit, AfterContentInit {
this.projectService.getProjects().then(projects => this.projects = projects);
}
ngAfterContentInit(): void {
this.analytics.trackPageHit('Projects');
}
}

View File

@@ -1,22 +1,9 @@
import {AfterContentInit, Component, OnInit} from '@angular/core';
import {AnalyticsService} from '../analytics.service';
import {MatomoTracker} from 'ngx-matomo';
import {Component, OnInit} from '@angular/core';
@Component({
selector: 'app-resume',
templateUrl: './resume.component.html',
styleUrls: ['./resume.component.css']
})
export class ResumeComponent implements AfterContentInit {
private analytics: AnalyticsService;
constructor(analytics: AnalyticsService, private matomoTracker: MatomoTracker) {
this.analytics = analytics;
}
ngAfterContentInit(): void {
this.analytics.trackPageHit('Resume');
this.matomoTracker.trackPageView('Resume');
}
export class ResumeComponent {
}

View File

@@ -11,39 +11,20 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<!-- Start Open Web Analytics Tracker -->
<script type="text/javascript">
//<![CDATA[
var owa_baseUrl = 'https://cameroncordes.me/Open-Web-Analytics-1.6.2/';
var owa_cmds = owa_cmds || [];
owa_cmds.push(['setSiteId', '472a6484ee74d426b805ef774a407b37']);
owa_cmds.push(['trackPageView']);
owa_cmds.push(['trackClicks']);
// owa_cmds.push(['trackDomStream']);
(function() {
var _owa = document.createElement('script'); _owa.type = 'text/javascript'; _owa.async = true;
_owa.src = owa_baseUrl + 'modules/base/js/owa.tracker-combined-min.js';
var _owa_s = document.getElementsByTagName('script')[0]; _owa_s.parentNode.insertBefore(_owa, _owa_s);
}());
//]]>
</script>
<!-- End Open Web Analytics Code -->
<!-- Matomo -->
<!-- Piwik -->
<script type="text/javascript">
var _paq = window._paq || [];
_paq.push(['trackPageView']);
var _paq = _paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['enableLinkTracking']);
(function() {
var u="//cameroncordes.me/piwik/";
var u="//matomo.cameroncordes.me/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '1']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
<!-- End Piwik Code -->
</head>
<body>
<app-root></app-root>