diff --git a/.eslintrc b/.eslintrc index 8edb1d35a..430969719 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,6 +20,7 @@ "plugin:import/typescript", "plugin:eslint-comments/recommended" ], + "globals": { "googletag": "readonly" }, "rules": { "eslint-comments/require-description": ["error", { "ignore": [] }], "eslint-comments/disable-enable-pair": 0, diff --git a/package.json b/package.json index e4f59c4af..24dbf8d65 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "@types/jest": "^26.0.14", "@typescript-eslint/eslint-plugin": "^4.4.0", "@typescript-eslint/parser": "^4.4.0", + "@types/doubleclick-gpt": "^2019041801.0.3", "commitizen": "^4.2.1", "cz-conventional-changelog": "3.3.0", "eslint": "^7.11.0", diff --git a/src/index.ts b/src/index.ts index 5c33f0d8a..e6d89dea9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ export { ias } from './third-party-tags/ias'; export { permutive } from './third-party-tags/permutive'; export { fbPixel } from './third-party-tags/facebook-pixel'; export { twitter } from './third-party-tags/twitter-uwt'; +export { inizio } from './third-party-tags/inizio'; export { remarketing } from './third-party-tags/remarketing'; export { lotame, getLotameData } from './third-party-tags/lotame'; export type { LotameData, ThirdPartyTag } from './types'; diff --git a/src/third-party-tags/inizio.spec.ts b/src/third-party-tags/inizio.spec.ts new file mode 100644 index 000000000..39e2dfc18 --- /dev/null +++ b/src/third-party-tags/inizio.spec.ts @@ -0,0 +1,13 @@ +import { inizio } from './inizio'; + +describe('index', () => { + it('should use the feature switch option', () => { + const inizioInstance = inizio({ shouldRun: true }); + expect(inizioInstance).toMatchObject({ + shouldRun: true, + url: + '//cdn.brandmetrics.com/survey/script/e96d04c832084488a841a06b49b8fb2d.js', + name: 'inizio', + }); + }); +}); diff --git a/src/third-party-tags/inizio.ts b/src/third-party-tags/inizio.ts new file mode 100644 index 000000000..48c32d26f --- /dev/null +++ b/src/third-party-tags/inizio.ts @@ -0,0 +1,32 @@ +import { GetThirdPartyTag } from '../types'; + +const onLoad = () => { + const handleQuerySurveyDone = ( + surveyAvailable: boolean, + survey: { measurementId: string }, + ) => { + if (surveyAvailable) { + if (window && window.googletag) { + window.googletag.cmd.push(() => { + window.googletag.pubads().setTargeting('inizio', 't'); + }); + } + console.log(`surveyAvailable: ${survey.measurementId}`); + } + }; + window._brandmetrics ||= []; + window._brandmetrics.push({ + cmd: '_querySurvey', + val: { + callback: handleQuerySurveyDone, + }, + }); +}; + +export const inizio: GetThirdPartyTag = ({ shouldRun }) => ({ + shouldRun, + url: + '//cdn.brandmetrics.com/survey/script/e96d04c832084488a841a06b49b8fb2d.js', + name: 'inizio', + onLoad, +}); diff --git a/src/types.ts b/src/types.ts index 6aa94af0a..c78e445d3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -29,6 +29,8 @@ declare global { interface Window { google_trackConversion: (arg0: GoogleTrackConversionObject) => void; google_tag_params: GoogleTagParams; + _brandmetrics?: { cmd: string; val: Record }[]; + googletag: googletag.Googletag; } } diff --git a/yarn.lock b/yarn.lock index 36afba953..fccb13b14 100644 --- a/yarn.lock +++ b/yarn.lock @@ -899,6 +899,11 @@ dependencies: "@babel/types" "^7.3.0" +"@types/doubleclick-gpt@^2019041801.0.3": + version "2019041801.0.3" + resolved "https://registry.yarnpkg.com/@types/doubleclick-gpt/-/doubleclick-gpt-2019041801.0.3.tgz#93c37580b45e2bb891d2c8172c8154dbe14b1826" + integrity sha512-tUQFjyf5wgm/LCvJhynjulz7eDLqERsWYeLSlYXlMJClQZR3abKTZSEBWPIj2nsTfniGFuiyxuhFuArX2RVO5Q== + "@types/graceful-fs@^4.1.2": version "4.1.3" resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"