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 'googletagservices-gpt' — updateTargetingFromMap() #293

Closed
AdamWr opened this issue Feb 28, 2023 · 1 comment
Closed

Fix 'googletagservices-gpt' — updateTargetingFromMap() #293

AdamWr opened this issue Feb 28, 2023 · 1 comment

Comments

@AdamWr
Copy link
Member

AdamWr commented Feb 28, 2023

If I'm not wrong, the problem is not related to redirect resource itself, but rather to the way how it's build.
It looks like that after script is compiled/built, then some methods are missed, in this case there is slicedToArray missed.

Steps to reproduce:

  1. Use latest nightly build which use latest version of googletagservices-gpt redirect resource
  2. Enable AdGuard Tracking Protection filter
  3. Go to - https://example.org/
  4. Run in browser console:
const script = document.createElement('script');
script.setAttribute("type", "text/javascript");
script.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js';
document.getElementsByTagName('head')[0].appendChild(script);
script.onload = () => {
  const slot = googletag.defineSlot('/1234567/sports', [160, 600], 'div-1');
  slot.updateTargetingFromMap({
    'color': 'red',
    'interests': ['sports']
  });
};

There is an error - gpt.js:1 Uncaught ReferenceError: slicedToArray is not defined

Screenshot

image

The same happens with test like this:

test('Test updateTargetingFromMap', (assert) => {
    runRedirect(name);

    assert.ok(window.googletag, 'window.googletag have been created');
    assert.strictEqual(typeof window.googletag.defineSlot(), 'object', 'Slot has been mocked');

    const optDiv = 3;

    const slot = window.googletag.defineSlot('1', 2, optDiv);
    slot.updateTargetingFromMap({
        color: 'red',
        interests: ['sports'],
    });
    assert.strictEqual(slot.getTargeting('interests')[0], 'sports', '.getTargeting() has been mocked.');
    assert.strictEqual(window.hit, 'FIRED', 'hit function was executed');
});
Screenshot

image

It seems the problem is related to this line:

for (const [k, v] of entries) {
    targeting.set(k, getTargetingValue(v));
}

here:

const updateTargeting = (targeting, map) => {
if (typeof map === 'object') {
const entries = Object.entries(map || {});
for (const [k, v] of entries) {
targeting.set(k, getTargetingValue(v));
}
}
};

@AdamWr
Copy link
Member Author

AdamWr commented Mar 1, 2023

One more thing, it seems that in Chrome, setting the sandbox attribute to true causes errors in console.

f.setAttribute('sandbox', true);

Screenshot

image

I guess it could just be:

f.setAttribute('sandbox', '');

@adguard-bot adguard-bot assigned maximtop and unassigned zzebrum Mar 3, 2023
@adguard-bot adguard-bot changed the title Fix 'googletagservices-gpt' — 'updateTargetingFromMap' Fix 'googletagservices-gpt' — updateTargetingFromMap() May 16, 2023
@adguard-bot adguard-bot assigned slavaleleka and unassigned maximtop May 16, 2023
adguard pushed a commit that referenced this issue May 18, 2023
Squashed commit of the following:

commit b7f12a4
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed May 17 16:27:11 2023 +0200

    Use hasOwnProperty() method instead of hasOwn()

commit 10e7098
Author: Adam Wróblewski <adam@adguard.com>
Date:   Wed May 17 16:08:08 2023 +0200

    Fix issue with updateTargetingFromMap() method in  googletagservices-gpt redirect resource
    Fix issue with sandbox attribute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants