wc-django-utm


Namewc-django-utm JSON
Version 0.1.0 PyPI version JSON
download
home_page
SummaryUTM parameters tracker.
upload_time2023-12-19 07:16:05
maintainer
docs_urlNone
authorWebCase
requires_python>=3.6
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WebCase UTM tracker

Simple middleware and utils for tracking utm parameters.

## Installation

```sh
pip install wc-django-utm
```

In `settings.py`:

```python
INSTALLED_APPS += [
  'wcd_utm',
]

WCD_UTM = {
  # All the "main" parameters that must be resolved.
  'PARAMETERS': [
    'utm_source', 'utm_medium', 'utm_campaign',
    'utm_term', 'utm_content',

    'gclid', 'aclk', 'msclkid', 'fbclid', 'twclid',
  ]),
  # Additional parameter prefixes. Also used to convert prefixed parameters
  # like "utm_content" into "content".
  'RESOLVABLE_PREFIXES':['utm_'],

  # Used to store all different utm parameters sets, that user had during the
  # session.
  'SESSION_STORAGE_KEY': 'utm_params_stored',
  # Latest utm parameters set. The key that you are mostly going to use.
  'SESSION_ACCESS_KEY': 'utm_params',

  # Header to parse UTM parameters from as if it is URL.
  # Use this to pass utm parameters from Android/iOS app, for example.
  'HEADER_ORIGIN_URL': 'HTTP_X_UTM_ORIGIN_URL',
  # Same as previous, but this one should store JSON data instead of plain
  # URL string.
  'HEADER_JSON': 'HTTP_X_UTM_JSON',
}
```

## Usage

Most of the time only the middleware will be used:

```python
MIDDLEWARE = [
  # ...
  'django.contrib.sessions.middleware.SessionMiddleware',
  # MUST be placed after session middleware ^.
  'wcd_utm.middleware.UTMSessionMiddleware',
  # ...
]
```

### In a view

Middleware will store parsed data in a `SESSION_ACCESS_KEY`(`'utm_params'`) key. Parameter values will always be a list of strings:

```python
def some_view(request):
  params = request.session["utm_params"]

  # Values are always lists
  if 'black_friday_sale' in params.get('utm_campaign', []):
    # Then do stuff related to you black friday sale campaign.
    pass

  # ...
```

# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.0]
Initial version.
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "wc-django-utm",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "WebCase",
    "author_email": "info@webcase.studio",
    "download_url": "https://files.pythonhosted.org/packages/ba/c3/982dd0fa87d3b3d6b706fcb253ad39459de7080ad35b43941b126f1916d7/wc-django-utm-0.1.0.tar.gz",
    "platform": null,
    "description": "# WebCase UTM tracker\n\nSimple middleware and utils for tracking utm parameters.\n\n## Installation\n\n```sh\npip install wc-django-utm\n```\n\nIn `settings.py`:\n\n```python\nINSTALLED_APPS += [\n  'wcd_utm',\n]\n\nWCD_UTM = {\n  # All the \"main\" parameters that must be resolved.\n  'PARAMETERS': [\n    'utm_source', 'utm_medium', 'utm_campaign',\n    'utm_term', 'utm_content',\n\n    'gclid', 'aclk', 'msclkid', 'fbclid', 'twclid',\n  ]),\n  # Additional parameter prefixes. Also used to convert prefixed parameters\n  # like \"utm_content\" into \"content\".\n  'RESOLVABLE_PREFIXES':['utm_'],\n\n  # Used to store all different utm parameters sets, that user had during the\n  # session.\n  'SESSION_STORAGE_KEY': 'utm_params_stored',\n  # Latest utm parameters set. The key that you are mostly going to use.\n  'SESSION_ACCESS_KEY': 'utm_params',\n\n  # Header to parse UTM parameters from as if it is URL.\n  # Use this to pass utm parameters from Android/iOS app, for example.\n  'HEADER_ORIGIN_URL': 'HTTP_X_UTM_ORIGIN_URL',\n  # Same as previous, but this one should store JSON data instead of plain\n  # URL string.\n  'HEADER_JSON': 'HTTP_X_UTM_JSON',\n}\n```\n\n## Usage\n\nMost of the time only the middleware will be used:\n\n```python\nMIDDLEWARE = [\n  # ...\n  'django.contrib.sessions.middleware.SessionMiddleware',\n  # MUST be placed after session middleware ^.\n  'wcd_utm.middleware.UTMSessionMiddleware',\n  # ...\n]\n```\n\n### In a view\n\nMiddleware will store parsed data in a `SESSION_ACCESS_KEY`(`'utm_params'`) key. Parameter values will always be a list of strings:\n\n```python\ndef some_view(request):\n  params = request.session[\"utm_params\"]\n\n  # Values are always lists\n  if 'black_friday_sale' in params.get('utm_campaign', []):\n    # Then do stuff related to you black friday sale campaign.\n    pass\n\n  # ...\n```\n\n# Changelog\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n## [Unreleased]\n\n## [0.1.0]\nInitial version.",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "UTM parameters tracker.",
    "version": "0.1.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bac3982dd0fa87d3b3d6b706fcb253ad39459de7080ad35b43941b126f1916d7",
                "md5": "a6cc2533e5f6989bbf3f9470adf3fe52",
                "sha256": "f73209de3233173e18ab1037ffe7b13e96762622d91bd545861c2a17f3ac1c9c"
            },
            "downloads": -1,
            "filename": "wc-django-utm-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a6cc2533e5f6989bbf3f9470adf3fe52",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 6582,
            "upload_time": "2023-12-19T07:16:05",
            "upload_time_iso_8601": "2023-12-19T07:16:05.986738Z",
            "url": "https://files.pythonhosted.org/packages/ba/c3/982dd0fa87d3b3d6b706fcb253ad39459de7080ad35b43941b126f1916d7/wc-django-utm-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-19 07:16:05",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "wc-django-utm"
}
        
Elapsed time: 0.55229s