Skip to content

Commit

Permalink
Fix google analytics
Browse files Browse the repository at this point in the history
- and typo in `next-config.js`
  • Loading branch information
PaperStrike committed Apr 6, 2021
1 parent 211dcdb commit 015dd00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/helpers/next-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ hexo.extend.helper.register('next_config_unique', function() {
comments : page.comments || '',
permalink: page.permalink || '',
path : page.path || '',
tittle : page.tittle || ''
title : page.title || ''
};
});
13 changes: 9 additions & 4 deletions source/js/third-party/analytics/google-analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
if (!CONFIG.google_analytics.only_pageview) {
if (CONFIG.hostname === location.hostname) {
window.dataLayer = window.dataLayer || [];
window.gtag = () => {
window.gtag = function() {
dataLayer.push(arguments);
};
gtag('js', new Date());
gtag('config', CONFIG.google_analytics.tracking_id);

document.addEventListener('page:loaded', () => {
gtag('js', new Date());
gtag('config', CONFIG.google_analytics.tracking_id);
document.addEventListener('pjax:success', () => {
gtag('event', 'page_view', {
page_location: location.href,
page_path : location.pathname,
page_title : document.title
});
});
}
} else {
Expand Down

0 comments on commit 015dd00

Please sign in to comment.