Skip to content

Commit

Permalink
Merge pull request #109 from glogiotatidis/country-to-ping
Browse files Browse the repository at this point in the history
[fix bug 1157141] Add user country info to the Snippets Stats Ping
  • Loading branch information
glogiotatidis committed Apr 23, 2015
2 parents 0a0efa4 + bb4a779 commit 53b2cd9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions snippets/base/templates/base/includes/snippet_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
(function(a,b,c){typeof c["module"]!="undefined"&&c.module.exports?c.module.exports=b():typeof c["define"]!="undefined"&&c["define"]=="function"&&c.define.amd?define(a,b):c[a]=b()})("$script",function(){function p(a,b){for(var c=0,d=a.length;c<d;++c)if(!b(a[c]))return j;return 1}function q(a,b){p(a,function(a){return!b(a)})}function r(a,b,i){function o(a){return a.call?a():d[a]}function t(){if(!--n){d[m]=1,l&&l();for(var a in f)p(a.split("|"),o)&&!q(f[a],o)&&(f[a]=[])}}a=a[k]?a:[a];var j=b&&b.call,l=j?b:i,m=j?a.join(""):b,n=a.length;return setTimeout(function(){q(a,function(a){if(h[a])return m&&(e[m]=1),h[a]==2&&t();h[a]=1,m&&(e[m]=1),s(!c.test(a)&&g?g+a+".js":a,t)})},0),r}function s(c,d){var e=a.createElement("script"),f=j;e.onload=e.onerror=e[o]=function(){if(e[m]&&!/^c|loade/.test(e[m])||f)return;e.onload=e[o]=null,f=1,h[c]=2,d()},e.async=1,e.src=c,b.insertBefore(e,b.firstChild)}var a=document,b=a.getElementsByTagName("head")[0],c=/^https?:\/\//,d={},e={},f={},g,h={},i="string",j=!1,k="push",l="DOMContentLoaded",m="readyState",n="addEventListener",o="onreadystatechange";return!a[m]&&a[n]&&(a[n](l,function t(){a.removeEventListener(l,t,j),a[m]="complete"},j),a[m]="loading"),r.get=s,r.order=function(a,b,c){(function d(e){e=a.shift(),a.length?r(e,d):r(e,b,c)})()},r.path=function(a){g=a},r.ready=function(a,b,c){a=a[k]?a:[a];var e=[];return!q(a,function(a){d[a]||e[k](a)})&&p(a,function(a){return d[a]})?b():!function(a){f[a]=f[a]||[],f[a][k](b),c&&c(e)}(a.join("|")),r},r},this);

var SNIPPET_METRICS_SAMPLE_RATE = 0.1;
var SNIPPET_METRICS_URL = 'https://snippets-stats.mozilla.org/foo.html';

(function(showDefaultSnippets) {
'use strict';
Expand Down Expand Up @@ -110,6 +111,7 @@

var userCountry = getUserCountry();
if (userCountry) {
document.getElementById('snippet_set').dataset.userCountry = userCountry;
snippets = snippets.filter(
function(snippet) {
var countries = snippet.parentNode.dataset.countries;
Expand All @@ -121,6 +123,8 @@
);
}
else {
document.getElementById('snippet_set').dataset.userCountry = '';

// If we don't have the user's country, remove all geolocated snippets.
// Bug 1140476
snippets = snippets.filter(
Expand Down Expand Up @@ -380,11 +384,11 @@
return;
}

var STATS_URL = 'https://snippets-stats.mozilla.org/foo.html';
var snippet_set = document.getElementById('snippet_set');
var locale = snippet_set.getAttribute('data-locale');
var userCountry = snippet_set.getAttribute('data-user-country');
var snippet_id = snippet_set.getAttribute('data-snippet-id');
var url = STATS_URL + '?snippet_name=' + snippet_id + '&locale=' + locale + '&metric=' + metric;
var url = SNIPPET_METRICS_URL + '?snippet_name=' + snippet_id + '&locale=' + locale + '&country=' + userCountry + '&metric=' + metric;
var r = new XMLHttpRequest();
r.open('GET', url);
if (callback) {
Expand Down

0 comments on commit 53b2cd9

Please sign in to comment.