-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add analytics data to CoursePlan route (#607)
* Create analytics container and add it to route file (copied from old branch) * Get newest doc to display as json * Pretty print json * Fix lint and type checks * Require auth to access route * Style page if no data shown * Add timestamp of last analytics run * Remove accidental commit * Bug fix for non-cp users * Refactor analytics retrieval to global-firestore-data * Optimize code by only retrieving newest document from collection (and adding timestamp field) * Change timestamp to date type * Remove null check, add comment
- Loading branch information
1 parent
812a089
commit 0a9384a
Showing
7 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<div> | ||
<div class="body-container" :class="{ 'no-data': !hasData() }"> | ||
<top-bar /> | ||
<div class="timestamp" v-if="hasData()">Data last retrieved at: {{ analyticsTimestamp }}</div> | ||
<pre class="analytics" v-if="hasData()">{{ analyticsData }}</pre> | ||
<div class="back_to_home"> | ||
<a class="back_to_home_link" href="/login">Back to home</a> | ||
</div> | ||
<custom-footer /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue'; | ||
import CustomFooter from '@/components/Footer.vue'; | ||
import TopBar from '@/components/TopBar.vue'; | ||
import { retrieveAnalytics } from '@/global-firestore-data'; | ||
export default defineComponent({ | ||
components: { CustomFooter, TopBar }, | ||
mounted() { | ||
this.retrieveData(); | ||
}, | ||
data() { | ||
return { | ||
analyticsData: '', | ||
analyticsTimestamp: '', | ||
}; | ||
}, | ||
methods: { | ||
async retrieveData() { | ||
const analyticsObject = await retrieveAnalytics(); | ||
this.analyticsData = analyticsObject.data; | ||
this.analyticsTimestamp = analyticsObject.timestamp; | ||
}, | ||
hasData() { | ||
return this.analyticsData.length > 2; | ||
}, | ||
}, | ||
}); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.no-data { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
} | ||
.back_to_home { | ||
font-size: 32px; | ||
vertical-align: middle; | ||
text-align: center; | ||
color: #7b7d7e; | ||
margin-bottom: 10rem; | ||
margin-top: 6rem; | ||
height: 100px; | ||
@media (max-width: 1154px) { | ||
margin-bottom: 3rem; | ||
} | ||
@media (max-width: 800px) { | ||
margin-top: 8%; | ||
font-size: 8vw; | ||
margin-bottom: 0; | ||
} | ||
} | ||
a.back_to_home_link { | ||
color: #7b7d7e; | ||
} | ||
.body-container { | ||
min-height: 100vh; | ||
} | ||
.timestamp { | ||
font-size: 16px; | ||
padding: 3.75rem 0 0 6.5rem; | ||
margin-bottom: 1rem; | ||
@media (max-width: 1154px) { | ||
padding: 0 0 0 3.125rem; | ||
} | ||
} | ||
.analytics { | ||
font-size: 14px; | ||
padding: 0 0 0 6.5rem; | ||
@media (max-width: 1154px) { | ||
padding: 0 0 0 3.125rem; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { trackUsersCollection } from '../firebase-frontend-config'; | ||
|
||
type AnalyticsData = { | ||
readonly data: string; | ||
readonly timestamp: string; | ||
}; | ||
|
||
const retrieveAnalytics = (): Promise<AnalyticsData> => | ||
trackUsersCollection | ||
.orderBy('timestamp', 'desc') | ||
.limit(1) | ||
.get() | ||
.then(querySnapshot => { | ||
let newestDocData = {}; | ||
let newestDocDate = new Date(0); | ||
querySnapshot.forEach(doc => { | ||
const isoTimestamp = doc.id; | ||
const date = new Date(isoTimestamp); | ||
if (date.getTime() > newestDocDate.getTime()) { | ||
newestDocDate = date; | ||
newestDocData = doc.data(); | ||
} | ||
}); | ||
|
||
const output = JSON.stringify(newestDocData, null, 2); | ||
|
||
return { | ||
data: output, | ||
timestamp: newestDocDate.toLocaleString(), | ||
}; | ||
}); | ||
|
||
export default retrieveAnalytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters