GPT - Non key value ads showing in key valuse ad slots - javascript

I have set up Ad Units and Key Values in DFP. I have built the site with the following code based on Google's tutorials:
<html lang="en">
<head>
<script type="text/javascript">
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement("script");
gads.async = true;
gads.type = "text/javascript";
var useSSL = "https:" == document.location.protocol;
gads.src = (useSSL ? "https:" : "http:") + "//www.googletagservices.com/tag/js/gpt.js";
var node =document.getElementsByTagName("script")[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script>
var sitePath = "/test-kv/parent/page"
googletag.cmd.push(function() {
var kvAdSlot =
googletag.defineSlot('/00000000' + sitePath, [300, 250], 'kvAd');
kvAdSlot.addService(googletag.pubads());
kvAdSlot.setTargeting('key', 'value');
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
</head>
<body>
<div id='kvAd'>
<script>
googletag.cmd.push(function() { googletag.display('kvAd'); });
</script>
</div>
</body>
</html>
However, when I test the page, my ROS ads (which have no key values assigned but target all ad units) are showing up. I have been messing with this for a while and cannot figure out why the setTargeting doesn't seem to be working properly to keep non targeted ads out of the key value ad slot.

It's perfectly logical that your ROS ads are returned. Google DFP will not exclude ads based on setTargeting unless specifically defined in your line-item.
In your line-item, if you were to specify that the ROS should be shown IF "key" is not equal to "value", then the ROS ads would not be shown.

Related

How can I dynamically update 'src' in <script src=> in Squarespace

I an trying to grab url parameters onto a Zoho form in Squarespace for Google tracking purposes. I made a custom function to get the parameter and add it to a url. The alerts at the end are just to show that it is getting set correctly. But I am unable to add the form with the variable 'site'.
<script type="text/javascript">
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
var campaign = getUrlVars()["campaign"];
var site = "https://forms.zohopublic.com/....wj7Q?campaign="+campaign;
var scriptElement = document.createElement('script');
scriptElement.type = "text/javascript";
scriptElement.src = site;
scriptElement.id = "ZFScript";
document.head.appendChild(scriptElement);
alert(decodeURI(campaign));
alert(site);
alert(scriptElement.src);
alert(scriptElement.type);
alert(scriptElement.id);
</script>
So at the end I just need to run
<script type="text/javascript" src=site id="ZFScript"></script>
But I can not get it to write a new script with src equaling the site variable.
If you are using only javascript, you almost got it as #Julesezaar comment, I complement it with something like this:
document.getElementById('ZFScript').setAttribute('src',site);
And you are done.

Placing Amazon Banner | Angular V4

I'm placing an Amazon banner inside an angular material 2 card.But the problem is that it is not rendering.It shows empty div.What could be the reason.Below is the code showing how I did it.
<md-card class="full-width full-height border-box ">
<div class="adv">
<script type="text/javascript" language="javascript">
var aax_size = '728x90';
var aax_pubname = 'XXXXXXXXXXX';
var aax_src = '302';
</script>
<script type="text/javascript" language="javascript" src="http://c.amazon-adsystem.com/aax2/assoc.js"></script>
</div>
</md-card>
I also tried to to bind it using property binding
<span [innerHTML]="advertisement()"></span>
advertisement(){
return `<div class="adv">
<script type="text/javascript" language="javascript">
var aax_size = '728x90';
var aax_pubname = 'XXXXXXXXXXX';
var aax_src = '302';
</script>
<script type="text/javascript" language="javascript" src="http://c.amazon-adsystem.com/aax2/assoc.js"></script>
</div>`;
}
I also tried to dynamically add the div inside my card,it shows inside the div but the banner doesn't appear.Below is the code showing how I did that.
ngAfterViewInit() {
let x: HTMLElement = document.getElementById('adv');
let s: HTMLScriptElement = document.createElement('script');
s.type = 'text/javascript';
// s.language = 'javascript';
let code = `var aax_size = '728x90';
var aax_pubname = 'XXXXXXX';
var aax_src = '302';`;
let src = document.createElement('script');
src.type = 'text/javascript';
// src.language = 'javascript';
src.src = 'http://c.amazon-adsystem.com/aax2/assoc.js';
try {
s.appendChild(document.createTextNode(code));
x.appendChild(s);
x.appendChild(src);
} catch (e) {
s.text = code;
document.body.appendChild(s);
}
console.log(x);
}
After scrapping every post in SO regarding or similar to this question I did not find any solution to this.I followed almost everything in those posts but nothing was working for me.After that I came across postscribe library which does the externally loading of any third party script.
First I installed the library and imported it in my component
import * as postscribe from 'postscribe';
After that all I did was calling a function inside my ngAfterViewInit function, by targetting the div with its id which in my case was adv and passed the script as a second parameter to this function.
ngAfterViewInit() {
postscribe('#adv', `<script type="text/javascript" language="javascript">
var aax_size='728x90';
var aax_pubname = 'XXXXXXXX';
var aax_src='302';
</script>
<script type="text/javascript" language="javascript" src="http://c.amazon-adsystem.com/aax2/assoc.js"></script>`);}
By doing this my banner was loaded.

Disqus in Cordova/Ionic app gets stuck on Disqus page

I am trying to add Disqus to my Ionic/Cordova app. I have successfully got the Disqus widget to appear in a template using an iframe but if I click on the Disqus widget to login to Disqus to add a comment, or look at the Disqus community tab, for example, then the app goes to a non scrollable Disqus page that fills all of the screen and there is no way to get back to the app.
Is there a way to make the page it goes to scrollable and smaller than the screen so the user can get back into the app.
The Disqus code server on a static server is:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<div id="disqus_thread"></div>
<script type="text/javascript">
var params;
var disqus_url;
var disqus_title;
var disqus_shortname;
var disqus_identifier;
window.onload = function () {
var match,
pattern = /\+/g,
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pattern, " ")); },
query = window.location.search.substring(1);
params = {};
while (match = search.exec(query))
params[decode(match[1])] = decode(match[2]);
if (params["shortname"] === undefined || params["url"] === undefined || params["title"] === undefined) {
alert("Required arguments missing");
}
else {
loadComments(params["shortname"], params["url"], params["title"], params["identifier"]);
}
};
function loadComments(shortname, url, title, identifier) {
disqus_url = url;
disqus_title = title;
disqus_shortname = shortname;
if (identifier !== undefined)
disqus_identifier = identifier;
else
disqus_identifier = "";
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = false;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
}
</script>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
blog comments powered by <span class="logo-disqus">Disqus</span>
</body>
</html>
In my app's controller I have:
var disqus_title = "TEST";
var disqus_identifier = '/movie/' + 0;
var disqus_url = 'http://example.com/movie/' + 0;
var url = "http://example.com/disqus.html?";
$scope.disqusurl = url + "shortname=example&url=" + encodeURIComponent(disqus_url) +
"&title=" + encodeURIComponent(disqus_title) + "&identifier=" + encodeURIComponent(disqus_identifier);
$scope.disqusurl = $sce.trustAsResourceUrl($scope.disqusurl);
The relevant part of the template file looks like this:
<ion-content>
...
<iframe style="max-height: 40%;" src="{{disqusurl}}"></iframe>
...
</ion-content>
EDIT
The problem seems to be that the web links in the Disqus widget are launched within the app. If somehow the links could be made to open in an external browser then all might work fine but I can't see how to make pulled in HTML code work this way.
Here's what I would try:
1) try to over ride disqus's css using !important selector
2) try to load in content with ajax
3) search and read articles like this: https://help.disqus.com/customer/portal/articles/472096-using-disqus-in-mobile-apps
4) have an iframe to a page on your website that has disqus, and make the iframe smaller than page height.

