Skip to content

Commit

Permalink
fix: analytics service
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcamargo committed Aug 5, 2022
1 parent 48b60ad commit a90a945
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/webapp/scripts/services/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ function getGoogleAnalyticsId(){
}

function buildPath(){
const pathname = windowService.getPathname();
return pathname.replace('/#!/','/').split('?')[0];
const pathname = windowService.getHash();
return pathname.replace('#!/','/').split('?')[0];
}

export default _public;
4 changes: 2 additions & 2 deletions src/webapp/scripts/services/analytics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ describe('Analytics Service', () => {
});

it('should track page view', () => {
windowService.getPathname = jest.fn(() => '/#!/components/vue/alert?some=param');
windowService.getHash = jest.fn(() => '#!/components/vue/column');
const googleAnalyticsId = '123';
mockGoogleAnalyticsId(googleAnalyticsId);
analyticsService.init();
analyticsService.trackPageView();
expect(ganalyticsInstanceMock.trackPageview).toHaveBeenCalledTimes(1);
expect(ganalyticsInstanceMock.trackPageview).toHaveBeenCalledWith({
path: '/components/vue/alert'
path: '/components/vue/column'
});
});
});
4 changes: 2 additions & 2 deletions src/webapp/scripts/services/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ _public.getPageYOffset = () => {
return window.pageYOffset;
};

_public.getPathname = () => {
return window.location.pathname;
_public.getHash = () => {
return window.location.hash;
};

export default _public;
4 changes: 2 additions & 2 deletions src/webapp/scripts/services/window.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Window Service', () => {
expect(windowService.getPageYOffset()).toEqual(window.pageYOffset);
});

it('should get pathname', () => {
expect(windowService.getPathname()).toEqual(window.location.pathname);
it('should get hash', () => {
expect(windowService.getHash()).toEqual(window.location.hash);
});
});

0 comments on commit a90a945

Please sign in to comment.