add tests and docs for ANALYTICAL_IDENTITY_FUNC settings

This commit is contained in:
Petr Dlouhý 2022-07-12 17:48:06 +02:00
parent 39961bfac9
commit 5ef70a6fc4
2 changed files with 20 additions and 0 deletions

View file

@ -25,3 +25,17 @@ their default values.
``GOOGLE_ANALYTICS_INTERNAL_IPS`` to configure for Google Analytics.
See :ref:`internal-ips`.
.. data:: ANALYTICAL_IDENTITY_FUNC
Default: Identity function dependent on provider
A function that returns the identity of the given user. This overrides the
default settings of different providers.
E.g. Google has in its conditions for enabling UserID the requirement, that prohibits
sending personal data (such as an e-mail address) to analytics.
If e-mail address is used as username, using GTag would break the requirements.
In such case add uuid field to the user and set ```ANALYTICAL_IDENTITY_FUNC``` to
```lambda user: user.uuid```

View file

@ -34,6 +34,7 @@ class SettingDeletedTestCase(TestCase):
class MyUser(AbstractBaseUser):
identity = models.CharField(max_length=50)
name = models.CharField(max_length=50)
USERNAME_FIELD = 'identity'
class Meta:
@ -46,6 +47,11 @@ class GetIdentityTestCase(TestCase):
get_id = get_identity(Context({}), user=MyUser(identity='fake_id'))
assert get_id == 'fake_id'
@override_settings(ANALYTICAL_IDENTITY_FUNC=lambda user: f"{user.name} ({user.identity})")
def test_custom_username_field_identity_func(self):
get_id = get_identity(Context({}), user=MyUser(identity='fake_id', name='fake_name'))
assert get_id == 'fake_name (fake_id)'
@override_settings(ANALYTICAL_DOMAIN="example.org")
class GetDomainTestCase(TestCase):