1π
A possible solution is to store a value in the userβs session.
It should be pretty easy assuming you have a separate view for each page.
Set the session variable in the signup view, after a successful signup (before redirecting):
request.session['conversion'] = True
And then add the value to the context in the thank you page:
return direct_to_template(request, template_name, {
'conversion': request.session.pop('conversion', False),
})
Then you simply wrap the conversion tracking code in an if statement in the template:
{% if conversion %}
{# Conversion tracking script #}
{% endif %}
I think that this is more reliable then checking the referrer.
1π
Checking HTTP_REFERER
is pretty reliable; check the referrer in your view:
data = {
'foo': 'bar',
...
}
if request.META.get('HTTP_REFERER', False) == reverse('signup'):
data.update({'conversion': True})
render(request, 'thanks.html', data)
then use that information in your template to determine whether to detect a conversion:
{% if conversion %}<script type='text/javascript'> // record conversion</script>{% endif %}
Although Yuriβs answer is more generally correct (as it ensures that each conversion will be recorded at least once, as long as the user visits the thank-you page within a reasonable time-frame), it will involve a hit to session storage every time. Use either, or both ;)
- [Answered ]-Got an unexpected keyword argument 'pk' on genric view
- [Answered ]-Django: Update object from view, with no model or template
- [Answered ]-Django NoReverseMatch Error With Namespacing
- [Answered ]-Python django redirect url on render
- [Answered ]-Get error message with custom validation Class on Tastypie