Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit 3038c64

Browse files
authored
Update Documentation (#23)
1 parent eeeaaf6 commit 3038c64

File tree

9 files changed

+160
-39
lines changed

9 files changed

+160
-39
lines changed

docs/conf.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/configuration.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Configuration
2+
3+
The configuration is a list of dicts and each dict consists of three fields, one being mandatory and the other two being optional:
4+
5+
- id(string, required): Experiment id required to identify each experiment in the cookie set by Google.
6+
- alias(string, optional): Alias for the experiment id, useful for clarity when accessing experiment variants by key.
7+
- variant_aliases(dict, optional): Aliases for each variant, consist of key-value variables. The key represents the index for each experiment variant. The value is the alias for the variant. Check your Google Optimize experiment to see which index represents what experiment variant.
8+
9+
## Single experiment
10+
11+
For a single experiment the settings could be the following:
12+
13+
```py
14+
# django-google-optimize
15+
GOOGLE_OPTIMIZE_EXPERIMENTS = [
16+
{
17+
"id": "utSuKi3PRbmxeG08en8VNw",
18+
"alias": "redesign",
19+
"variant_aliases": {0: "old_design", 1: "new_design"},
20+
}
21+
]
22+
```
23+
24+
## Multiple experiments
25+
26+
For multiple experiments the settings could be the following:
27+
28+
```py
29+
# django-google-optimize
30+
GOOGLE_OPTIMIZE_EXPERIMENTS = [
31+
{
32+
"id": "3x8_BbSCREyqtWm1H1OUrQ",
33+
"alias": "redesign_page",
34+
"variant_aliases": {0: "old_design", 1: "new_design"},
35+
},
36+
{
37+
"id": "7IXTpXmLRzKwfU-Eilh_0Q",
38+
"alias": "redesign_header",
39+
"variant_aliases": {0: "old_header", 1: "new_header"},
40+
},
41+
]
42+
```
43+
44+
## Notes
45+
46+
If you do not set the alias you'll have to access the experiment variant by the Google Optimize id for the experiment.
47+
48+
If you do not set the variant alias for a variant the index will be the variant returned.

docs/getting_started.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

docs/index.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Welcome to django-google-optimize's documentation!
2+
3+
django-google-optimize is a reusable Django application designed to make running server side Google Optimize A/B test easy.
4+
5+
## Contents
6+
7+
* [Installation](./installation.md)
8+
* [Configuration](./configuration.md)
9+
* [Usage](./usage.md)

docs/index.rst

Lines changed: 0 additions & 16 deletions
This file was deleted.

docs/installation.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Installing django-google-optimize
2+
3+
Install django-google-optimize with pip:
4+
5+
`pip install django-google-optimize`
6+
7+
Add the application to installed django applications:
8+
9+
```py
10+
DJANGO_APPS = [
11+
...
12+
"django_google_optimize",
13+
...
14+
]
15+
```
16+
17+
Add the middleware:
18+
19+
```py
20+
MIDDLEWARE = [
21+
...
22+
"django_google_optimize.middleware.google_optimize",
23+
...
24+
]
25+
```
26+
27+
If you want to access the request in your templates remember to add the request context processor:
28+
29+
```python
30+
TEMPLATES = [
31+
{
32+
"BACKEND": "django.template.backends.django.DjangoTemplates",
33+
"APP_DIRS": True,
34+
"DIRS": [path.join(path.dirname(__file__), "templates"),],
35+
"OPTIONS": {
36+
"context_processors": ["django.template.context_processors.request",]
37+
},
38+
}
39+
]
40+
```

docs/usage.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Usage
2+
3+
## Usage in templates
4+
5+
If you are redesigning major changes then you maybe would like to have two different templates. You can create a file that is called `jobs/xyz.html` that target two different files based on the experiment variant.
6+
7+
`jobs/xyz.html`
8+
9+
```django
10+
{% if request.google_optimize.redesign == "new_design" %}
11+
{% include "jobs/xyz_new.html" %}
12+
{% else %}
13+
{% include "jobs/xyz_old.html" %}
14+
{% endif %}
15+
```
16+
17+
Or you can use `django-google-optimize` inline within a single template:
18+
19+
```django
20+
<nav class="navbar navbar-expand-lg navbar-dark
21+
{% if request.google_optimize.redesign == "new_design" %} navbar-redesign{% endif %}
22+
">
23+
```
24+
25+
## Usage in views
26+
27+
To display two different templates based on the experiment variant:
28+
29+
```python
30+
def get_template_names(self):
31+
variant = request.google_optimize.get("redesign", None)
32+
if variant == "new":
33+
return ["jobs/xyz_new.html"]
34+
return ["jobs/xyz_old.html"]
35+
```
36+
37+
Adjust the queryset based of the experiment variant:
38+
39+
```python
40+
def get_queryset(self):
41+
variant = self.request.google_optimize.get("redesign", None)
42+
43+
if variant == "new":
44+
qs = qs.exclude(design__contains="old")
45+
```

mkdocs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
site_name: django-google-optimize
3+
nav:
4+
- Home: index.md
5+
- Installation: installation.md
6+
- Configuration: configuration.md
7+
- Usage: usage.md
8+
theme: readthedocs
9+
repo_url: https://github.com/adinhodovic/django-google-optimize/
10+
site_url: https://github.com/adinhodovic/django-google-optimize/
11+
copyright: Adin Hodovic and individual contributors
12+
site_author: Adin Hodovic
13+
14+
extra:
15+
version: 0.1
16+
release: 0.1.7

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ deps =
4747
commands = pylint django_google_optimize tests
4848

4949
[testenv:docs]
50-
deps = sphinx
51-
commands = sphinx-build -n -W docs docs/_build
50+
deps = mkdocs
51+
commands = mkdocs build
5252

5353
[testenv:release]
5454
deps =

0 commit comments

Comments
 (0)