Skip to content

Commit

Permalink
Google Analytics integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Chaptsev committed Nov 20, 2017
1 parent ae9cf46 commit 14ea3a2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ Answer the prompts with your own desired options. For example::
2 - Amazon S3 for static and media
Choose from 1, 2 [1]: 1
====================== FRONT-END ===================== [ ]:
use_yandex_metrika [y]: y
Select analytics:
1 - Google Analytics
2 - Yandex metrika
3 - None
use_progressbar [n]: n
use_vue_material [n]: n

Expand Down
2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"static_and_media": ["Whitenoise for static, Amazon S3 for media", "Amazon S3 for static and media"],

"====================== FRONT-END =====================": " ",
"use_yandex_metrika": "y",
"analytics": ["Google Analytics", "Yandex Metrika", "None"],
"use_progressbar": "n",
"use_vue_material": "n"
}
8 changes: 6 additions & 2 deletions {{cookiecutter.project_slug}}/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@
# Mailgun api
DJANGO_MAILGUN_API_PUB = env('DJANGO_MAILGUN_API_PUB', default=None)

{% if cookiecutter.use_yandex_metrika == 'y' -%}
# YandexMetrika
{% if cookiecutter.analytics == 'Google Analytics' -%}
# Google Analytics
GOOGLE_ANALYTICS = env('GOOGLE_ANALYTICS', default=None){% endif %}

{% if cookiecutter.analytics == 'Yandex Metrika' -%}
# Yandex Metrika
YANDEX_METRIKA = env('YANDEX_METRIKA', default=None){% endif %}
3 changes: 2 additions & 1 deletion {{cookiecutter.project_slug}}/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ExtraContextTemplateView(TemplateView):
def get_context_data(self, **kwargs):
context = super(ExtraContextTemplateView, self).get_context_data(**kwargs)
context['DEBUG'] = settings.DEBUG
{% if cookiecutter.use_yandex_metrika == 'y' -%}context['yandex_metrika'] = settings.YANDEX_METRIKA{% endif %}
{% if cookiecutter.analytics == 'Google Analytics' -%}context['google_analytics'] = settings.GOOGLE_ANALYTICS{% endif %}
{% if cookiecutter.analytics == 'Yandex Metrika' -%}context['yandex_metrika'] = settings.YANDEX_METRIKA{% endif %}
return context


Expand Down
9 changes: 7 additions & 2 deletions {{cookiecutter.project_slug}}/env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ DJANGO_SERVER_EMAIL=info@{{cookiecutter.domain}}
DJANGO_SENTRY_DSN=
{% endif %}

{% if cookiecutter.use_yandex_metrika == 'y' -%}
# YandexMetrika
{% if cookiecutter.analytics == 'Google Analytics' -%}
# Google Analytics
GOOGLE_ANALYTICS=
{% endif %}

{% if cookiecutter.analytics == 'Yandex Metrika' -%}
# Yandex Metrika
YANDEX_METRIKA=
{% endif %}
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"sass-loader": "^6.0.6",
{% if cookiecutter.static_and_media == 'Amazon S3 for static and media' -%}"string-replace-loader": "^1.3.0",{% endif -%}
"vue": "^2.3.4",
{% if cookiecutter.analytics == "Google Analytics" -%}"vue-analytics": "^5.3.2",{% endif -%}
{% if cookiecutter.use_ckeditor == "Both" or cookiecutter.use_ckeditor == "Frontend" -%}"vue-ckeditor2": "^1.15.0",{% endif -%}
{% if cookiecutter.use_vue_material == 'y' -%}"vue-material": "^0.8.1",{% endif -%}
"vue-loader": "^12.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<div id="main"></div>
</body>

{% if cookiecutter.use_yandex_metrika == 'y' -%}{% raw %}{% if yandex_metrika %}
{% if cookiecutter.analytics == 'Google Analytics' -%}{% raw %}{% if google_analytics %}<script type="text/javascript">var analytics = {{ google_analytics }}</script>{% endif %}{% endraw %}{% endif %}
{% if cookiecutter.analytics == 'Yandex Metrika' -%}{% raw %}{% if yandex_metrika %}
<script src="https://mc.yandex.ru/metrika/watch.js"></script>
<script type="text/javascript">var metrika = new Ya.Metrika({id: {{ yandex_metrika }}})</script>
{% endif %}{% endraw %}{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import axios from 'axios'
import router from './router'
import {store} from './store'
import Meta from 'vue-meta'
{% if cookiecutter.analytics == 'Google Analytics' -%}
import VueAnalytics from 'vue-analytics'{% endif %}

{% if cookiecutter.use_progressbar == 'y' %}import VueProgressBar from 'vue-progressbar'{% endif %}
{% if cookiecutter.use_vue_material == 'y' %}
Expand All @@ -15,11 +17,13 @@ import Main from './Main.vue'
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = 'X-CSRFToken'

{% if cookiecutter.use_yandex_metrika == 'y' -%}
{% if cookiecutter.analytics == 'Yandex Metrika' -%}
router.afterEach ((to, from, next) => {
if (!DEBUG) {metrika.hit(to.path)} // YandexMetrika hit
}){% endif %}

{% if cookiecutter.analytics == 'Google Analytics' -%}Vue.use(VueAnalytics, {id: analytics, router}){% endif %}

{% if cookiecutter.use_progressbar == 'y' -%}
// Progress bar interceptors
axios.interceptors.request.use((config) => {
Expand Down

0 comments on commit 14ea3a2

Please sign in to comment.