/*! * Piwik - Web Analytics * * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ (function ($) { $(document).ready(function () { var piwikHost = window.location.host, piwikPath = location.pathname.substring(0, location.pathname.lastIndexOf('/')); // // utility methods // // returns JavaScript code for tracking custom variables based on an array of // custom variable name-value pairs (so an array of 2-element arrays) and // a scope (either 'visit' or 'page') var getCustomVariableJS = function (customVariables, scope) { var result = ''; for (var i = 0; i != 5; ++i) { if (customVariables[i]) { var key = customVariables[i][0], value = customVariables[i][1]; result += ' _paq.push(["setCustomVariable", ' + (i + 1) + ', ' + JSON.stringify(key) + ', ' + JSON.stringify(value) + ', ' + JSON.stringify(scope) + ']);\n'; } } return result; }; // gets the list of custom variables entered by the user in a custom variable // section var getCustomVariables = function (sectionId) { var customVariableNames = $('.custom-variable-name', '#' + sectionId), customVariableValues = $('.custom-variable-value', '#' + sectionId); var result = []; if ($('.section-toggler-link', '#' + sectionId).is(':checked')) { for (var i = 0; i != customVariableNames.length; ++i) { var name = $(customVariableNames[i]).val(); result[i] = null; if (name) { result[i] = [name, $(customVariableValues[i]).val()]; } } } return result; }; // quickly gets the host + port from a url var getHostNameFromUrl = function (url) { var element = $('')[0]; element.href = url; return element.hostname; }; // get preloaded server-side data necessary for code generation var dataElement = $('#js-tracking-generator-data'), currencySymbols = JSON.parse(dataElement.attr('data-currencies')), siteUrls = {}, siteCurrencies = {}, allGoals = {}, noneText = $('#image-tracker-goal').find('>option').text(); // queries Piwik for needed site info for one site var getSiteData = function (idSite, sectionSelect, callback) { // if data is already loaded, don't do an AJAX request if (siteUrls[idSite] && siteCurrencies[idSite] && typeof allGoals[idSite] !== 'undefined') { callback(); return; } // disable section $(sectionSelect).find('input,select,textarea').attr('disabled', 'disabled'); var ajaxRequest = new ajaxHelper(); ajaxRequest.setBulkRequests( // get site info (for currency) { module: 'API', method: 'SitesManager.getSiteFromId', idSite: idSite }, // get site urls { module: 'API', method: 'SitesManager.getSiteUrlsFromId', idSite: idSite }, // get site goals { module: 'API', method: 'Goals.getGoals', idSite: idSite } ); ajaxRequest.setCallback(function (data) { var currency = data[0][0].currency || ''; siteCurrencies[idSite] = currencySymbols[currency.toUpperCase()]; siteUrls[idSite] = data[1] || []; allGoals[idSite] = data[2] || []; // re-enable controls $(sectionSelect).find('input,select,textarea').removeAttr('disabled'); callback(); }); ajaxRequest.setFormat('json'); ajaxRequest.send(false); }; // resets the select options of a goal select using a site ID var resetGoalSelectItems = function (idsite, id) { var selectElement = $('#' + id).html(''); selectElement.append($('').text(noneText)); var goals = allGoals[idsite] || []; for (var key in goals) { var goal = goals[key]; selectElement.append($('