Skip to content

Commit

Permalink
Revert "fix: Fix le tracker floodlight (#3455)"
Browse files Browse the repository at this point in the history
This reverts commit 0b55a4a.
  • Loading branch information
Mintoo200 authored and sokl-octo committed Jan 24, 2025
1 parent e3c5781 commit 2a77838
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@ 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().then(() => {
// eslint-disable-next-line
// @ts-ignore
window.gtag('config', GoogleTagManagerService.ADS_ID);
service.ready = true;
document.dispatchEvent(new CustomEvent('floodlight_ready'));
});
gtagService.mount();
},
key: FloodlightMarketingService.SERVICE_NAME,
name: 'Floodlight',
Expand All @@ -36,22 +27,16 @@ 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]',
});

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

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

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; }
mount() {
if (this.mounted) { return; }

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();
}
service.pending.forEach((resolve) => resolve());
service.status = 'mounted';
document.dispatchEvent(new CustomEvent('gtag_ready'));
});
return result;
this.mounted = true;
}

cookies() {
Expand Down
21 changes: 2 additions & 19 deletions src/client/services/marketing/seedtag/seedtag.marketing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,15 @@ 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';
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'));
});
gtagService.mount();
},
key: SeedtagMarketingService.SEEDTAG_SERVICE_NAME,
name: 'Seedtag',
Expand All @@ -37,23 +27,16 @@ 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: 1 addition & 2 deletions src/pages/apprentissage-entreprises/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export default function ApprentissageEntreprises ({ videos }: ApprentissageEntre
useEffect(() => {
seedtagService.trackPage('');
floodlightService.trackPage('');
// eslint-disable-next-line
}, []);
}, [floodlightService, seedtagService]);

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

return (
<>
Expand Down

0 comments on commit 2a77838

Please sign in to comment.