Skip to content

Commit

Permalink
feat: Ajoute le tracker Snapchat (#3463)
Browse files Browse the repository at this point in the history
* feat: Ajoute le tracker Snapchat

* fix: Fix les tests
  • Loading branch information
Mintoo200 authored Nov 22, 2024
1 parent 0e1551f commit ec7df05
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
1 change: 1 addition & 0 deletions public/scripts/tarteaucitron/lang/tarteaucitron.fr.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/client/dependencies.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { MarketingService } from '~/client/services/marketing/marketing.service'
import MetaMarketingService from '~/client/services/marketing/meta/meta.marketing.service';
import { NullMarketingService } from '~/client/services/marketing/null/null.marketing.service';
import SeedtagMarketingService from '~/client/services/marketing/seedtag/seedtag.marketing.service';
import SnapchatMarketingService from '~/client/services/marketing/snapchat/snapchat.marketing.service';
import TiktokMarketingService from '~/client/services/marketing/TikTok/tiktok.marketing.service';
import { BffAlternanceMetierService } from '~/client/services/metiers/bff.alternance.metier.service';
import { MetierService } from '~/client/services/metiers/metier.service';
Expand Down Expand Up @@ -103,6 +104,7 @@ export type Dependencies = {
amnetService: MarketingService
metaService: MarketingService
floodlightService: MarketingService
snapchatService: MarketingService
}

class DependencyInitException extends Error {
Expand Down Expand Up @@ -134,6 +136,7 @@ export default function dependenciesContainer(sessionId?: string): Dependencies
const seedtagService = new SeedtagMarketingService(cookiesService, googleTagManagerService);
const floodlightService = new FloodlightMarketingService(cookiesService, googleTagManagerService);
const tiktokService = new TiktokMarketingService(cookiesService);
const snapchatService = new SnapchatMarketingService(cookiesService);
const azerionService = new AzerionMarketingService(cookiesService);
const amnetService = new AmnetMarketingService(cookiesService);
const metaService = new MetaMarketingService(cookiesService);
Expand Down Expand Up @@ -204,6 +207,7 @@ export default function dependenciesContainer(sessionId?: string): Dependencies
rechercheClientService,
seedtagService,
sessionStorageService,
snapchatService,
stage3eEt2deService,
stageDeposerOffreEtape1PersistenceService,
stageDeposerOffreEtape2PersistenceService,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import { CookiesService } from '~/client/services/cookies/cookies.service';
import { TarteAuCitron } from '~/client/services/cookies/tarteaucitron/tarteAuCitron.cookies.service';

import { MarketingService } from '../marketing.service';

export default class SnapchatMarketingService implements MarketingService {
private static SERVICE_NAME = 'snapchat-custom';
private ready = false;

constructor(private readonly cookiesService: CookiesService) {
this.cookiesService.addUser('snapchatId', 'd48efe29-caa9-4f0c-86e8-353fc35a8b3f');
// 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: [],
js: function () {
'use strict';

// eslint-disable-next-line no-undef
if (tarteaucitron.user.snapchatId === undefined) {
return;
}

const a = window.snaptr = function () {
// eslint-disable-next-line prefer-rest-params, prefer-spread
a.handleRequest ? a.handleRequest.apply(a, arguments) : a.queue.push(arguments);
};
a.queue = [];
// eslint-disable-next-line no-undef
window.snaptr('init', tarteaucitron.user.snapchatId, {});

// eslint-disable-next-line no-undef
tarteaucitron.addScript('https://sc-static.net/scevent.min.js', undefined, () => {
service.ready = true;
document.dispatchEvent(new CustomEvent('snapchat_ready'));
});

// eslint-disable-next-line no-undef
if (typeof tarteaucitron.user.snapchatMore === 'function') {
// eslint-disable-next-line no-undef
tarteaucitron.user.snapchatMore();
}
},
key: SnapchatMarketingService.SERVICE_NAME,
name: 'Snapchat',
needConsent: true,
type: 'analytic',
uri: 'https://snap.com/fr-FR/privacy/privacy-policy',
};
this.cookiesService.addService(SnapchatMarketingService.SERVICE_NAME, config);
}

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

window.snaptr('track', 'PAGE_VIEW');
}
if (this.ready) {
sendAnalytics();
} else {
document.addEventListener('snapchat_ready', sendAnalytics);
}
}
}
5 changes: 5 additions & 0 deletions src/pages/choisir-apprentissage/index.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ describe('Page Apprentissage Jeunes', () => {
tiktokService={aMarketingService()}
analyticsService={aManualAnalyticsService()}
floodlightService={aMarketingService()}
snapchatService={aMarketingService()}
youtubeService={aVideoService()}>
<ApprentissageJeunes videos={videos} />
</DependenciesProvider>);
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('Page Apprentissage Jeunes', () => {
metaService={aMarketingService()}
tiktokService={aMarketingService()}
floodlightService={aMarketingService()}
snapchatService={aMarketingService()}
analyticsService={analyticsService}
youtubeService={aVideoService()}>
<ApprentissageJeunes videos={videos} />
Expand All @@ -149,6 +151,7 @@ describe('Page Apprentissage Jeunes', () => {
amnetService={aMarketingService()}
metaService={aMarketingService()}
tiktokService={aMarketingService()}
snapchatService={aMarketingService()}
floodlightService={aMarketingService()}
analyticsService={analyticsService}>
<ApprentissageJeunes videos={[]} />
Expand All @@ -167,6 +170,7 @@ describe('Page Apprentissage Jeunes', () => {
marketingService={aMarketingService()}
amnetService={aMarketingService()}
metaService={aMarketingService()}
snapchatService={aMarketingService()}
tiktokService={aMarketingService()}
floodlightService={aMarketingService()}
analyticsService={analyticsService}>
Expand All @@ -188,6 +192,7 @@ describe('Page Apprentissage Jeunes', () => {
marketingService={aMarketingService()}
amnetService={aMarketingService()}
metaService={aMarketingService()}
snapchatService={aMarketingService()}
tiktokService={aMarketingService()}
floodlightService={aMarketingService()}
analyticsService={analyticsService}>
Expand Down
12 changes: 6 additions & 6 deletions src/pages/choisir-apprentissage/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ export default function ApprentissageJeunes(props: ApprentissageJeunesPageProps)
return () => adformService.trackPage(undefined);
// eslint-disable-next-line
}, []);
const tiktokService: MarketingService = useDependency('tiktokService');
tiktokService.trackPage('');
const snapchatService: MarketingService = useDependency('snapchatService');
useEffect(() => {
return () => {
tiktokService.trackPage('off');
};
snapchatService.trackPage('');
// eslint-disable-next-line
}, []);
const amnetService: MarketingService = useDependency('amnetService');
amnetService.trackPage('');
useEffect(() => {
amnetService.trackPage('');
// eslint-disable-next-line
}, []);
useEffect(() => {
return () => {
amnetService.trackPage('off');
Expand Down

0 comments on commit ec7df05

Please sign in to comment.