I am integrating the clevertap in my angular project and for doing this i have install the npm package for clevertap. I am facing issue when for first time i am login into the application and then bydefault my first screen is dashboard and there i have catch some events and they are not getting fired. but when i refresh the page everthing works fine.
Don't know why this is happening pls help in figuring it out.
this is my service in which i have configure my clevertap code.
// src/app/analytics/analytics.service.ts
import { Injectable } from '@angular/core';
import clevertap from 'clevertap-web-sdk';
import { environment } from 'src/environments/environment';
import { BaseService } from 'src/modules/shared-base/services/base.service';
@Injectable({ providedIn: 'root' })
export class AnalyticsService {
constructor(private baseService: BaseService
) {
const CLEVERTAP_ACCOUNT_ID = environment.clevertapAccountId;
// Replace with your own CleverTap ID and region
// (window as any).clevertap = clevertap;
clevertap.privacy.push({ optOut: false });
clevertap.privacy.push({ useIP: false });
clevertap.init(CLEVERTAP_ACCOUNT_ID)
clevertap.setLogLevel(3);
clevertap.spa = true;
console.log('CleverTap Initialized');
}
logEvent(eventName: string, data: Record<string, any> = {}) {
// Add timestamp to every event
const eventData = {
lat: sessionStorage.getItem('latitude') || '',
long: sessionStorage.getItem('longitude') || '',
location: sessionStorage.getItem('selectedCity') || '',
timestamp: new Date().toISOString(), // ISO 8601 format timestamp
...data
};
if (localStorage.getItem('device_platform') && (localStorage.getItem('device_platform') == "Android" || localStorage.getItem('device_platform') == "iOS")) {
this.baseService.cleverTapEventHandling(eventName, eventData);
}
else {
// setTimeout(()=>{
clevertap.event.push(eventName, eventData);
// },1000)
}
}
onLoginUser(userData:any){
clevertap.profile.push({Site:{...userData}})
}
}