Skip to content

Commit

Permalink
track visitorId on checkout (#8655)
Browse files Browse the repository at this point in the history
* track visitorId on checkout

* make fix

* log uid
  • Loading branch information
owocki authored Mar 23, 2021
1 parent aae45e4 commit fd59862
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/app/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def preprocess(request):
except Exception as e:
logger.exception(e)
metadata = {
'visitorId': request.COOKIES.get("visitorId", None),
'useragent': request.META['HTTP_USER_AGENT'],
'referrer': request.META.get('HTTP_REFERER', None),
'path': request.META.get('PATH_INFO', None),
Expand Down
4 changes: 4 additions & 0 deletions app/assets/v2/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,12 @@ $(document).ready(function() {
});
};

if (document.visitorId) {
Cookies.set('visitorId', document.visitorId);
}
record_campaign_to_cookie();


if (!$('.header > .minihero').length && $('.header > .navbar').length) {
$('.header').css('overflow', 'visible');
}
Expand Down
1 change: 1 addition & 0 deletions app/assets/v2/js/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ Vue.component('grants-cart', {
signature: 'onetime',
splitter_contract_address: contractAddress,
subscription_hash: 'onetime',
visitorId: document.visitorId,
// Values that vary by donation
'gitcoin-grant-input-amount': [],
admin_address: [],
Expand Down
2 changes: 0 additions & 2 deletions app/grants/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ class SubscriptionAdmin(GeneralAdmin):
raw_id_fields = ['grant', 'contributor_profile']
readonly_fields = [
'contributions_links',
'error_email_copy_insufficient_balance',
'error_email_copy_not_active',
]

def contributions_links(self, instance):
Expand Down
18 changes: 18 additions & 0 deletions app/grants/migrations/0117_subscription_visitorid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2021-03-21 19:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('grants', '0116_auto_20210316_2021'),
]

operations = [
migrations.AddField(
model_name='subscription',
name='visitorId',
field=models.CharField(blank=True, default='', help_text='The visitorID of the contributor', max_length=255),
),
]
6 changes: 6 additions & 0 deletions app/grants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,12 @@ class Subscription(SuperModel):
help_text=_('The amount per contribution period in USDT'),
)
tenant = models.CharField(max_length=10, null=True, blank=True, default="ETH", choices=TENANT, help_text="specific tenant in which contribution is made")
visitorId = models.CharField(
default='',
max_length=255,
help_text=_('The visitorID of the contributor'),
blank=True,
)

@property
def negative(self):
Expand Down
1 change: 1 addition & 0 deletions app/grants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def process_grant_contribution(self, grant_id, grant_slug, profile_id, package,
subscription.split_tx_id = package.get('split_tx_id', '0x0')
subscription.num_tx_approved = package.get('num_tx_approved', 1)
subscription.network = package.get('network', '')
subscription.visitorId = package.get('visitorId', '')
if subscription.network == 'undefined':
# we unfortunately cannot trust the frontend to give us a valid network name
# so this handles that case. more details are available at
Expand Down
1 change: 1 addition & 0 deletions app/grants/templates/grants/cart-vue.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ <h1 class="text-left text-black mt-5 mb-3">Grants Cart</h1>
{% include 'shared/footer_scripts.html' with slim=1 ignore_inject_web3=1 %}
{% include 'shared/footer.html' %}
{% include 'grants/shared/shared_scripts.html' %}
{% include 'shared/fingerprintjs.html' %}

{% comment %} ===================== START ZKSYNC SCRIPTS ====================== {% endcomment %}
<script type="text/javascript" src="https://cdn.ethers.io/lib/ethers-5.0.umd.min.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2199,6 +2199,7 @@ def bulk_fund(request):
'real_period_seconds': request.POST.get('real_period_seconds'),
'recurring_or_not': request.POST.get('recurring_or_not'),
'signature': request.POST.get('signature'),
'visitorId': request.POST.get('visitorId'),
'splitter_contract_address': request.POST.get('splitter_contract_address'),
'subscription_hash': request.POST.get('subscription_hash'),
'anonymize_gitcoin_grants_contributions': json.loads(request.POST.get('anonymize_gitcoin_grants_contributions', 'false')),
Expand Down Expand Up @@ -2243,7 +2244,6 @@ def bulk_fund(request):

from grants.tasks import batch_process_grant_contributions
batch_process_grant_contributions.delay(grants_with_payload, profile.pk)

return JsonResponse({
'success': True,
'grant_ids': grant_ids_list,
Expand Down
12 changes: 12 additions & 0 deletions app/retail/templates/shared/fingerprintjs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
function initFingerprintJS() {
FingerprintJS.load({token: 'W0FUPDGsTv97t0sPFbgI'})
.then(fp => fp.get({ pid: document.contxt.profile_id}))
.then(result => document.visitorId = result.visitorId);
}
</script>
<script
async
src="https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs-pro@3/dist/fp.min.js"
onload="initFingerprintJS()"
></script>

0 comments on commit fd59862

Please sign in to comment.