diff --git a/network-api/networkapi/buyersguide/templates/primary_nav.html b/network-api/networkapi/buyersguide/templates/primary_nav.html index 8fd79caa232..ee7c2c0bebd 100644 --- a/network-api/networkapi/buyersguide/templates/primary_nav.html +++ b/network-api/networkapi/buyersguide/templates/primary_nav.html @@ -11,7 +11,7 @@

Help us keep the Internet healthy

Mozilla is a nonprofit organization fighting for a healthy interent.

- Donate +
diff --git a/network-api/networkapi/buyersguide/templates/product_page.html b/network-api/networkapi/buyersguide/templates/product_page.html index 8cf2064dd19..70adb6aa9ce 100644 --- a/network-api/networkapi/buyersguide/templates/product_page.html +++ b/network-api/networkapi/buyersguide/templates/product_page.html @@ -21,7 +21,7 @@

{{product.name}}

- Copy link + Copy link
{{product.blurb}}
@@ -122,7 +122,7 @@

Company shows it cares about its custome
Live Chat {% if product.live_chat %} - Yes + Yes {% else %} No {% endif %} diff --git a/network-api/networkapi/buyersguide/templates/social.html b/network-api/networkapi/buyersguide/templates/social.html index ed7f6fc77ce..6ab7716645b 100644 --- a/network-api/networkapi/buyersguide/templates/social.html +++ b/network-api/networkapi/buyersguide/templates/social.html @@ -2,18 +2,18 @@ {% if mobile %} {% else %}
- +

{this.state.totalVotes} votes

diff --git a/source/js/buyers-guide/product-analytics.js b/source/js/buyers-guide/product-analytics.js new file mode 100644 index 00000000000..8624bf51148 --- /dev/null +++ b/source/js/buyers-guide/product-analytics.js @@ -0,0 +1,120 @@ +import ReactGA from 'react-ga'; + +function getElementGAInformation(pageTitle, productName) { + return { + 'product-live-chat': { + category: `product`, + action: `customer support link tap`, + label: `support link for ${productName}` + }, + 'donate-button': { + category: `site`, + action: `donate tap`, + label: `${pageTitle} donate header` + }, + 'donate-footer-btn': { + category: `site`, + action: `donate tap`, + label: `${pageTitle} donate footer` + }, + 'nav-social-button-fb': { + category: `site`, + action: `share tap`, + label: `share site to Facebook`, + transport: `beacon` + }, + 'nav-social-button-twitter': { + category: `site`, + action: `share tap`, + label: `share site to Twitter`, + transport: `beacon` + }, + 'nav-social-button-link': { + category: `site`, + action: `copy link tap`, + label: `copy link to site ` + }, + 'nav-social-button-email': { + category: `site`, + action: `share tap`, + label: `share site to Email`, + transport: `beacon` + }, + 'nav-social-button-fb-mb': { + category: `site`, + action: `share tap`, + label: `share site to Facebook`, + transport: `beacon` + }, + 'nav-social-button-twitter-mb': { + category: `site`, + action: `share tap`, + label: `share site to Twitter`, + transport: `beacon` + }, + 'nav-social-button-link-mb': { + category: `site`, + action: `copy link tap`, + label: `copy link to site ` + }, + 'nav-social-button-email-mb': { + category: `site`, + action: `share tap`, + label: `share site to Email`, + transport: `beacon` + }, + 'product-copy-link-button': { + category: `product`, + action: `copy link tap`, + label: `copy link ${productName}` + }, + 'creep-vote-btn': { + category: `product`, + action: `opinion submitted`, + label: `opinion on ${productName}` + }, + 'product-social-button-fb': { + category: `product`, + action: `share tap`, + label: `share ${productName} to Facebook`, + transport: `beacon` + }, + 'product-social-button-twitter': { + category: `product`, + action: `share tap`, + label: `share ${productName} to Twitter`, + transport: `beacon` + }, + 'product-social-button-email': { + category: `product`, + action: `share tap`, + label: `share ${productName} to Email`, + transport: `beacon` + } + }; +} + +function setupElementGA(elementId, opts) { + let element = document.getElementById(elementId); + + if (element) { + element.onclick = () => { + ReactGA.event(opts); + }; + } +} + +const ProductGA = { + init: () => { + let productBox = document.querySelector(`.product-detail .h1-heading`); + let productName = productBox ? productBox.textContent : `unknown product`; + let pageTitle = document.querySelector(`meta[property='og:title']`).getAttribute(`content`); + let elementsWithAnalytics = getElementGAInformation(pageTitle, productName); + + Object.keys(elementsWithAnalytics).forEach( elementId => { + setupElementGA(elementId, elementsWithAnalytics[elementId]); + }); + } +}; + +export default ProductGA;