ubyssey.ca icon indicating copy to clipboard operation
ubyssey.ca copied to clipboard

Isolate and document ad behaviour into a single Django app

Open keeganland opened this issue 3 years ago • 1 comments

Templates get divided up according to Django app according to their purpose. However, many of our existing template designs serve many purposes at once. This occurs because we often need to find places for certain behaviours when the templates which facilitate those behaviours don't cleanly correspond to a View. The most common reason for this is ad related behaviour

Here's some specimen code from ubyssey/templates/article/default.html:

  {% include 'objects/advertisement.html' with size='leaderboard' name='Leaderboard' id=1 article=article.id %}
  {% include 'objects/advertisement.html' with size='mobile-leaderboard' name='Mobile_Leaderboard' id=2 article=article.id %}

Here's more specimen code from ubyssey/templates/section.html:

  {% include 'objects/advertisement.html' with size='leaderboard' name='Leaderboard' id=1 %}
  {% include 'objects/advertisement.html' with size='mobile-leaderboard' name='Mobile_Leaderboard' id=5 %}

Most of these parameter variables take magic numbers, and the reason for the difference in each instance is never explained. Why id=1, vs id=5? It seems so that we can support the id of the following div element

    <div class="adslot" id="div-gpt-ad-1443288719995-{{ name }}-{{ id }}{% if article %}-{{ article }}{% endif %}" data-size="{{ size }}" data-dfp="{{ name }}"></div>

but it's left completely obscure why this element is important etc.

While it's undocumented, it's clear that this element has something to do with our Google Ad Manager account (which something distinct from our Google AdSense account, we should note!). Given this, we should probably have some sort of administrative UI that corresponds to these values (perhaps locked behind a high-level user permission) so it can be intelligible to both users and developers when this element will be inserted onto a page that will be rendered for readers, and why it will be so inserted. This calls for a distinct Django app that takes the load off both the user and the developer's need to think about Google Ad Manager when trying to be concerned about the Section or Article models and their corresponding Views.

As it is, this behaviour is obscure and it is uncertain when it might break. Particularly worrisome is it being unclear which element attributes need to be targeted by CSS/jQuery/etc. in order to actually facilitate our sale of ad inventory etc.

Meanwhile, here are some clearly related but undocumented and obscure parts of the code demanding investigation. These parts will likely be moved to live in the proposed Django app so related code all lives in one place:

  • Google tag behaviour in the script ubyssey/static_src/src/js/dfp.js
  • Script element in ubyssey/templates/base.html
  <script>
    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:') +
    '//securepubads.g.doubleclick.net/tag/js/gpt.js';
    var node = document.getElementsByTagName('script')[0];
    node.parentNode.insertBefore(gads, node);
    })();
  </script>  

keeganland avatar Jun 01 '21 07:06 keeganland

@brittkhat This has some relationship with your ongoing task of template documentation, particularly in ubyssey/templates/base.html.

keeganland avatar Jun 01 '21 07:06 keeganland