Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix le tracker floodlight #3455

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ import { MarketingService } from '../marketing.service';

export default class FloodlightMarketingService implements MarketingService {
static readonly SERVICE_NAME = 'floodlight';
private ready = false;

constructor(private readonly cookiesService: CookiesService, private readonly gtagService: GoogleTagManagerService) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const service = this;
// eslint-disable-next-line
type ConfigObject = any;
const config: TarteAuCitron.ServiceConfig<ConfigObject> = {
cookies: this.gtagService.cookies(),
js: function () {
'use strict';
gtagService.mount();
gtagService.mount().then(() => {
// eslint-disable-next-line
// @ts-ignore
window.gtag('config', GoogleTagManagerService.ADS_ID);
service.ready = true;
document.dispatchEvent(new CustomEvent('floodlight_ready'));
});
},
key: FloodlightMarketingService.SERVICE_NAME,
name: 'Floodlight',
Expand All @@ -27,16 +36,22 @@ export default class FloodlightMarketingService implements MarketingService {

// eslint-disable-next-line
trackPage(pagename: string): void {
const cookiesService = this.cookiesService;
function sendAnalytics() {
if (!cookiesService.isServiceAllowed(FloodlightMarketingService.SERVICE_NAME)) { return; }

// eslint-disable-next-line
// @ts-ignore
window.gtag('event', 'conversion', {
allow_custom_scripts: true,
send_to: 'DC-3048978/appre0/24appren+unique',
u1: '[URL]',
});

}
document.addEventListener('gtag_ready', sendAnalytics);
if (this.ready) {
sendAnalytics();
} else {
document.addEventListener('floodlight_ready', sendAnalytics, { once: true });
}
}
}
23 changes: 12 additions & 11 deletions src/client/services/marketing/googleTagManager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,32 @@

export default class GoogleTagManagerService {
static readonly ADS_ID = 'DC-10089018';
private mounted = false;
private status: 'unmounted' | 'mounting' | 'mounted' = 'unmounted';
private pending = [];

mount() {
if (this.mounted) { return; }
async mount() {
if (this.status === 'mounted') { return; }
// eslint-disable-next-line @typescript-eslint/no-this-alias
const service = this;
const result = new Promise((resolve) => {this.pending.push(resolve);});
if (this.status === 'mounting') { return result; }

this.status = 'mounting';
window.dataLayer = window.dataLayer || [];
window.tarteaucitron.addScript('https://www.googletagmanager.com/gtag/js?id=' + GoogleTagManagerService.ADS_ID, '', function () {
window.gtag = function gtag() {
// eslint-disable-next-line prefer-rest-params
window.dataLayer.push(arguments);
};
window.gtag('js', new Date());
const additional_config_info = (window.timeExpire !== undefined) ? {
anonymize_ip: true,
cookie_expires: window.timeExpire / 1000,
} : { anonymize_ip: true };

window.gtag('config', GoogleTagManagerService.ADS_ID, additional_config_info);

if (typeof window.tarteaucitron.user.googleadsMore === 'function') {
window.tarteaucitron.user.googleadsMore();
}
document.dispatchEvent(new CustomEvent('gtag_ready'));
service.pending.forEach((resolve) => resolve());
service.status = 'mounted';
});
this.mounted = true;
return result;
}

cookies() {
Expand Down
21 changes: 19 additions & 2 deletions src/client/services/marketing/seedtag/seedtag.marketing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@ import { MarketingService } from '../marketing.service';

export default class SeedtagMarketingService implements MarketingService {
static readonly SEEDTAG_SERVICE_NAME = 'seedtag';
private ready = false;

constructor(private readonly cookiesService: CookiesService, private readonly gtagService: GoogleTagManagerService) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const service = this;
// eslint-disable-next-line
type ConfigObject = any;
const config: TarteAuCitron.ServiceConfig<ConfigObject> = {
cookies: this.gtagService.cookies(),
js: function () {
'use strict';
gtagService.mount();
const promise = gtagService.mount();
promise.then(() => {
// eslint-disable-next-line
// @ts-ignore
window.gtag('config', GoogleTagManagerService.ADS_ID);
service.ready = true;
document.dispatchEvent(new CustomEvent('seedtag_ready'));
});
},
key: SeedtagMarketingService.SEEDTAG_SERVICE_NAME,
name: 'Seedtag',
Expand All @@ -27,16 +37,23 @@ export default class SeedtagMarketingService implements MarketingService {

// eslint-disable-next-line
trackPage(pagename: string): void {
const cookiesService = this.cookiesService;
function sendAnalytics() {
if (!cookiesService.isServiceAllowed(SeedtagMarketingService.SEEDTAG_SERVICE_NAME)) { return; }
// eslint-disable-next-line
// @ts-ignore
window.gtag('event', 'conversion', {
allow_custom_scripts: true,
send_to: `${GoogleTagManagerService.ADS_ID}/invmedia/fr_ga005+standard`,
u2: '[URL_Info]',
});
}
if (!this.cookiesService.isServiceAllowed(SeedtagMarketingService.SEEDTAG_SERVICE_NAME)) { return; }

if (this.ready) {
sendAnalytics();
} else {
document.addEventListener('seedtag_ready', sendAnalytics, { once: true });
}
document.addEventListener('gtag_ready', sendAnalytics);
}
}
3 changes: 2 additions & 1 deletion src/pages/apprentissage-entreprises/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export default function ApprentissageEntreprises ({ videos }: ApprentissageEntre
useEffect(() => {
seedtagService.trackPage('');
floodlightService.trackPage('');
}, [floodlightService, seedtagService]);
// eslint-disable-next-line
}, []);

const azerionService: MarketingService = useDependency('azerionService');
azerionService.trackPage('');
Expand Down
3 changes: 2 additions & 1 deletion src/pages/choisir-apprentissage/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default function ApprentissageJeunes(props: ApprentissageJeunesPageProps)
const floodlightService = useDependency<MarketingService>('floodlightService');
useEffect(() => {
floodlightService.trackPage('');
});
// eslint-disable-next-line
}, []);

return (
<>
Expand Down