Skip to content

Commit

Permalink
Fix GA4 output for purchase (#2310)
Browse files Browse the repository at this point in the history
  • Loading branch information
JenniWhitman authored Jul 25, 2024
1 parent 44e1ab7 commit 6bbb241
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ecommerce/templates/checkout_interstitial.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ <h1 class="mt-4">Redirecting to the payment processor...</h1>
{% endfor %}
</form>
{% if ga_purchase_flag %}
{{ ga_purchase_payload | json_script:"ga-purchase-payload" }}
<script type="text/javascript">
const ga_purchase_payload = JSON.parse({{ ga_purchase_payload|safe }});
gtag("event", "purchase", ga_purchase_payload);
gtag("event", "purchase", JSON.parse(document.getElementById('ga-purchase-payload').textContent));
</script>
{% endif %}
<script type="text/javascript">
Expand Down
6 changes: 3 additions & 3 deletions ecommerce/views/v0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,8 @@ def _create_ga4_context(self, order):
"item_id": line.purchased_object_id,
"item_name": line.item_description,
"affiliation": "MITx Online",
"discount": line.discounted_price,
"price": line.total_price,
"discount": str(line.discounted_price),
"price": str(line.total_price),
"quantity": line.quantity,
"item_category": "Series",
}
Expand All @@ -730,7 +730,7 @@ def _create_ga4_context(self, order):
payload_items.append(line_object)
ga_purchase_payload = {
"transaction_id": order.reference_number,
"value": order.total_price_paid,
"value": str(order.total_price_paid),
"tax": 0.00,
"shipping": 0.00,
"currency": "USD",
Expand Down

0 comments on commit 6bbb241

Please sign in to comment.