Skip to content

Commit

Permalink
track time spent on each card/between clicking. Coding is fun with Katie
Browse files Browse the repository at this point in the history
  • Loading branch information
Weihua Li committed Sep 1, 2022
1 parent 671092b commit 56f8333
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Randousel/Randousel.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script>
import { Card, CardSubtitle, CardTitle, CardText, CardActions, Button, MaterialApp } from 'svelte-materialify';
import { format } from 'd3';
import { now } from 'svelte/internal';

This comment has been minimized.

Copy link
@rdmurphy

rdmurphy Sep 1, 2022

Contributor

This should not be here!

This comment has been minimized.

Copy link
@Weihua4455

Weihua4455 Sep 1, 2022

Collaborator

Huh!! Donno how it got there. Deleted now.

export let location;
export let wtfData;
let count = 0;
let data = []; // Initialize data
let selectedIndex = 0; // Randomly pick an array element
let selectedWTF;
let timeBeforeClick;
const loading = Promise.all([location, wtfData])
.then( ([locationResponse, wtfResponse]) => {
Expand All @@ -19,12 +21,29 @@
function handleClick() {
// Report the interaction to GA
const currentTime = Date.now()
if (timeBeforeClick) {
const clickDelta = currentTime - timeBeforeClick;
const clickDeltaSecond = Math.ceil(clickDelta/1000);
window.TMPAnalytics.trackEvent(
'#arpa-categories-randousel',
'timeOnCard',
String(clickDeltaSecond),
);
}
timeBeforeClick = currentTime;
window.TMPAnalytics.trackEvent(
'#arpa-categories-randousel',
'clicked',
String(count)
String(count),
);
if (count === 51) {
count = 1
} else {
Expand Down

0 comments on commit 56f8333

Please sign in to comment.