Broken Embed Code - rateabiz

I received the following Review Widget code from a client which i cannot get functioning.
<script type="text/javascript">
(function(w, d) {
w._rab_review_q = w._rab_review_q || [];
w._rab_review_q.push({
id: '66e0c56a275da98c80814d01513be966',
reviewDivId: 'review-widget-container'
});
var el = d.createElement("script");
el.async=true;
el.src="//cdn.rateabiz.com/reviews/loader.js";
el.type="text/javascript";
var s0 = d.getElementsByTagName("script")[0];
s0.parentNode.insertBefore(el, s0);
})(window, document);
</script>
<div style="width:220px;" id="review-widget-container"></div>
I have tried the code on one of our development wp sites http://doctor-connect.org/about-us/ with all plugins turned off, i have also tried a straight up html page that again produces no results (http://doctor-connect.org/testing.html).
Unfortunately the client will not provide me with their account details and i cannot find any customer support info for Rateabiz.
Any ideas on what might be going wrong?
Here's an example of a currently working model if it helps. Key things I see different are that the template: 'dark' or template: 'light' is missing and that the el.src='.....' are different. Please see the working code below:
<script type="text/javascript">
(function(w, d){
w._rab_review_q = w._rab_review_q || [];
w._rab_review_q.push({
id: '7b258b0c5ec39fc7b15eaf390c70d1b7',
reviewDivId: 'review-widget-container',
template: 'dark'
});
var el = d.createElement("script");
el.async=true;
el.src="//s3.amazonaws.com/cdn.rateabiz.com/reviews/loader.js";
el.type="text/javascript";
var s0 = d.getElementsByTagName("script")[0];
s0.parentNode.insertBefore(el, s0);
})(window, document);
</script>

JavaScript : display Google ad conditionally

I want to display google ads at vbulletin forum when the thread not contains any crack or serial so I write this code:
<div id ="d_content"> post goes here...</div>
<div id="adv_content"></div>
<script>
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
var str = document.getElementById("d_content").innerHTML;
var pattern = /crack|nulled|serial|register|key|pach|patch/gi;
var Len= str.match(pattern);
if( isBlank(Len) ) document.write("adv..");
</script>
but how to put the google ad code instead of "adv.."
this is my try :
<div id ="d_content"> post goes here...</div>
<div id="adv_content"></div>
<script>
function isBlank(str) {
return (!str || /^\s*$/.test(str));
}
var str = document.getElementById("d_content").innerHTML;
var pattern = /crack|nulled|serial|register|key|pach|patch/gi;
var Len= str.match(pattern);
if( isBlank(Len) ) document.write("
<script type="text/javascript"><!--
google_ad_client = "ca-pub-1564912551365218";
/* 728x90, تم إنشاؤها 02/06/11 زهير طه */
google_ad_slot = "7785253845";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
");
</script>
but not worked..
Your code is not going to work because browsers will interpret the first </script> as the end of your script, eve though it is within a text string.
A workaround is to use an escape/unescape sequence:
document.write(unescape("%3Cscript type='text/javascript'%3E[your script here]%3C/script%3E"));
where < is escaped as %3C and > is escaped as %3E.

Categories