From 4c04260aa59d470ced95b03ab6a125b60b8d4b7a Mon Sep 17 00:00:00 2001 From: Cameron Cordes Date: Fri, 22 Feb 2019 11:46:45 -0500 Subject: [PATCH] Trying to add page tracking --- src/app/analytics.service.spec.ts | 12 ++++++++++++ src/app/analytics.service.ts | 18 ++++++++++++++++++ src/app/contact/contact.component.ts | 17 +++++++++++------ src/app/home/home.component.ts | 10 ++++++---- src/app/projects/projects.component.ts | 19 ++++++++++++------- src/app/resume/resume.component.ts | 13 +++++++++---- src/index.html | 19 +++++++++++++++++++ 7 files changed, 87 insertions(+), 21 deletions(-) create mode 100644 src/app/analytics.service.spec.ts create mode 100644 src/app/analytics.service.ts diff --git a/src/app/analytics.service.spec.ts b/src/app/analytics.service.spec.ts new file mode 100644 index 0000000..e0babf1 --- /dev/null +++ b/src/app/analytics.service.spec.ts @@ -0,0 +1,12 @@ +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(); + }); +}); diff --git a/src/app/analytics.service.ts b/src/app/analytics.service.ts new file mode 100644 index 0000000..262f2b8 --- /dev/null +++ b/src/app/analytics.service.ts @@ -0,0 +1,18 @@ +import {Injectable} from '@angular/core'; + +declare var owa_cmds: Array; + +@Injectable({ + providedIn: 'root' +}) +export class AnalyticsService { + + constructor() { + } + + public trackPageHit(pageName: String) { + if (typeof owa_cmds === 'object') { + owa_cmds.push(pageName); + } + } +} diff --git a/src/app/contact/contact.component.ts b/src/app/contact/contact.component.ts index 8d74752..cfd9e2f 100644 --- a/src/app/contact/contact.component.ts +++ b/src/app/contact/contact.component.ts @@ -1,24 +1,29 @@ -import { Component, OnInit } from '@angular/core'; +import {AfterContentInit, Component, OnInit} from '@angular/core'; +import {AnalyticsService} from '../analytics.service'; @Component({ selector: 'app-contact', templateUrl: './contact.component.html', styleUrls: ['./contact.component.css'] }) -export class ContactComponent { +export class ContactComponent implements AfterContentInit { - constructor() { } + constructor(private analytics: AnalyticsService) { + } + ngAfterContentInit(): void { + this.analytics.trackPageHit('Contact'); + } linkedInClicked() { - window.open("https://www.linkedin.com/in/cameron-cordes-3b166583/") + window.open('https://www.linkedin.com/in/cameron-cordes-3b166583/'); } githubClicked() { - window.open("https://github.com/Stampede10343") + window.open('https://github.com/Stampede10343'); } emailClicked() { - window.open("mailto:cameronc.dev@gmail.com") + window.open('mailto:cameronc.dev@gmail.com'); } } diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 33fd770..4fd58b0 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,15 +1,17 @@ -import { Component, OnInit } from '@angular/core'; +import {AfterContentInit, Component, OnInit} from '@angular/core'; +import {AnalyticsService} from '../analytics.service'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.css'] }) -export class HomeComponent implements OnInit { +export class HomeComponent implements AfterContentInit { - constructor() { } + constructor(private analytics: AnalyticsService) { } - ngOnInit() { + ngAfterContentInit(): void { + this.analytics.trackPageHit('Home'); } } diff --git a/src/app/projects/projects.component.ts b/src/app/projects/projects.component.ts index d462148..ffdb864 100644 --- a/src/app/projects/projects.component.ts +++ b/src/app/projects/projects.component.ts @@ -1,24 +1,29 @@ -import {Component, OnInit} from '@angular/core'; -import {ProjectService} from "./project.service"; -import {ProjectItem} from "./project-item"; +import {AfterContentInit, 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 { +export class ProjectsComponent implements OnInit, AfterContentInit { projects: Array; - constructor(private projectService: ProjectService) { + constructor(private projectService: ProjectService, private analytics: AnalyticsService) { } ngOnInit(): void { - this.getProjects() + this.getProjects(); } getProjects() { - return this.projectService.getProjects().then(projects => this.projects = projects) + this.projectService.getProjects().then(projects => this.projects = projects); + } + + ngAfterContentInit(): void { + this.analytics.trackPageHit('Projects'); } } diff --git a/src/app/resume/resume.component.ts b/src/app/resume/resume.component.ts index 074042e..7736752 100644 --- a/src/app/resume/resume.component.ts +++ b/src/app/resume/resume.component.ts @@ -1,15 +1,20 @@ -import { Component, OnInit } from '@angular/core'; +import {AfterContentInit, Component, OnInit} from '@angular/core'; +import {AnalyticsService} from '../analytics.service'; @Component({ selector: 'app-resume', templateUrl: './resume.component.html', styleUrls: ['./resume.component.css'] }) -export class ResumeComponent implements OnInit { +export class ResumeComponent implements AfterContentInit { + private analytics: AnalyticsService; - constructor() { } + constructor(analytics: AnalyticsService) { + this.analytics = analytics; + } - ngOnInit() { + ngAfterContentInit(): void { + this.analytics.trackPageHit('Resume'); } } diff --git a/src/index.html b/src/index.html index 5144296..8bf0aeb 100644 --- a/src/index.html +++ b/src/index.html @@ -10,6 +10,25 @@ + + + +