From 884474d1332544a01237016493f0a896f366ac9a Mon Sep 17 00:00:00 2001 From: haszari Date: Tue, 9 Apr 2019 10:29:51 +1200 Subject: [PATCH] add tracks event for clicks on `marketplace-suggestion-manage-link` --- assets/js/admin/marketplace-suggestions.js | 8 ++++++++ assets/js/admin/marketplace-suggestions.min.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/assets/js/admin/marketplace-suggestions.js b/assets/js/admin/marketplace-suggestions.js index fdb78cbd961..89f4a19dbaf 100644 --- a/assets/js/admin/marketplace-suggestions.js +++ b/assets/js/admin/marketplace-suggestions.js @@ -312,6 +312,12 @@ } } + function addManageSuggestionsTracksHandler() { + $( 'a.marketplace-suggestion-manage-link' ).on( 'click', function() { + window.wcTracks.recordEvent( 'marketplace_suggestions_manage_clicked' ); + } ); + } + // Render suggestion data in appropriate places in UI. function displaySuggestions( marketplaceSuggestionsApiData ) { var usedSuggestionsContexts = []; @@ -377,6 +383,8 @@ if ( marketplace_suggestions.suggestions_data ) { displaySuggestions( marketplace_suggestions.suggestions_data ); } + + addManageSuggestionsTracksHandler(); }); })( jQuery, marketplace_suggestions, ajaxurl ); diff --git a/assets/js/admin/marketplace-suggestions.min.js b/assets/js/admin/marketplace-suggestions.min.js index dd1ac665abf..80f161b1500 100644 --- a/assets/js/admin/marketplace-suggestions.min.js +++ b/assets/js/admin/marketplace-suggestions.min.js @@ -1 +1 @@ -!function(p,v,d){p(function(){function f(e,s,n,a,o){var t=document.createElement("a");return t.classList.add("suggestion-dismiss"),t.setAttribute("title",v.i18n_marketplace_suggestions_dismiss_tooltip),t.setAttribute("href","#"),t.onclick=function(t){t.preventDefault(),function c(t,e,s,n,a){if(p("[data-suggestion-slug="+a+"]").fadeOut(function(){p(this).remove(),g()}),jQuery.post(d,{action:"woocommerce_add_dismissed_marketplace_suggestion",_wpnonce:v.dismiss_suggestion_nonce,slug:a}),_.contains(["products-list-inline"],t)){var o="woocommerce_snooze_suggestions__"+t;Cookies.set(o,"true",{expires:2});var i="woocommerce_dismissed_suggestions__"+t,r=parseInt(Cookies.get(i),10)||0;Cookies.set(i,r+1,{expires:31})}window.wcTracks.recordEvent("marketplace_suggestion_dismissed",{suggestion_slug:a,context:t,product:e||"",promoted:s||"",target:n||""})}(e,s,n,a,o)},t}function h(t,e,s,n,a,o,i){var r=document.createElement("a"),c=function u(e,t){var s={utm_source:"unknown",utm_campaign:"marketplacesuggestions",utm_medium:"product"},n=_.findKey({productstable:["products-list-inline"],productsempty:["products-list-empty-header","products-list-empty-footer","products-list-empty-body"],ordersempty:["orders-list-empty-header","orders-list-empty-footer","orders-list-empty-body"],editproduct:["product-edit-meta-tab-header","product-edit-meta-tab-footer","product-edit-meta-tab-body"]},function(t){return _.contains(t,e)});return n&&(s.utm_source=n),t+"?"+jQuery.param(s)}(t,a);if(r.setAttribute("href",c),r.setAttribute("target","blank"),r.textContent=o,r.onclick=function(){window.wcTracks.recordEvent("marketplace_suggestion_clicked",{suggestion_slug:n,context:t,product:e||"",promoted:s||"",target:a||""})},i)r.classList.add("button");else{r.classList.add("linkout");var d=document.createElement("span");d.classList.add("dashicons","dashicons-external"),r.appendChild(d)}return r}function l(t,e,s,n,a,o,i,r,c,d,u){var l=document.createElement("div");l.classList.add("marketplace-suggestion-container"),l.dataset.suggestionSlug=n;var g=function p(t){if(!t)return null;var e=document.createElement("img");return e.src=t,e.classList.add("marketplace-suggestion-icon"),e}(a);return g&&l.appendChild(g),l.appendChild(function m(t,e,s){var n=document.createElement("div");if(n.classList.add("marketplace-suggestion-container-content"),e){var a=document.createElement("h4");a.textContent=e,n.appendChild(a)}if(s){var o=document.createElement("p");o.textContent=s,n.appendChild(o)}if(-1!==["product-edit-empty-footer-browse-all","product-edit-meta-tab-footer-browse-all"].indexOf(t)){n.classList.add("has-manage-link");var i=document.createElement("a");i.classList.add("marketplace-suggestion-manage-link","linkout"),i.setAttribute("href","/wp-admin/admin.php?page=wc-settings&tab=account#marketplace_suggestions-description"),i.textContent=v.i18n_marketplace_suggestions_manage_suggestions,n.appendChild(i)}return n}(n,o,i)),l.appendChild(function k(t,e,s,n,a,o,i,r){var c=document.createElement("div");if(o||(o=v.i18n_marketplace_suggestions_default_cta),c.classList.add("marketplace-suggestion-container-cta"),a&&o){var d=h(t,e,s,n,a,o,i);c.appendChild(d)}return r&&c.appendChild(f(t,e,s,a,n)),c}(t,e,s,n,r,c,d,u)),l}function g(){if(p('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]').children().length<=0){', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"]',', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]',p('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"], .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"], .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]').fadeOut({complete:function(){p(".marketplace-suggestions-metabox-nosuggestions-placeholder").fadeIn()}})}}void 0!==v&&(window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){},v.suggestions_data&&function t(d){var u=[];p(".marketplace-suggestions-container").each(function(){var t=this.dataset.marketplaceSuggestionsContext,e=function c(t,e){var s=_.filter(t,function(t){return _.isArray(t.context)?_.contains(t.context,e):e===t.context});return s=_.filter(s,function(t){return!_.contains(v.dismissed_suggestions,t.slug)}),s=_.filter(s,function(t){return!_.contains(v.active_plugins,t.product)}),s=_.filter(s,function(t){return!t["show-if-active"]||0<_.intersection(v.active_plugins,t["show-if-active"]).length})}(d,t),s=_.sample(e,5);for(var n in s){var a=s[n]["link-text"],o=!0;s[n]["link-text"]&&(a=s[n]["link-text"],o=!1);var i=!0;!1===s[n]["allow-dismiss"]&&(i=!1);var r=l(t,s[n].product,s[n].promoted,s[n].slug,s[n].icon,s[n].title,s[n].copy,s[n].url,a,o,i);p(this).append(r),p(this).addClass("showing-suggestion"),u.push(t),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:s[n].slug,context:t,product:s[n].product||"",promoted:s[n].promoted||"",target:s[n].url||""})}}),function s(t){var e=0<_.intersection(t,["products-list-empty-body","orders-list-empty-body"]).length;e&&(p("#screen-meta-links").hide(),p("#wpfooter").hide()),e||(p('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]').hide(),p('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]').hide(),p('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-header"]').hide(),p('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-footer"]').hide())}(u),g()}(v.suggestions_data))})}(jQuery,marketplace_suggestions,ajaxurl); \ No newline at end of file +!function(p,v,d){p(function(){function f(e,s,n,a,o){var t=document.createElement("a");return t.classList.add("suggestion-dismiss"),t.setAttribute("title",v.i18n_marketplace_suggestions_dismiss_tooltip),t.setAttribute("href","#"),t.onclick=function(t){t.preventDefault(),function c(t,e,s,n,a){if(p("[data-suggestion-slug="+a+"]").fadeOut(function(){p(this).remove(),g()}),jQuery.post(d,{action:"woocommerce_add_dismissed_marketplace_suggestion",_wpnonce:v.dismiss_suggestion_nonce,slug:a}),_.contains(["products-list-inline"],t)){var o="woocommerce_snooze_suggestions__"+t;Cookies.set(o,"true",{expires:2});var i="woocommerce_dismissed_suggestions__"+t,r=parseInt(Cookies.get(i),10)||0;Cookies.set(i,r+1,{expires:31})}window.wcTracks.recordEvent("marketplace_suggestion_dismissed",{suggestion_slug:a,context:t,product:e||"",promoted:s||"",target:n||""})}(e,s,n,a,o)},t}function h(t,e,s,n,a,o,i){var r=document.createElement("a"),c=function u(e,t){var s={utm_source:"unknown",utm_campaign:"marketplacesuggestions",utm_medium:"product"},n=_.findKey({productstable:["products-list-inline"],productsempty:["products-list-empty-header","products-list-empty-footer","products-list-empty-body"],ordersempty:["orders-list-empty-header","orders-list-empty-footer","orders-list-empty-body"],editproduct:["product-edit-meta-tab-header","product-edit-meta-tab-footer","product-edit-meta-tab-body"]},function(t){return _.contains(t,e)});return n&&(s.utm_source=n),t+"?"+jQuery.param(s)}(t,a);if(r.setAttribute("href",c),r.setAttribute("target","blank"),r.textContent=o,r.onclick=function(){window.wcTracks.recordEvent("marketplace_suggestion_clicked",{suggestion_slug:n,context:t,product:e||"",promoted:s||"",target:a||""})},i)r.classList.add("button");else{r.classList.add("linkout");var d=document.createElement("span");d.classList.add("dashicons","dashicons-external"),r.appendChild(d)}return r}function l(t,e,s,n,a,o,i,r,c,d,u){var l=document.createElement("div");l.classList.add("marketplace-suggestion-container"),l.dataset.suggestionSlug=n;var g=function p(t){if(!t)return null;var e=document.createElement("img");return e.src=t,e.classList.add("marketplace-suggestion-icon"),e}(a);return g&&l.appendChild(g),l.appendChild(function m(t,e,s){var n=document.createElement("div");if(n.classList.add("marketplace-suggestion-container-content"),e){var a=document.createElement("h4");a.textContent=e,n.appendChild(a)}if(s){var o=document.createElement("p");o.textContent=s,n.appendChild(o)}if(-1!==["product-edit-empty-footer-browse-all","product-edit-meta-tab-footer-browse-all"].indexOf(t)){n.classList.add("has-manage-link");var i=document.createElement("a");i.classList.add("marketplace-suggestion-manage-link","linkout"),i.setAttribute("href","/wp-admin/admin.php?page=wc-settings&tab=account#marketplace_suggestions-description"),i.textContent=v.i18n_marketplace_suggestions_manage_suggestions,n.appendChild(i)}return n}(n,o,i)),l.appendChild(function k(t,e,s,n,a,o,i,r){var c=document.createElement("div");if(o||(o=v.i18n_marketplace_suggestions_default_cta),c.classList.add("marketplace-suggestion-container-cta"),a&&o){var d=h(t,e,s,n,a,o,i);c.appendChild(d)}return r&&c.appendChild(f(t,e,s,a,n)),c}(t,e,s,n,r,c,d,u)),l}function g(){if(p('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"]').children().length<=0){', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"]',', .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]',p('.marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-body"], .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-header"], .marketplace-suggestions-container[data-marketplace-suggestions-context="product-edit-meta-tab-footer"]').fadeOut({complete:function(){p(".marketplace-suggestions-metabox-nosuggestions-placeholder").fadeIn()}})}}void 0!==v&&(window.wcTracks=window.wcTracks||{},window.wcTracks.recordEvent=window.wcTracks.recordEvent||function(){},v.suggestions_data&&function t(d){var u=[];p(".marketplace-suggestions-container").each(function(){var t=this.dataset.marketplaceSuggestionsContext,e=function c(t,e){var s=_.filter(t,function(t){return _.isArray(t.context)?_.contains(t.context,e):e===t.context});return s=_.filter(s,function(t){return!_.contains(v.dismissed_suggestions,t.slug)}),s=_.filter(s,function(t){return!_.contains(v.active_plugins,t.product)}),s=_.filter(s,function(t){return!t["show-if-active"]||0<_.intersection(v.active_plugins,t["show-if-active"]).length})}(d,t),s=_.sample(e,5);for(var n in s){var a=s[n]["link-text"],o=!0;s[n]["link-text"]&&(a=s[n]["link-text"],o=!1);var i=!0;!1===s[n]["allow-dismiss"]&&(i=!1);var r=l(t,s[n].product,s[n].promoted,s[n].slug,s[n].icon,s[n].title,s[n].copy,s[n].url,a,o,i);p(this).append(r),p(this).addClass("showing-suggestion"),u.push(t),window.wcTracks.recordEvent("marketplace_suggestion_displayed",{suggestion_slug:s[n].slug,context:t,product:s[n].product||"",promoted:s[n].promoted||"",target:s[n].url||""})}}),function s(t){var e=0<_.intersection(t,["products-list-empty-body","orders-list-empty-body"]).length;e&&(p("#screen-meta-links").hide(),p("#wpfooter").hide()),e||(p('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-header"]').hide(),p('.marketplace-suggestions-container[data-marketplace-suggestions-context="products-list-empty-footer"]').hide(),p('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-header"]').hide(),p('.marketplace-suggestions-container[data-marketplace-suggestions-context="orders-list-empty-footer"]').hide())}(u),g()}(v.suggestions_data),function e(){p("a.marketplace-suggestion-manage-link").on("click",function(){window.wcTracks.recordEvent("marketplace_suggestions_manage_clicked")})}())})}(jQuery,marketplace_suggestions,ajaxurl); \ No newline at end of file