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

native tracker manager click tracker not firing #103

Merged
merged 1 commit into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/nativeTrackerManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,7 @@ export function newNativeTrackerManager(win) {
return adId || '';
}

function readAdIdFromEvent(event) {
let adId =
event &&
event.target &&
event.target.attributes &&
event.target.attributes[AD_DATA_ADID_ATTRIBUTE] &&
event.target.attributes[AD_DATA_ADID_ATTRIBUTE].value;

return adId || '';
}

function loadClickTrackers(event) {
let adId = readAdIdFromEvent(event);
function loadClickTrackers(event, adId) {
fireTracker(adId, 'click');
}

Expand All @@ -57,7 +45,10 @@ export function newNativeTrackerManager(win) {
adElements = adElements || findAdElements(AD_ANCHOR_CLASS_NAME);

for (let i = 0; i < adElements.length; i++) {
adElements[i].addEventListener('click', listener, true);
let adId = readAdIdFromSingleElement(adElements[i]);
adElements[i].addEventListener('click', function(event) {
listener(event, adId);
}, true);
}
}

Expand Down Expand Up @@ -88,16 +79,16 @@ export function newNativeTrackerManager(win) {
}
const boundedLoadMobileClickTrackers = loadMobileClickTrackers.bind(null, clickTrackers);
attachClickListeners(false, boundedLoadMobileClickTrackers);

(impTrackers || []).forEach(triggerPixel);
}
nativeAssetManager.loadMobileAssets(targetingData, cb);
} else {
let parsedUrl = parseUrl(targetingData && targetingData.pubUrl);
publisherDomain = parsedUrl.protocol + '://' + parsedUrl.host;

let adElements = findAdElements(AD_ANCHOR_CLASS_NAME);

nativeAssetManager.loadAssets(
readAdIdFromElement(adElements),
attachClickListeners
Expand Down
17 changes: 6 additions & 11 deletions test/spec/nativeTrackerManager_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('nativeTrackerManager', function () {
describe('load startTrackers', function () {
let mockWin;
let consoleWarn;

let tagData = {
pubUrl: 'http://example.com'
};
Expand Down Expand Up @@ -70,13 +70,6 @@ describe('nativeTrackerManager', function () {
},
addEventListener: ((type, listener, capture) => {
listener({
target: {
attributes: {
pbAdId: {
value: 'ad123'
}
}
}
})
})
}];
Expand All @@ -96,16 +89,18 @@ describe('nativeTrackerManager', function () {
expect(trimPort(postMessageTargetDomain)).to.equal(tagData.pubUrl);
});

it('should verify the warning message was executed', function() {
it('should verify 2 warning messages (one for impression, one for click) was executed', function() {
mockWin.document.getElementsByClassName = () => [{
addEventListener: ((type, listener, capture) => {
listener({
})
})
}];

let nativeTracker = new newNativeTrackerManager(mockWin);
nativeTracker.startTrackers(tagData);

expect(consoleWarn.callCount).to.equal(1);
expect(consoleWarn.callCount).to.equal(2);
});
});
});
});