Created
June 18, 2024 00:32
-
-
Save wharley/39d011f97f391a05725bdead92f70f69 to your computer and use it in GitHub Desktop.
/utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { trackFacebookPixelEvent, trackGoogleAdsConversion } from '@/utils'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent implements OnInit { | |
constructor(private analyticsConfig: { setFacebookPixel, setGoogleCode } ) {} | |
ngOnInit() { | |
ngOnInit() { | |
this.analyticsConfig.setFacebookPixel("inputPixel"); | |
ngOnInit() { | |
this.analyticsConfig.setGoogleCode('inputGoogleCode'); | |
} | |
trackPurchase() { | |
trackFacebookPixelEvent(this.analyticsConfig, 'Purchase', { value: 30.00, currency: 'USD' }); | |
trackGoogleAdsConversion(this.analyticsConfig, { value: 30.00, currency: 'USD' }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare var fbq: Function; | |
declare var gtag: Function; | |
export function trackFacebookPixelEvent(configService: any, event: string, data: any = {}) { | |
const pixelId = configService.getFacebookPixelId(); | |
if (typeof fbq === 'function' && pixelId) { | |
fbq('init', pixelId); | |
fbq('track', event, data); | |
} else { | |
console.error('Facebook Pixel não está definido ou ID não configurado.'); | |
} | |
} | |
export function trackGoogleAdsConversion(configService: any, data: any = {}) { | |
const conversionId = configService.getGoogleAdsConversionId(); | |
if (typeof gtag === 'function' && conversionId) { | |
gtag('config', conversionId); | |
gtag('event', 'conversion', { | |
'send_to': conversionId, | |
...data | |
}); | |
} else { | |
console.error('Google Ads gtag não está definido ou ID não configurado.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment