[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: Подмена заголовков относительно UTM метки
Pagy
Добрый день, сообщество! Мои знания в программировании чуть больше чем 0, пытаюсь доделать одну идейку методом тыка, но почему-то не получается))) Прошу Вашей помощи.
Что я хочу: мультилейдинг, т.е. при переходе по ссылке по определенной UTM метке, часть заголовков и информации подменяется в соответствии с UTM меткой.
Что смог сделать: реализована данная задача с помощью плагина, но в самом плагине анализ идет по параметру "utm_source", а не по "utm_multi" или же любому другому, и почемуто не спабатывает подмена, если в ссылке присутствует параметр "tm_campaign=cid|{campaign_id}|{source_type}"
Что имеем: сайт на Wordpress
Ссылки на одну и туже страницу с UTM метками такого типа:
https://site.ru/?utm_source=yandex&utm_medium=cpc&utm_campaign=cid|{campaign_id}|{source_type}&utm_cont ent=gid|{gbid}|aid|{ad_id}|{phrase_id}_{retargeting_id}&utm_term={keyword}&pm_source={source} &pm_block={position_type}&pm_position={position}&utm_multi=iskvsud
Вот сам плагин: https://cloud.mail.ru/public/7xAf/YAbXjBRd1
Интерфейс программы:
user posted image
Как работает, обычный заголовок, без подмены.
user posted image
Использована переменная в ссылке utm_source=advokatuslugi
user posted image
Нашел в плагине два главных javascripta, которые, как я понимаю и отвечают за обработку UTM меток
utm-switcher\public\assets\js\public.js
(function ($) {
'use strict';
$(function () {
/* ========================================================================
* DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish
*
* Only fires on body classes that match. If a body class contains a dash,
* replace the dash with an underscore when adding it to the object below.
*
* .noConflict()
* The routing is enclosed within an anonymous function so that you can
* always reference jQuery with $, even when in .noConflict() mode.
* ========================================================================
*/
var Utm_Switcher, Utm_UTIL;
Utm_Switcher = {
common: {
init: function () {
var parsedQuery = Utm_UTIL.queryString();

//CF7 Hidden input value replacement
if (parsedQuery.utm_source || parsedQuery.utm_medium || parsedQuery.utm_campaign) {
if (parsedQuery.utm_source) {
document.cookie = 'utmfieldsource=' + parsedQuery.utm_source;
}
if (parsedQuery.utm_medium) {
document.cookie = 'utmfieldmedium=' + parsedQuery.utm_medium;
}
if (parsedQuery.utm_campaign) {
document.cookie = 'utmfieldcampaign=' + parsedQuery.utm_campaign;
}

Utm_UTIL.populateFormValues(parsedQuery);
} else if (document.cookie.indexOf("utmfieldsource") >= 0 || document.cookie.indexOf("utmfieldmedium") >= 0 || document.cookie.indexOf("utmfieldcampaign") >= 0) {
Utm_UTIL.populateFormValues(parsedQuery);
}


if (!Utm_UTIL.isArray(utm_switchers)) {
return false;
}

//Value replacement based on utm_source
if (('utm_source' in parsedQuery) || ( document.cookie.indexOf("utmfieldsource") >= 0 ) ) {

var i,j;
for (i = 0; i < utm_switchers.length; ++i) {
var switcher = utm_switchers[i], markup = $(switcher.match_element).html();
//Name this loop
switchersSubLoop:
for (j = 0; j < switcher.switchers.length; ++j) {

if ( (switcher.switchers[j].campaign_source !== parsedQuery.utm_source) && (switcher.switchers[j].campaign_source !== Utm_UTIL.getCookieValue('utmfieldsource')) ) {
continue switchersSubLoop;
}
if (switcher.switcher_type === 'phone') {
markup = '<a href="tel:' + switcher.switchers[j].replace_value + '" class="phone-number">' + switcher.switchers[j].replace_value + '</a>';
$(switcher.match_element).replaceWith(markup);
} else {
markup = switcher.switchers[j].replace_value;
$(switcher.match_element).html(markup);
}
}
}
}
}
}
};
Utm_UTIL = {
fire: function (func, funcname, args) {
var namespace;
namespace = Utm_Switcher;
funcname = funcname === void 0 ? 'init' : funcname;
if (func !== '' && namespace[func] && typeof namespace[func][funcname] === 'function') {
namespace[func][funcname](args);
}
},
loadEvents: function () {
Utm_UTIL.fire('common');
$.each(document.body.className.replace(/-/g, '_').split(/\s+/), function (i, classnm) {
Utm_UTIL.fire(classnm);
});
},
isArray: function (obj) {
return (typeof obj !== 'undefined' &&
obj && obj.constructor === Array);
},
queryString: function(){
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [query_string[pair[0]], pair[1]];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
},
getCookieValue: function (a, b) {
b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
},
populateFormValues: function (parsedQuery) {

if ((document.cookie.indexOf("utmfieldsource") >= 0 || parsedQuery.utm_source) && document.getElementsByClassName("utm-field-source")[0]) {
Utm_UTIL.applyFormValues(document.getElementsByClassName("utm-field-source"), Utm_UTIL.getCookieValue('utmfieldsource'));
}
if ((document.cookie.indexOf("utmfieldmedium") >= 0 || parsedQuery.utm_medium) && document.getElementsByClassName("utm-field-medium")[0]) {
Utm_UTIL.applyFormValues(document.getElementsByClassName("utm-field-medium"), Utm_UTIL.getCookieValue('utmfieldmedium'));

}
if ((document.cookie.indexOf("utmfieldcampaign") >= 0 || parsedQuery.utm_campaign) && document.getElementsByClassName("utm-field-campaign")[0]) {
Utm_UTIL.applyFormValues(document.getElementsByClassName("utm-field-campaign"), Utm_UTIL.getCookieValue('utmfieldcampaign'));
}
},
applyFormValues : function(elements, value){
elements = elements || {};
for (var i = 0; i < elements.length; i++) {
elements[i].value = value;
}
}
};
$(document).ready(Utm_UTIL.loadEvents);
});
})(jQuery);


