I am currently trying to use one single feed for 4 different format of ads.(300x250,300x600,160x600,728x90). Each of them use a different image background (different size and cropping).
The feed will contain in the URL column the last part of the image url : myimage.jpg... the true url to be constructed would be https://www.mydomain.com/dam/300x600/myimage.jpg?wid=300&fit=1. The first part will be constructed on the load by the Ad itself and would allow any add to use one single feed.
In order to do so, I would do the following in my <body> loading 2 <img>, one to bind the source from the feed and the second one to show the image in the ad after url re-construction :
<img bind-source="Product.0.imageUrl" is="gwd-image" id="img_hidden" class="img_hidden" src="">
<img id="img_displayed" class="img_displayed" is="gwd-image" src="">
The at the bottom I would like to trigger the following JS :
function RewriteSrc() {
//Retrieves the URL generated by the feed "myimage.jpg"
var imgSrc = document.getElementById("img_hidden").src;
//cleans the previous value in case there are other element surronding the image name (removing the first part of url and possible query strings
var a_imgSrc = imgSrc.substr(imgSrc.lastIndexOf('/') + 1);
var b_imgSrc = a_imgSrc.split("?")[0];
// construct the New Url with the full Path and the query string
var n_imgSrc = "https://www.mydomain.com/dam/300x600/" + b_imgSrc + "?wid=300&fit=hfit,1";
//Set this new URL as the value of the SRC of the displayed <img>
document.getElementById("img_displayed").src = n_imgSrc;
}
The only issue is that the above is triggered to early in the code. The bidding (feed loaded) did not happened yet when this is triggered.
I have added this code in the below function :
function handleWebComponentsReady(event) {
// Start the Ad lifecycle.
setTimeout(function() {
gwdAd.initAd();
RewriteSrc();
}, 0);
}
It works in Chrome and IE 11+ ... but nothing on Firefox.
I see 2 possible reasons :
1. I am not using the right Callback function
2. What I am trying to do is not a best practice (re-consctruct an image url in the Ad). If so How to manage different Ad formats with their respective image sources as a dynamic Remarketing feed in Adwords allows only one image source column ?
I tried the below to test :
function handleAdInitialized(event) {
console.log("image source:" + document.getElementById("img_bk").src);
}
but the console is showing the following errors :
VM61 index.html:656 Uncaught TypeError: Cannot read property 'src' of null
at handleAdInitialized (VM61 index.html:656)
at m (gwddoubleclick_min.js:1)
at HTMLElement.f.ga (gwddoubleclick_min.js:17)
at HTMLElement.f.ea (gwddoubleclick_min.js:16)
at HTMLElement.f.V (gwddoubleclick_min.js:16)
at HTMLElement.f.aa (gwddoubleclick_min.js:15)
at HTMLElement.<anonymous> (gwddoubleclick_min.js:14)
at HTMLElement.f.Z (gwddoubleclick_min.js:15)
at HTMLElement.f.initAd (gwddoubleclick_min.js:10)
at VM61 index.html:644
very strange...
Then I like the solution number 2 and 3.
But I cannot find ANY docuementation on how to use transformDynamicData().
I looked at the template you mentionned and the only reference to this function is the following :
function handleDomContentLoaded(event) {
// This is a good place to show a loading or branding image while
// the ad loads.
custom.transformDynamicData();
}
Once this function added how do I actually transform my Data ? Custom script ? if so Where ?
Thanks for your help !
Xavier
I'm assuming your background image needs to be dynamic (and 4 sizes). FYI-if the background is not dynamic (but still 4 sizes) then a different static background image can be uploaded for each size in the "previous Adwords" UI. I don't know if that feature will be supported in the new Adwords Beta UI.