mirror of
https://github.com/DerTyp7/tealcode-django-python.git
synced 2025-10-29 12:32:09 +01:00
Merge branch 'better-analytics'
This commit is contained in:
@@ -41,8 +41,6 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'main.apps.MainConfig',
|
'main.apps.MainConfig',
|
||||||
'analytics.apps.AnalyticsConfig',
|
|
||||||
'ipware',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from django.views.generic.base import TemplateView
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('main.urls')),
|
path('', include('main.urls')),
|
||||||
path('analytics/', include('analytics.urls')),
|
|
||||||
path("robots.txt", TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
|
path("robots.txt", TemplateView.as_view(template_name="robots.txt", content_type="text/plain")),
|
||||||
path('AD/SDGFOLKJASDNVASDFASDFSLAKDF/', admin.site.urls),
|
path('AD/SDGFOLKJASDNVASDFASDFSLAKDF/', admin.site.urls),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
from analytics.models import View
|
|
||||||
|
|
||||||
admin.site.register(View)
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class AnalyticsConfig(AppConfig):
|
|
||||||
default_auto_field = 'django.db.models.BigAutoField'
|
|
||||||
name = 'analytics'
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
# Generated by Django 3.2.9 on 2021-11-22 18:23
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
import django.utils.timezone
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('main', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name='View',
|
|
||||||
fields=[
|
|
||||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
||||||
('ip', models.CharField(max_length=200)),
|
|
||||||
('date', models.DateTimeField(default=django.utils.timezone.now)),
|
|
||||||
('admin', models.BooleanField(default=False)),
|
|
||||||
('home', models.BooleanField(default=False)),
|
|
||||||
('category', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='main.category')),
|
|
||||||
('topic', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='main.topic')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
from django.utils import timezone
|
|
||||||
from main.models import Topic, Category
|
|
||||||
|
|
||||||
class View(models.Model):
|
|
||||||
ip = models.CharField(max_length=200)
|
|
||||||
date = models.DateTimeField(default=timezone.now)
|
|
||||||
topic = models.ForeignKey(Topic, on_delete=models.CASCADE, blank=True, null=True)
|
|
||||||
category = models.ForeignKey(Category, on_delete=models.CASCADE, blank=True, null=True)
|
|
||||||
admin = models.BooleanField(default=False)
|
|
||||||
home = models.BooleanField(default=False)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.ip
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{% extends "base.html" %}
|
|
||||||
{% block content %}
|
|
||||||
<h2>Analytics</h2>
|
|
||||||
|
|
||||||
<div class="main-content-block">
|
|
||||||
<h5>Clicks Last 30 Days</h5>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="main-content-block">
|
|
||||||
<h5>Clicks In Total</h5>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="main-content-block">
|
|
||||||
<h5>Clicks From Coutries Last 30 Days</h5>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="main-content-block">
|
|
||||||
<h5>Clicks From Coutries In Total</h5>
|
|
||||||
</div>
|
|
||||||
{% endblock content %}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
from . import views
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path('', views.index, name="analytics-index"),
|
|
||||||
]
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
from django.shortcuts import render
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def index(req):
|
|
||||||
return render(req, 'analytics/index.html')
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
# Generated by Django 3.2.9 on 2021-11-22 18:23
|
# Generated by Django 3.2.9 on 2021-11-23 17:55
|
||||||
|
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|||||||
22
TealCode/main/static/js/cookies.js
Normal file
22
TealCode/main/static/js/cookies.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
function accept_cookies(){
|
||||||
|
document.cookie = "cookies_allowed=1;path=/";
|
||||||
|
window.location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
document.write('<div style="background-color: rgba(255, 255, 255, 0.219);" id="cookie_banner" class="text-center"><p>We only use non-technical cookies for analysis purposes.<br> Do you want to accept those cookies? (please)</p><button class="btn btn-success mb-3" onclick="accept_cookies()">Accept</button></div>');
|
||||||
|
|
||||||
|
cookies_allowed = document.cookie.split("cookies_allowed=")[1][0]
|
||||||
|
|
||||||
|
if(cookies_allowed == null){
|
||||||
|
document.cookie = "cookies_allowed=0;path=/";
|
||||||
|
cookies_allowed = document.cookie.split("cookies_allowed=")[1]
|
||||||
|
}
|
||||||
|
if(cookies_allowed == "1"){
|
||||||
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag(){dataLayer.push(arguments);}
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', 'G-PGM5LTFSMG');
|
||||||
|
document.getElementById("cookie_banner").style.display = "none";
|
||||||
|
}else if(cookies_allowed == "0"){
|
||||||
|
console.log("DO NOT LOAD ANALYTILCS");
|
||||||
|
}
|
||||||
@@ -2,6 +2,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<!-- Google Analytics -->
|
||||||
|
<script async src="https://www.googletagmanager.com/gtag/js?id=G-PGM5LTFSMG"></script>
|
||||||
|
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;ga('create', 'UA-213552250-1', {'storage': 'none',});ga('send', 'pageview');</script>
|
||||||
|
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
||||||
|
<script src="{% static 'js/cookies.js' %}"></script>
|
||||||
|
<!-- End Google Analytics -->
|
||||||
|
|
||||||
<!-- Required META Tags-->
|
<!-- Required META Tags-->
|
||||||
<meta charset="utf-8"/>
|
<meta charset="utf-8"/>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||||
@@ -26,31 +33,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-dark">
|
<body class="bg-dark">
|
||||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
|
||||||
<script async src="https://www.googletagmanager.com/gtag/js?id=G-9M4H60DMBG"></script>
|
|
||||||
<div style="background-color: rgba(255, 255, 255, 0.219);" id="cookie_banner" class="text-center">
|
|
||||||
<p>We only use non-technical cookies for analysis purposes.<br> Do you want to accept those cookies? (please)</p>
|
|
||||||
<button class="btn btn-success mb-3" onclick='document.cookie = "cookies_allowed=1;path=/";window.location.reload();'>Accept</button>
|
|
||||||
</div>
|
|
||||||
<script>
|
|
||||||
cookies_allowed = document.cookie.split("cookies_allowed=")[1][0]
|
|
||||||
console.log(cookies_allowed)
|
|
||||||
|
|
||||||
if(cookies_allowed == null){
|
|
||||||
document.cookie = "cookies_allowed=0;path=/";
|
|
||||||
cookies_allowed = document.cookie.split("cookies_allowed=")[1]
|
|
||||||
}
|
|
||||||
if(cookies_allowed == "1"){
|
|
||||||
window.dataLayer = window.dataLayer || [];
|
|
||||||
function gtag(){dataLayer.push(arguments);}
|
|
||||||
gtag('js', new Date());
|
|
||||||
|
|
||||||
gtag('config', 'G-9M4H60DMBG');
|
|
||||||
document.getElementById("cookie_banner").style.display = "none";
|
|
||||||
}else if(cookies_allowed == "0"){
|
|
||||||
console.log("DO NOT LOAD ANALYTILCS");
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
<header class="p-3 bg-dark text-white shadow">
|
<header class="p-3 bg-dark text-white shadow">
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
from django.http.response import HttpResponse, HttpResponseForbidden
|
from django.http.response import HttpResponse
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from .models import Category, Topic, Rating
|
from .models import Category, Topic, Rating
|
||||||
from analytics.models import View
|
|
||||||
|
|
||||||
def index(req):
|
def index(req):
|
||||||
view = View(ip=get_ip(req), home=True)
|
|
||||||
view.save()
|
|
||||||
categorys_obj = Category.objects.all()
|
categorys_obj = Category.objects.all()
|
||||||
return render(req, "main/index.html", {'categorys': categorys_obj})
|
return render(req, "main/index.html", {'categorys': categorys_obj})
|
||||||
|
|
||||||
@@ -40,10 +37,6 @@ def topic(req, category, topic):
|
|||||||
'notHelpful_count': notHelpful_count,
|
'notHelpful_count': notHelpful_count,
|
||||||
'read_more': topic_obj.read_more,
|
'read_more': topic_obj.read_more,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
view = View(ip=get_ip(req), topic=topic_obj)
|
|
||||||
view.save()
|
|
||||||
return render(req, "main/topic.html", context)
|
return render(req, "main/topic.html", context)
|
||||||
|
|
||||||
return redirect("main-index")
|
return redirect("main-index")
|
||||||
@@ -57,9 +50,6 @@ def category(req, category):
|
|||||||
if category_obj:
|
if category_obj:
|
||||||
topics_obj = Topic.objects.filter(category=category_obj)
|
topics_obj = Topic.objects.filter(category=category_obj)
|
||||||
|
|
||||||
view = View(ip=get_ip(req), category=category_obj)
|
|
||||||
view.save()
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'category_obj': category_obj,
|
'category_obj': category_obj,
|
||||||
'topics': topics_obj,
|
'topics': topics_obj,
|
||||||
@@ -83,8 +73,6 @@ def search(req, value): # https://django-taggit.readthedocs.io/en/latest/getting
|
|||||||
def sitemap(req):
|
def sitemap(req):
|
||||||
topics = Topic.objects.all()
|
topics = Topic.objects.all()
|
||||||
categories = Category.objects.all()
|
categories = Category.objects.all()
|
||||||
#REPLACE ALL BLANKS WITH %20
|
|
||||||
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
'topics': topics,
|
'topics': topics,
|
||||||
|
|||||||
Reference in New Issue
Block a user