и второй utm-switcher\public\dist\scripts\public.js
!function(e){"use strict";e(function(){var t,u;t={common:{init:function(){var t=u.queryString();if(t.utm_source||t.utm_medium||t.utm_campaign?(t.utm_source&&(document.cook ie="utmfieldsource="+t.utm_source),t.utm_medium&&(document.cookie="utmfieldmed ium="+t.utm_medium),t.utm_campaign&&(document.cookie="utmfieldcampaign="+t.utm _campaign),u.populateFormValues(t)):(document.cookie.indexOf("utmfieldsource")>=0||document.cookie.indexOf("utmfieldmedium")>=0||document.cookie.indexOf("utmfieldcampaign")>=0)&&u.populateFormValues(t),!u.isArray(utm_switchers))return!1;if("utm_source"in t||document.cookie.indexOf("utmfieldsource")>=0){var m,i;for(m=0;m<utm_switchers.length;++m){var o=utm_switchers[m],n=e(o.match_element).html();for(i=0;i<o.switchers.length;++i)o.switchers[i].campaign_source!==t.utm_source&&o.switchers[i].campaign_source!==u.getCookieValue("utmfieldsource")||("phone"===o.switcher_type?(n='<a href="tel:'+o.switchers[i].replace_value+'" class="phone-number">'+o.switchers[i].replace_value+"</a>",e(o.match_element).replaceWith(n)):(n=o.switchers[i].replace_value,e(o.match_element).html(n)))}}}}},u={fire:function(e,u,m){var i;i=t,u=void 0===u?"init":u,""!==e&&i[e]&&"function"==typeof i[e][u]&&i[e][u](m)},loadEvents:function(){u.fire("common"),e.each(document.body.className.replace(/-/g,"_").split(/\s+/),function(e,t){u.fire(t)})},isArray:function(e){return"undefined"!=typeof e&&e&&e.constructor===Array},queryString:function(){for(var e={},t=window.location.search.substring(1),u=t.split("&"),m=0;m<u.length;m++){var i=u[m].split("=");if("undefined"==typeof e[i[0]])e[i[0]]=i[1];else if("string"==typeof e[i[0]]){var o=[e[i[0]],i[1]];e[i[0]]=o}else e[i[0]].push(i[1])}return e},getCookieValue:function(e,t){return t=document.cookie.match("(^|;)\\s*"+e+"\\s*=\\s*([^;]+)"),t?t.pop():""},populateFormValues:function(e){(document.cookie.indexOf("utmfieldsource")>=0||e.utm_source)&&document.getElementsByClassName("utm-field-source")[0]&&u.applyFormValues(document.getElementsByClassName("utm-field-source"),u.getCooki eValue("utmfieldsource")),(document.cookie.indexOf("utmfieldmedium")>=0||e.utm_medium)&&document.getElementsByClassName("utm-field-medium")[0]&&u.applyFormValues(document.getElementsByClassName("utm-field-medium"),u.getCooki eValue("utmfieldmedium")),(document.cookie.indexOf("utmfieldcampaign")>=0||e.utm_campaign)&&document.getElementsByClassName("utm-field-campaign")[0]&&u.applyFormValues(document.getElementsByClassName("utm-field-campaign"),u.getCoo kieValue("utmfieldcampaign"))},applyFormValues:function(e,t){e=e||{};for(var u=0;u<e.length;u++)e[u].value=t}},e(document).ready(u.loadEvents)})}(jQuery);
//# sourceMappingURL=public.js.map


Помогите пожалуйста. Вроде интересная задачка. Надо сделать так, чтобы параметр искался не в UTM_SOURCE а в UTM_MULTI или же любом другом параметре. Если возможно, сделать так, чтобы срабатывал скрипт со всеми переменными. Если есть необходимость в тестировании наработок, я тут, скидывайте сразу залью на сайт и проверю.

З.Ы. В интернетах есть множество ссылок на такой вот подход к созданию мультилейдинга (подмены содержимого сайта относительно поискового запроса), но нет нормальной реализации, тем более в виде плагина.
Заранее спасибо
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.