From 6ed8f2827481f6192794ba07ee82a8d6b8cd723a Mon Sep 17 00:00:00 2001 From: fefa4ka Date: Thu, 31 Mar 2016 01:33:36 +0300 Subject: [PATCH] Google goals and region detection --- .../form_template/default.html | 2 +- zsite/static/js/snippets.js | 63 +++++++++++++++++++ .../templates/form_template/consultation.html | 5 +- .../templates/form_template/order_modal.html | 5 +- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/djangocms_forms/templates/djangocms_forms/form_template/default.html b/djangocms_forms/templates/djangocms_forms/form_template/default.html index f3b40b7..007e95c 100644 --- a/djangocms_forms/templates/djangocms_forms/form_template/default.html +++ b/djangocms_forms/templates/djangocms_forms/form_template/default.html @@ -49,7 +49,7 @@ var form = { {% endif %}
-
+ {% for field in form.visible_fields %}
diff --git a/zsite/static/js/snippets.js b/zsite/static/js/snippets.js index 4ee1fd2..003b355 100644 --- a/zsite/static/js/snippets.js +++ b/zsite/static/js/snippets.js @@ -28,9 +28,72 @@ setCookie = function(key, value) { document.cookie = key + '=' + value + ';expires=' + expires.toUTCString() + ';path=/'; }; +getCookie = function(name) { + var matches = document.cookie.match(new RegExp( + "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" + )); + + return matches ? decodeURIComponent(matches[1]) : undefined; +} + +detectRegion = function() { + function renderRegionData(current_region) { + var regions = { + 'Moscow': { + 'city': 'В Москве', + 'phone': '+7 495 775-16-37' + }, + 'St.-Petersburg': { + 'city': 'В Санкт Петербурге', + 'phone': '+7 800 700-16-37' + }, + 'Rostov': { + 'city': 'В Ростове-на-Дону', + 'phone': '+7 863 209-85-65' + }, + 'Krasnodarskiy Kray': { + 'city': 'В Ростове-на-Дону', + 'phone': '+7 863 209-85-65' + }, + 'Volgogradskaya Oblast': { + 'city': 'В Ростове-на-Дону', + 'phone': '+7 863 209-85-65' + }, + 'Voronezhskaya Oblast': { + 'city': 'В Ростове-на-Дону', + 'phone': '+7 863 209-85-65' + } + }; + + console.log(current_region); + + if(typeof current_region !== "undefined") { + + $('.city').text(regions[current_region]['city']); + $('.header-contacts .consultation h3').text(regions[current_region]['phone']); + } + + } + + + if(typeof getCookie('region') === undefined || getCookie('region') == "") { + var request = $.get('http://ip-api.com/json') + + request.done(function(data) { + setCookie('region', data.regionName); + + renderRegionData(data.regionName); + }); + } else { + renderRegionData(getCookie('region')); + } + +}; + $(function() { $( "[href^=mailto]" ).click(function() { yaCounter950321.reachGoal('EmailClick'); + ga('send', 'event', 'Communication', 'email'); }); $( "[href^='#service-form-submit']" ).click(function(e) { diff --git a/zsite/templates/form_template/consultation.html b/zsite/templates/form_template/consultation.html index 0580b34..119d5b4 100644 --- a/zsite/templates/form_template/consultation.html +++ b/zsite/templates/form_template/consultation.html @@ -18,7 +18,7 @@
{% endif %}
- +
@@ -97,7 +97,7 @@
- +
@@ -112,6 +112,7 @@ angular.element($('.consultation-form')[0]).scope().open({{ instance.id }}); yaCounter950321.reachGoal('CallbackOpen'); + ga('send', 'event', 'Communication', 'callback_open'); }); consultation_link = true; diff --git a/zsite/templates/form_template/order_modal.html b/zsite/templates/form_template/order_modal.html index c6b83ed..466c585 100644 --- a/zsite/templates/form_template/order_modal.html +++ b/zsite/templates/form_template/order_modal.html @@ -22,7 +22,7 @@
{% endif %}
- +
@@ -101,7 +101,7 @@
- + {% if request.LANGUAGE_CODE == 'ru' %}

Вы можете обратить к нам с вопросом или заказать услугу «{{ instance.name }}»

{% else %} @@ -120,6 +120,7 @@ angular.element($('.order-form')[0]).scope().open({{ instance.id }}); yaCounter950321.reachGoal('OrderOpen'); + ga('send', 'event', 'Service', 'order_open'); }); consultation_link = true;