Skip to content

Instantly share code, notes, and snippets.

@jackie1santana
Created June 22, 2025 17:57
Show Gist options
  • Save jackie1santana/adedb464efe121478c19a7fff1729098 to your computer and use it in GitHub Desktop.
Save jackie1santana/adedb464efe121478c19a7fff1729098 to your computer and use it in GitHub Desktop.
// Add this to your ModelingEventInitiateComponent
import { trackAnalytics } from '@app/services/common/track-analytics/analytics';
export class ModelingEventInitiateComponent implements OnInit {
// ... your existing properties ...
public ngOnInit(): void {
// ... your existing ngOnInit code ...
// Add tracking at the end of ngOnInit
this.trackPlanningPageLoad();
}
/**
* Track planning page load with dynamic life event type and available benefits
*/
private trackPlanningPageLoad(): void {
try {
const eventType = this.getLifeEventType();
const availableBenefits = this.getAvailableBenefitTypes();
// Track page view
trackAnalytics({
vv: 'ip', // ip = page view
sec1: 'fhb',
dvn: `lem ${eventType} planning`,
intname: `lem ${eventType} planning`
});
// Track available benefit types for this life event
availableBenefits.forEach(benefitType => {
trackAnalytics({
vv: 'ip', // Still page view, but for each benefit type available
sec1: 'fhb',
dvn: `lem ${eventType} planning`,
intname: `${benefitType} available for ${eventType}`
});
});
} catch (error) {
console.error('Analytics tracking error:', error);
}
}
/**
* Get the current life event type
* Replace this with however you determine the event type in your component
*/
private getLifeEventType(): string {
// Look for properties like:
// - this.eventCode
// - this.eventName
// - this.selectedEventType
// - this.modelingParams
// - route parameters
// Check route parameters first
if (this.route.snapshot.params['eventType']) {
return this.route.snapshot.params['eventType'].toLowerCase();
}
// Check component properties
if (this.eventCode) {
return this.eventCode.toLowerCase();
}
if (this.eventName) {
return this.eventName.toLowerCase();
}
// Check if it's in the URL
const url = window.location.href;
if (url.includes('retirement')) return 'retirement';
if (url.includes('cobra')) return 'cobra';
if (url.includes('marriage')) return 'marriage';
if (url.includes('birth')) return 'birth';
if (url.includes('adoption')) return 'adoption';
if (url.includes('address')) return 'address change';
if (url.includes('domestic')) return 'domestic partner';
return 'unknown';
}
/**
* Get available benefit types for the current life event
* This determines what benefits are "in scope" for this life event type
*/
private getAvailableBenefitTypes(): string[] {
const eventType = this.getLifeEventType();
// This logic should match your business rules for what benefits
// are available for each life event type
switch (eventType) {
case 'retirement':
return this.getRetirementBenefits();
case 'cobra':
return ['medical', 'dental', 'vision']; // COBRA typically only these
case 'marriage':
case 'domestic partner':
return ['medical', 'dental', 'vision', 'hra', 'eap']; // Can add spouse/partner
case 'birth':
case 'adoption':
return ['medical', 'dental', 'vision', 'eap']; // Adding dependent
case 'address change':
return ['medical', 'dental', 'vision']; // Might affect network
default:
return ['medical', 'dental', 'vision']; // Default set
}
}
/**
* Get retirement-specific benefits
* Retirees might have different benefit options
*/
private getRetirementBenefits(): string[] {
const benefits = ['medical', 'dental', 'vision'];
// Add HRA if applicable for retirees
if (this.isHRAAvailableForRetiree()) {
benefits.push('hra');
}
// Add EAP if applicable for retirees
if (this.isEAPAvailableForRetiree()) {
benefits.push('eap');
}
return benefits;
}
/**
* Check if HRA is available for this retiree
* Replace with your actual business logic
*/
private isHRAAvailableForRetiree(): boolean {
// This might depend on:
// - Employee's age
// - Years of service
// - Company policy
// - Current benefit elections
// For now, check if HRA benefits exist in your data
return this.benefitGroups?.some(bg =>
bg.benefits?.some(b => b.type?.toLowerCase().includes('hra'))
) || false;
}
/**
* Check if EAP is available for this retiree
* Replace with your actual business logic
*/
private isEAPAvailableForRetiree(): boolean {
// Similar logic to HRA
return this.benefitGroups?.some(bg =>
bg.benefits?.some(b => b.type?.toLowerCase().includes('eap'))
) || false;
}
/**
* Track Get Started button click (for your other requirement)
*/
public trackGetStartedClick(): void {
const eventType = this.getLifeEventType();
trackAnalytics({
vv: 'ie', // ie = interaction
sec1: 'fhb',
dvn: `lem ${eventType} planning`,
intname: `get started ${eventType}`
});
}
}
// UPDATE YOUR TEMPLATE:
// Make sure your "Get Started" button calls the tracking:
// <button (click)="handleGetStartedClick()">Get Started</button>
// Add this method to handle the button click:
public handleGetStartedClick(): void {
// Your existing button logic
this.goToTemplatePage(); // or whatever your existing method is
// Add analytics tracking
this.trackGetStartedClick();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment