Skip to content

Commit

Permalink
Updates to GA methods (oppia#16719)
Browse files Browse the repository at this point in the history
* Updates to GA methods
* Fixes an error preventing practice_session_end from
  triggering.
* Trigger community_lesson_completed event along with
  lesson_completed.
* Remove legacy methods that contain "start <topic>".
* Remove topic_start and topic_end events

* remove unused var

* test fixes
  • Loading branch information
Kevin Thomas authored Dec 19, 2022
1 parent 628b426 commit af8dc51
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('Question Player Component', () => {


it('should get user info on initialization', fakeAsync(() => {
spyOn(urlService, 'getClassroomUrlFragmentFromUrl').and.returnValue(
spyOn(urlService, 'getClassroomUrlFragmentFromLearnerUrl').and.returnValue(
'classroom_url_fragment');
spyOn(urlService, 'getTopicUrlFragmentFromLearnerUrl').and.returnValue(
'topic_url_fragment');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export class QuestionPlayerComponent implements OnInit, OnDestroy {

this.testIsPassed = this.hasUserPassedTest();
this.siteAnalyticsService.registerPracticeSessionEndEvent(
this.urlService.getClassroomUrlFragmentFromUrl(),
this.urlService.getClassroomUrlFragmentFromLearnerUrl(),
this.urlService.getTopicUrlFragmentFromLearnerUrl(),
Object.keys(this.scorePerSkillMapping).toString(),
Object.keys(questionStateData).length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@
<div *ngIf="storySummary.isNodeCompleted(title)" class="fas fa-check completed-icon">
</div>
<div [ngClass]="{'border-bottom': idx < chaptersDisplayed, 'pending-chapter': !storySummary.isNodeCompleted(title) && isPreviousChapterCompleted(idx), 'incomplete-chapter': !storySummary.isNodeCompleted(title), 'complete-chapter': storySummary.isNodeCompleted(title)}"
*ngIf="idx < chaptersDisplayed"
(click)="onChapterClick(idx)">
*ngIf="idx < chaptersDisplayed">
<a [href]="getChapterUrl(title)" rel="noopener">
<span class="chapter-identifier" [innerHTML]="'I18N_TOPIC_VIEWER_CHAPTER' | translate">
</span>&nbsp;<span class="chapter-identifier">{{ idx + 1 }}:</span>&nbsp;<span dir="auto" *ngIf="!isHackyNodeTitleTranslationDisplayed(idx)">{{ title }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { StorySummary } from 'domain/story/story-summary.model';
import { WindowDimensionsService } from 'services/contextual/window-dimensions.service';
import { I18nLanguageCodeService } from 'services/i18n-language-code.service';
import { SiteAnalyticsService } from 'services/site-analytics.service';
import { MockTranslatePipe } from 'tests/unit-test-utils';
import { StorySummaryTileComponent } from './story-summary-tile.component';

Expand All @@ -31,7 +30,6 @@ describe('StorySummaryTileComponent', () => {
let fixture: ComponentFixture<StorySummaryTileComponent>;
let wds: WindowDimensionsService;
let i18nLanguageCodeService: I18nLanguageCodeService;
let siteAnalyticsService: SiteAnalyticsService;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand All @@ -48,7 +46,6 @@ describe('StorySummaryTileComponent', () => {
component = fixture.componentInstance;
wds = TestBed.inject(WindowDimensionsService);
i18nLanguageCodeService = TestBed.inject(I18nLanguageCodeService);
siteAnalyticsService = TestBed.inject(SiteAnalyticsService);

spyOn(i18nLanguageCodeService, 'isCurrentLanguageRTL').and.returnValue(
true);
Expand Down Expand Up @@ -536,88 +533,4 @@ describe('StorySummaryTileComponent', () => {

expect(component.chaptersDisplayed).toBe(1);
});

it('should register topic start', () => {
spyOn(siteAnalyticsService, 'registerTopicStartEvent');
component.storySummary = StorySummary.createFromBackendDict({
id: 'storyId',
title: 'Story Title',
node_titles: ['node1'],
thumbnail_filename: 'math_thumbnail.jpg',
thumbnail_bg_color: '#FF9933',
description: 'This is the story description',
story_is_published: true,
completed_node_titles: ['node1'],
url_fragment: 'story1',
all_node_dicts: [
{
id: 'node_1',
title: 'node1',
description: 'This is node 1',
destination_node_ids: [],
prerequisite_skill_ids: [],
acquired_skill_ids: [],
outline: '',
outline_is_finalized: true,
exploration_id: null,
thumbnail_bg_color: null,
thumbnail_filename: null
}
]
});
component.nodeTitles = ['node1'];
component.nodeCount = 1;

component.onChapterClick(0);

expect(siteAnalyticsService.registerTopicStartEvent).toHaveBeenCalled();
});

it('should register topic end', () => {
spyOn(siteAnalyticsService, 'registerTopicEndEvent');
component.storySummary = StorySummary.createFromBackendDict({
id: 'storyId',
title: 'Story Title',
node_titles: ['node1'],
thumbnail_filename: 'math_thumbnail.jpg',
thumbnail_bg_color: '#FF9933',
description: 'This is the story description',
story_is_published: true,
completed_node_titles: ['node1', 'node2'],
url_fragment: 'story1',
all_node_dicts: [
{
id: 'node_1',
title: 'node1',
description: 'This is node 1',
destination_node_ids: [],
prerequisite_skill_ids: [],
acquired_skill_ids: [],
outline: '',
outline_is_finalized: true,
exploration_id: null,
thumbnail_bg_color: null,
thumbnail_filename: null
}, {
id: 'node_2',
title: 'node1',
description: 'This is node 1',
destination_node_ids: [],
prerequisite_skill_ids: [],
acquired_skill_ids: [],
outline: '',
outline_is_finalized: true,
exploration_id: null,
thumbnail_bg_color: null,
thumbnail_filename: null
}
]
});
component.nodeCount = 2;
component.nodeTitles = ['node1', 'node2'];

component.onChapterClick(1);

expect(siteAnalyticsService.registerTopicEndEvent).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { I18nLanguageCodeService, TranslationKeyType } from 'services/i18n-langu
import { StoryNode } from 'domain/story/story-node.model';

import './story-summary-tile.component.css';
import { SiteAnalyticsService } from 'services/site-analytics.service';


@Component({
Expand Down Expand Up @@ -71,35 +70,12 @@ export class StorySummaryTileComponent implements OnInit {
private urlService: UrlService,
private windowDimensionsService: WindowDimensionsService,
private assetsBackendApiService: AssetsBackendApiService,
private siteAnalyticsService: SiteAnalyticsService
) {}

checkTabletView(): boolean {
return this.windowDimensionsService.getWidth() < 768;
}

onChapterClick(index: number): void {
if (index === 0) {
this.siteAnalyticsService.registerTopicStartEvent(
this.classroomUrlFragment,
this.topicUrlFragment,
this.nodeTitles[0],
this.nodeCount.toString(),
this.storySummary.getAllNodes()[0].getExplorationId() || 'NA'
);
} else if (index === this.nodeCount - 1) {
this.siteAnalyticsService.registerTopicEndEvent(
this.classroomUrlFragment,
this.topicUrlFragment,
this.nodeTitles[this.nodeCount - 1],
this.nodeCount.toString(),
this.storySummary.getAllNodes()[
this.nodeCount - 1
].getExplorationId() || 'NA'
);
}
}

getStoryLink(): string {
// This component is being used in the topic editor as well and
// we want to disable the linking in this case.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe('Stats reporting service ', () => {
expect(statsReportingService.currentStateName).toBe('firstState');
});

it('should record stats when an exploration is finished', () => {
it('should record stats for classroom lesson when finished', () => {
spyOn(urlService, 'getUrlParams')
.and.returnValue({classroom_url_fragment: 'classroom'});
let recordExplorationCompletedSpy = spyOn(
Expand All @@ -323,6 +323,30 @@ describe('Stats reporting service ', () => {
statsReportingService.recordExplorationCompleted(
'firstState', {}, '1', '2', 'en');

expect(
siteAnalyticsService.registerCuratedLessonCompleted
).toHaveBeenCalled();
expect(recordExplorationCompletedSpy).toHaveBeenCalled();
expect(statsReportingService.explorationIsComplete).toBe(true);
expect(statsReportingBackendApiService.postsStatsAsync).toHaveBeenCalled();
});

it('should record stats for community lesson when finished', () => {
spyOn(urlService, 'getUrlParams').and.returnValue({});
let recordExplorationCompletedSpy = spyOn(
statsReportingBackendApiService, 'recordExplorationCompletedAsync')
.and.returnValue(Promise.resolve({}));
spyOn(statsReportingBackendApiService, 'postsStatsAsync')
.and.returnValue(Promise.resolve({}));
spyOn(siteAnalyticsService, 'registerCommunityLessonCompleted');
expect(statsReportingService.explorationIsComplete).toBe(false);

statsReportingService.recordExplorationCompleted(
'firstState', {}, '1', '2', 'en');

expect(
siteAnalyticsService.registerCommunityLessonCompleted
).toHaveBeenCalled();
expect(recordExplorationCompletedSpy).toHaveBeenCalled();
expect(statsReportingService.explorationIsComplete).toBe(true);
expect(statsReportingBackendApiService.postsStatsAsync).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,10 @@ export class StatsReportingService {
cardCount,
language
);
} else {
this.siteAnalyticsService.registerCommunityLessonCompleted(
this.explorationId
);
}

this.postStatsToBackend();
Expand Down
76 changes: 34 additions & 42 deletions core/templates/services/site-analytics.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,14 @@ describe('Site Analytics Service', () => {
it('should register finish curated lesson event', () => {
sas.registerCuratedLessonStarted('Fractions', '123');

expect(gtagSpy).toHaveBeenCalledWith('event', 'start Fractions', {
event_category: 'CuratedLessonStarted',
event_label: '123'
});
expect(gtagSpy).toHaveBeenCalledWith(
'event',
'classroom_lesson_started',
{
topic_name: 'Fractions',
exploration_id: '123'
}
);
});

it('should register finish curated lesson event', () => {
Expand All @@ -480,10 +484,19 @@ describe('Site Analytics Service', () => {
'en'
);

expect(gtagSpy).toHaveBeenCalledWith('event', 'start Fractions', {
event_category: 'CuratedLessonCompleted',
event_label: '123'
});
expect(gtagSpy).toHaveBeenCalledWith(
'event',
'classroom_lesson_completed',
{
classroom_name: 'math',
topic_name: 'Fractions',
chapter_name: 'ch1',
exploration_id: '123',
chapter_number: '2',
chapter_card_count: '3',
exploration_language: 'en'
}
);
});

it('should register open collection from landing page event', () => {
Expand Down Expand Up @@ -610,10 +623,19 @@ describe('Site Analytics Service', () => {
sas.registerClassroomLessonEngagedWithEvent(
'math', 'Fractions', 'ch1', explorationId, '2', '3', 'en');

expect(gtagSpy).toHaveBeenCalledWith('event', 'start Fractions', {
event_category: 'ClassroomActiveUserStartAndSawCards',
event_label: explorationId
});
expect(gtagSpy).toHaveBeenCalledWith(
'event',
'classroom_lesson_engaged_with',
{
classroom_name: 'math',
topic_name: 'Fractions',
chapter_name: 'ch1',
exploration_id: '123',
chapter_number: '2',
chapter_card_count: '3',
exploration_language: 'en'
}
);
});

it('should register classroom header click event', () => {
Expand Down Expand Up @@ -703,35 +725,5 @@ describe('Site Analytics Service', () => {
'event', 'discovery_start_learning', {}
);
});

it('should register topic start event', () => {
sas.registerTopicStartEvent(
'math', 'Fractions', 'ch1', '2', 'exp_id');

expect(gtagSpy).toHaveBeenCalledWith(
'event', 'topic_start', {
classroom_name: 'math',
topic_name: 'Fractions',
chapter_name: 'ch1',
topic_chapter_count: '2',
exploration_id: 'exp_id'
}
);
});

it('should register topic end event', () => {
sas.registerTopicEndEvent(
'math', 'Fractions', 'ch1', '2', 'exp_id');

expect(gtagSpy).toHaveBeenCalledWith(
'event', 'topic_end', {
classroom_name: 'math',
topic_name: 'Fractions',
chapter_name: 'ch1',
topic_chapter_count: '2',
exploration_id: 'exp_id'
}
);
});
});
});
Loading

0 comments on commit af8dc51

Please sign in to comment.