Skip to content

Commit

Permalink
Merge pull request #292 from near/fix/rudder-analytics-metrics
Browse files Browse the repository at this point in the history
Fix: Rudderstack Analytics Page Load Metric
  • Loading branch information
charleslavon authored Jul 14, 2023
2 parents 11c63f7 + 0075fc2 commit 6aee127
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/utils/rudder-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let rudderAnalytics: Analytics | null = null;
let anonymousUserId = '';
let hashId = '';
let anonymousUserIdCreatedAt = '';
let pendingEvents: any = [];

declare global {
interface Window {
Expand Down Expand Up @@ -62,6 +63,10 @@ export async function init() {
window.rudderanalytics.load(rudderAnalyticsKey, analyticsUrl);
rudderAnalytics = window.rudderanalytics;
if (rudderAnalytics) rudderAnalytics.setAnonymousId(getAnonymousId());
for (const event of pendingEvents) {
event();
}
pendingEvents = [];
} catch (e) {
console.error(e);
}
Expand All @@ -78,7 +83,12 @@ function filterURL(url: string) {
}

export function recordPageView(pageName: string) {
if (!rudderAnalytics) return;
if (!rudderAnalytics) {
pendingEvents.push(() => {
recordPageView(pageName)
})
return;
}
try {
rudderAnalytics.page('category', pageName, {
hashId: localStorage.getItem('hashId'),
Expand Down

2 comments on commit 6aee127

@vercel
Copy link

@vercel vercel bot commented on 6aee127 Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 6aee127 Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.