//
// Analytics for all things articles. This includes tests for share buttons
// and potentionally other alternative layout options or more.
//

if (
  location.pathname.match("/article/") ||
  location.pathname.match("/2016-year-in-art")
) {
  $(document.body)
    .on("click", ".article-social a", function() {
      var articleId = $(this)
        .closest(".article-container")
        .data("id")
      analytics.track("Article Share", {
        article_id: articleId,
        context_type: sd.ARTICLE ? "article_fixed" : "magazine_fixed",
        service: $(this).attr("data-service"),
      })
    })
    .on("click", ".article-share-fixed > a", function() {
      var articleId = $(this)
        .closest(".article-container")
        .data("id")
      analytics.track("Article Share", {
        article_id: articleId,
        context_type: "article_sticky",
        service: $(this).attr("data-service"),
      })
    })
    .on("click", ".article-sa-primary-logo a", function() {
      analytics.track("Clicked primary partner logo", {
        destination_path: $(this)[0].href,
        impression_type: "sa_primary_logo",
        context_type: "article_fixed",
      })
    })
    .on("click", ".article-sa-secondary-logo a", function() {
      analytics.track("Clicked secondary partner logo", {
        destination_path: $(this)[0].href,
        impression_type: "sa_secondary_logo",
        context_type: "article_fixed",
      })
    })
    .on("click", ".article-sa-cta-container a", function() {
      analytics.track("Clicked partner cta link", {
        destination_path: $(this)[0].href,
        impression_type: "sa_partner_cta",
        context_type: "article_fixed",
      })
    })
    .on("click", ".article-sa-footer-blurb a", function() {
      analytics.track("Clicked partner cta link in footer blurb", {
        destination_path: $(this)[0].href,
        impression_type: "sa_partner_cta",
        context_type: "article_fixed",
      })
    })

  // Hooks
  analyticsHooks.on("view:editorial-signup", function(options) {
    analytics.track("Article impression", {
      article_id: null,
      destination_path: null,
      impression_type: "newsletter_signup",
      context_type: options.type,
    })
  })
}

// Applies to both /article/* and /articles
if (
  location.pathname.match("/article/") ||
  location.pathname.match("/articles") ||
  location.pathname.match("/venice-biennale-2015")
) {
  analyticsHooks.on("submit:editorial-signup", function(options) {
    analytics.track("Sign up for editorial email", {
      article_id: $(this)
        .closest(".article-container")
        .data("id"),
      context_type: options.type,
      user_email: options.email,
    })
  })

  analyticsHooks.on("dismiss:editorial-signup", function(options) {
    analytics.track("Dismiss editorial signup", {
      context_type: options.type,
    })
  })
}

@@ -294,32 +294,33 @@
 ial a%22, function
+ 
 () %7B%0A      var a
@@ -306,35 +306,37 @@
 tion () %7B%0A      
-var
+const
  articleId = $(t
@@ -335,33 +335,24 @@
 Id = $(this)
-%0A        
 .closest(%22.a
@@ -365,33 +365,24 @@
 -container%22)
-%0A        
 .data(%22id%22)%0A
@@ -632,32 +632,33 @@
 d %3E a%22, function
+ 
 () %7B%0A      var a
@@ -656,11 +656,13 @@
     
-var
+const
  art
@@ -673,33 +673,24 @@
 Id = $(this)
-%0A        
 .closest(%22.a
@@ -703,33 +703,24 @@
 -container%22)
-%0A        
 .data(%22id%22)%0A
@@ -941,32 +941,33 @@
 ogo a%22, function
+ 
 () %7B%0A      analy
@@ -1202,32 +1202,33 @@
 ogo a%22, function
+ 
 () %7B%0A      analy
@@ -1466,32 +1466,33 @@
 ner a%22, function
+ 
 () %7B%0A      analy
@@ -1728,16 +1728,17 @@
 function
+ 
 () %7B%0A   
@@ -1940,919 +1940,13 @@
  %7D)%0A
+
     %7D)
-%0A%0A  // Hooks%0A  analyticsHooks.on(%22view:editorial-signup%22, function(options) %7B%0A    analytics.track(%22Article impression%22, %7B%0A      article_id: null,%0A      destination_path: null,%0A      impression_type: %22newsletter_signup%22,%0A      context_type: options.type,%0A    %7D)%0A  %7D)%0A%7D%0A%0A// Applies to both /article/* and /articles%0Aif (%0A  location.pathname.match(%22/article/%22) %7C%7C%0A  location.pathname.match(%22/articles%22) %7C%7C%0A  location.pathname.match(%22/venice-biennale-2015%22)%0A) %7B%0A  analyticsHooks.on(%22submit:editorial-signup%22, function(options) %7B%0A    analytics.track(%22Sign up for editorial email%22, %7B%0A      article_id: $(this)%0A        .closest(%22.article-container%22)%0A        .data(%22id%22),%0A      context_type: options.type,%0A      user_email: options.email,%0A    %7D)%0A  %7D)%0A%0A  analyticsHooks.on(%22dismiss:editorial-signup%22, function(options) %7B%0A    analytics.track(%22Dismiss editorial signup%22, %7B%0A      context_type: options.type,%0A    %7D)%0A  %7D)
 %0A%7D%0A

remove unused hooks for editorial signup