from urllib import quote

from pylons import c, g

from r2.lib.pages import Ads as BaseAds


class Ads(BaseAds):
    def __init__(self):
        BaseAds.__init__(self)
        adzerk_all_the_things = g.live_config.get("adzerk_all_the_things")
        adzerk_srs = g.live_config.get("adzerk_srs")
        in_adzerk_sr = adzerk_srs and c.site.name.lower() in adzerk_srs
        if adzerk_all_the_things or in_adzerk_sr:
            url_key = "adzerk_https_url" if c.secure else "adzerk_url"
            self.ad_url = g.config[url_key].format(
                subreddit=quote(c.site.name.lower()),
                origin=c.request_origin,
            )
            self.frame_id = "ad_main"

from urllib import quote

from pylons import c, g

from r2.lib.pages import Ads as BaseAds


class Ads(BaseAds):
    def __init__(self):
        BaseAds.__init__(self)
        adzerk_all_the_things = g.live_config.get("adzerk_all_the_things")
        adzerk_srs = g.live_config.get("adzerk_srs")
        in_adzerk_sr = adzerk_srs and c.site.name.lower() in adzerk_srs
        if adzerk_all_the_things or in_adzerk_sr:
            url_key = "adzerk_https_url" if c.secure else "adzerk_url"
            site_name = getattr(c.site, "analytics_name", c.site.name)
            self.ad_url = g.config[url_key].format(
                subreddit=quote(site_name.lower()),
                origin=c.request_origin,
            )
            self.frame_id = "ad_main"

Use analytics name for subreddits if available.
Use analytics name for subreddits if available.

This allows a catch-all for multis to be used.

  from urllib import quote
  
  from pylons import c, g
  
  from r2.lib.pages import Ads as BaseAds
  
  
  class Ads(BaseAds):
      def __init__(self):
          BaseAds.__init__(self)
          adzerk_all_the_things = g.live_config.get("adzerk_all_the_things")
          adzerk_srs = g.live_config.get("adzerk_srs")
          in_adzerk_sr = adzerk_srs and c.site.name.lower() in adzerk_srs
          if adzerk_all_the_things or in_adzerk_sr:
              url_key = "adzerk_https_url" if c.secure else "adzerk_url"
+             site_name = getattr(c.site, "analytics_name", c.site.name)
              self.ad_url = g.config[url_key].format(
-                 subreddit=quote(c.site.name.lower()),
+                 subreddit=quote(site_name.lower()),
                  origin=c.request_origin,
              )
              self.frame_id = "ad_main"
  
Use analytics name for subreddits if available.
## Code Before:
from urllib import quote

from pylons import c, g

from r2.lib.pages import Ads as BaseAds


class Ads(BaseAds):
    def __init__(self):
        BaseAds.__init__(self)
        adzerk_all_the_things = g.live_config.get("adzerk_all_the_things")
        adzerk_srs = g.live_config.get("adzerk_srs")
        in_adzerk_sr = adzerk_srs and c.site.name.lower() in adzerk_srs
        if adzerk_all_the_things or in_adzerk_sr:
            url_key = "adzerk_https_url" if c.secure else "adzerk_url"
            self.ad_url = g.config[url_key].format(
                subreddit=quote(c.site.name.lower()),
                origin=c.request_origin,
            )
            self.frame_id = "ad_main"

## Instruction:
Use analytics name for subreddits if available.
## Code After:
from urllib import quote

from pylons import c, g

from r2.lib.pages import Ads as BaseAds


class Ads(BaseAds):
    def __init__(self):
        BaseAds.__init__(self)
        adzerk_all_the_things = g.live_config.get("adzerk_all_the_things")
        adzerk_srs = g.live_config.get("adzerk_srs")
        in_adzerk_sr = adzerk_srs and c.site.name.lower() in adzerk_srs
        if adzerk_all_the_things or in_adzerk_sr:
            url_key = "adzerk_https_url" if c.secure else "adzerk_url"
            site_name = getattr(c.site, "analytics_name", c.site.name)
            self.ad_url = g.config[url_key].format(
                subreddit=quote(site_name.lower()),
                origin=c.request_origin,
            )
            self.frame_id = "ad_main"
