FIX: dfp category targeting params
DFP category targeting param wasn't always being updated on topic list pages. Also remove dependency on a category param being passed in to the component from a template so that we can now place dfp ads in places that don't have access to the current category and targeting will still work.
This commit is contained in:
parent
7af8f1d46b
commit
04525d0cf1
|
@ -8,6 +8,11 @@ export default Ember.Component.extend({
|
||||||
"router.currentRoute.parent.attributes.category_id"
|
"router.currentRoute.parent.attributes.category_id"
|
||||||
),
|
),
|
||||||
|
|
||||||
|
currentCategorySlug: Ember.computed.or(
|
||||||
|
"router.currentRoute.attributes.category.slug",
|
||||||
|
"router.currentRoute.parent.attributes.category.slug"
|
||||||
|
),
|
||||||
|
|
||||||
@computed("currentUser.groups")
|
@computed("currentUser.groups")
|
||||||
showToGroups(groups) {
|
showToGroups(groups) {
|
||||||
const currentUser = Discourse.User.current();
|
const currentUser = Discourse.User.current();
|
||||||
|
|
|
@ -266,22 +266,23 @@ export default AdComponent.extend({
|
||||||
return this.isNthPost(parseInt(this.siteSettings.dfp_nth_post_code));
|
return this.isNthPost(parseInt(this.siteSettings.dfp_nth_post_code));
|
||||||
},
|
},
|
||||||
|
|
||||||
@observes("refreshOnChange")
|
@on("didUpdate")
|
||||||
refreshAd() {
|
updated() {
|
||||||
var slot = ads[this.get("divId")];
|
if (this.get("listLoading")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let slot = ads[this.get("divId")];
|
||||||
if (!(slot && slot.ad)) {
|
if (!(slot && slot.ad)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this,
|
let ad = slot.ad,
|
||||||
ad = slot.ad;
|
categorySlug = this.get("currentCategorySlug");
|
||||||
|
|
||||||
if (this.get("loadedGoogletag") && this.get("refreshOnChange")) {
|
if (this.get("loadedGoogletag")) {
|
||||||
window.googletag.cmd.push(function() {
|
window.googletag.cmd.push(function() {
|
||||||
ad.setTargeting(
|
ad.setTargeting("discourse-category", categorySlug || "0");
|
||||||
"discourse-category",
|
|
||||||
self.get("category") ? self.get("category") : "0"
|
|
||||||
);
|
|
||||||
window.googletag.pubads().refresh([ad]);
|
window.googletag.pubads().refresh([ad]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -293,7 +294,7 @@ export default AdComponent.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
let self = this;
|
||||||
loadGoogle(this.siteSettings).then(function() {
|
loadGoogle(this.siteSettings).then(function() {
|
||||||
self.set("loadedGoogletag", true);
|
self.set("loadedGoogletag", true);
|
||||||
window.googletag.cmd.push(function() {
|
window.googletag.cmd.push(function() {
|
||||||
|
@ -306,7 +307,7 @@ export default AdComponent.extend({
|
||||||
if (slot && slot.ad) {
|
if (slot && slot.ad) {
|
||||||
slot.ad.setTargeting(
|
slot.ad.setTargeting(
|
||||||
"discourse-category",
|
"discourse-category",
|
||||||
self.get("category") ? self.get("category") : "0"
|
self.get("currentCategorySlug") || "0"
|
||||||
);
|
);
|
||||||
window.googletag.display(self.get("divId"));
|
window.googletag.display(self.get("divId"));
|
||||||
window.googletag.pubads().refresh([slot.ad]);
|
window.googletag.pubads().refresh([slot.ad]);
|
||||||
|
|
Loading…
Reference in New Issue