Skip to content

Commit

Permalink
Merge pull request #122 from aswathy-deriv/cookies-changes
Browse files Browse the repository at this point in the history
Aswathy/fix: cookies removing issue
  • Loading branch information
prince-deriv authored Sep 25, 2024
2 parents 91b3051 + 009c692 commit e928879
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/rudderstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { RudderAnalytics } from '@rudderstack/analytics-js'
import { TCoreAttributes, TEvents } from './types'
import { v6 as uuidv6 } from 'uuid'
import Cookies from 'js-cookie'

interface AnalyticsEvent {
name: string
properties: {
[key: string]: string
}
}
export class RudderStack {
analytics = new RudderAnalytics()
has_identified = false
Expand Down Expand Up @@ -51,18 +44,17 @@ export class RudderStack {

/** For caching mechanism, Rudderstack SDK, first page load */
handleCachedEvents = () => {
const storedEvents = Cookies.get('cached_analytics_events')
const storedEvents: any = Cookies.get('cached_analytics_events')

try {
if (storedEvents) {
let eventQueue: AnalyticsEvent[] = JSON.parse(storedEvents) as AnalyticsEvent[]

if (eventQueue.length > 0) {
eventQueue.forEach(event => {
if (storedEvents.length > 0) {
storedEvents.forEach((event: any) => {
this.analytics.track(event.name, event.properties)
})

eventQueue = []
Cookies.remove('cached_analytics_events')
storedEvents.length = 0
Cookies.remove('cached_analytics_events', { domain: '.deriv.com' })
}
}
} catch (error) {
Expand Down

0 comments on commit e928879

Please sign in to comment.