@@ -196,18 +196,23 @@ export class EthicalAdsAddon extends AddonBase {
196
196
if ( elementToAppend ) {
197
197
elementToAppend . append ( placement ) ;
198
198
}
199
- } else if ( window . innerWidth > 1300 ) {
200
- // https://ethical-ad-client.readthedocs.io/en/latest/#stickybox
201
- placement . setAttribute ( "data-ea-type" , "image" ) ;
202
- placement . setAttribute ( "data-ea-style" , "stickybox" ) ;
203
- this . addEaPlacementToElement ( placement ) ;
204
- // `document.body` here is not too much relevant, since we are going to
205
- // use this selector only for a floating stickybox ad
206
- const elementInsertBefore = document . body ;
207
- elementInsertBefore . insertBefore (
208
- placement ,
209
- elementInsertBefore . lastChild ,
210
- ) ;
199
+ } else {
200
+ // Default to a text ad appended to the root selector when no known placement found
201
+ placement . setAttribute ( "data-ea-type" , "text" ) ;
202
+ // TODO: Check this placement on the dashboard,
203
+ // and see how this is performing.
204
+ const docToolName = docTool . getDocumentationTool ( ) ;
205
+ const idSuffix = docToolName ? `-${ docToolName } ` : "" ;
206
+ placement . setAttribute ( "id" , `readthedocs-ea-text-footer${ idSuffix } ` ) ;
207
+
208
+ const rootSelector = docTool . getRootSelector ( ) ;
209
+ const rootElement = document . querySelector ( rootSelector ) ;
210
+
211
+ if ( rootElement ) {
212
+ rootElement . append ( placement ) ;
213
+ } else {
214
+ console . debug ( "Could not find root element to append ad" ) ;
215
+ }
211
216
}
212
217
}
213
218
@@ -239,6 +244,11 @@ export class EthicalAdsAddon extends AddonBase {
239
244
}
240
245
241
246
elementAboveTheFold ( element ) {
247
+ // Return false if element doesn't exist
248
+ if ( ! element ) {
249
+ return false ;
250
+ }
251
+
242
252
// Determine if this element would be above the fold.
243
253
// If this is off screen, instead create an ad in the footer.
244
254
// Assumes the ad would be AD_SIZE pixels high.
0 commit comments