Skip to content

Commit

Permalink
feat(3PT): Add inizio (#40)
Browse files Browse the repository at this point in the history
* refactor(types): add inizio types to the window

* refactor(types): use DefinitelyTyped for Googletag

* feat(third-party-tag): add inizio

* test(inizio): add inizio test

* fix(inizio): use name instead of sourcepointId

* refactor(suggestion): make it hipster

I cheated by changing the commit message :)

Co-authored-by: Alex Sanders <[email protected]>

* style(inizio): remove eslint ignores

* refactor(types): include googletag in ESLint globals

* chore(deps): update dependencies

* refactor(inizio): looser check on matching

* leave sourcepointID out of ThirdPartyTag

Co-authored-by: Alex Sanders <[email protected]>
  • Loading branch information
mxdvl and sndrs authored Oct 16, 2020
1 parent b4630ad commit c6d35fd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
13 changes: 13 additions & 0 deletions src/third-party-tags/inizio.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
});
});
});
32 changes: 32 additions & 0 deletions src/third-party-tags/inizio.ts
Original file line number Diff line number Diff line change
@@ -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,
});
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ declare global {
interface Window {
google_trackConversion: (arg0: GoogleTrackConversionObject) => void;
google_tag_params: GoogleTagParams;
_brandmetrics?: { cmd: string; val: Record<string, unknown> }[];
googletag: googletag.Googletag;
}
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c6d35fd

Please sign in to comment.