# Generated migration for survey tracking features from django.db import migrations, models import django.db.models.deletion class Migration(migrations.Migration): dependencies = [ ('surveys', '0002_remove_surveyinstance_journey_stage_instance_and_more'), ] operations = [ # Add tracking fields to SurveyInstance migrations.AddField( model_name='surveyinstance', name='open_count', field=models.PositiveIntegerField(default=0, help_text='Number of times the survey link was opened'), ), migrations.AddField( model_name='surveyinstance', name='last_opened_at', field=models.DateTimeField(blank=True, null=True), ), migrations.AddField( model_name='surveyinstance', name='time_spent_seconds', field=models.PositiveIntegerField(default=0, help_text='Total time spent on survey in seconds'), ), # Update status field choices migrations.AlterField( model_name='surveyinstance', name='status', field=models.CharField( choices=[ ('sent', 'Sent'), ('viewed', 'Viewed'), ('in_progress', 'In Progress'), ('completed', 'Completed'), ('abandoned', 'Abandoned'), ('expired', 'Expired'), ('cancelled', 'Cancelled'), ], default='sent', max_length=20, help_text='Current status of the survey instance' ), ), # Create SurveyTracking model migrations.CreateModel( name='SurveyTracking', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created_at', models.DateTimeField(auto_now_add=True)), ('event_type', models.CharField( choices=[ ('page_view', 'Page View'), ('survey_started', 'Survey Started'), ('question_answered', 'Question Answered'), ('survey_completed', 'Survey Completed'), ('survey_abandoned', 'Survey Abandoned'), ('reminder_sent', 'Reminder Sent'), ], default='page_view', max_length=20, help_text='Type of tracking event' )), ('time_on_page', models.PositiveIntegerField(blank=True, null=True, help_text='Time spent on current page in seconds')), ('total_time_spent', models.PositiveIntegerField(default=0, help_text='Total time spent in survey in seconds')), ('current_question', models.PositiveIntegerField(blank=True, null=True, help_text='Current question number being viewed')), ('user_agent', models.TextField(blank=True, help_text='Browser user agent string')), ('ip_address', models.GenericIPAddressField(blank=True, null=True)), ('device_type', models.CharField(blank=True, max_length=50)), ('browser', models.CharField(blank=True, max_length=50)), ('country', models.CharField(blank=True, max_length=100)), ('city', models.CharField(blank=True, max_length=100)), ('metadata', models.JSONField(blank=True, null=True, default=dict, help_text='Additional tracking metadata')), ('survey_instance', models.ForeignKey( on_delete=django.db.models.deletion.CASCADE, related_name='tracking_events', to='surveys.surveyinstance' )), ], options={ 'verbose_name': 'Survey Tracking', 'verbose_name_plural': 'Survey Tracking Events', 'ordering': ['-created_at'], 'indexes': [ models.Index(fields=['survey_instance', '-created_at'], name='idx_survey_instance_created'), models.Index(fields=['event_type', '-created_at'], name='idx_event_type_created'), models.Index(fields=['ip_address'], name='idx_ip_address'), ], }, ), ]