eCommerce with Gtag

Discussion in 'Integration' started by jigsawtrading, Feb 24, 2020.

  1. jigsawtrading

    jigsawtrading aMember Pro Customer

    Joined:
    Sep 28, 2012
    Messages:
    24
    Hi - I'm looking at this guide for Google eCommerce integration.

    https://developers.google.com/analytics/devguides/collection/gtagjs/ecommerce

    On their site, this is how it says it needs to be set up.

    Code:
    gtag('event', 'purchase', {
      "transaction_id": "24.031608523954162",
      "affiliation": "Google online store",
      "value": 23.07,
      "currency": "USD",
      "tax": 1.24,
      "shipping": 0,
      "items": [
        {
          "id": "P12345",
          "name": "Android Warhol T-Shirt",
          "list_name": "Search Results",
          "brand": "Google",
          "category": "Apparel/T-Shirts",
          "variant": "Black",
          "list_position": 1,
          "quantity": 2,
          "price": '2.0'
        },
        {
          "id": "P67890",
          "name": "Flame challenge TShirt",
          "list_name": "Search Results",
          "brand": "MyBrand",
          "category": "Apparel/T-Shirts",
          "variant": "Red",
          "list_position": 2,
          "quantity": 1,
          "price": '3.0'
        }
      ]
    });
    On aMember side it says this:

    The following variables will be automatically replaced:
    %payment.tax%
    %payment.amount%
    %payment.dattm%
    %payment.discount%
    %invoice.public_id%
    %user.email%
    %afflogin%
    %affkeyword%
    you may also use %foreach_product% and %endforeach_product% tags
    to run cycle for all items in invoice, you may use %item.item_title% %item.qty% %item.first_total% %item.item_id% and similar variables inside

    Which is cool. I'm a little concerned about the comma "," though

    [{item1},{item2}, {item3}] is the syntax google wants.

    Here's what I think it is looking for:

    Code:
    gtag('event', 'purchase', {
      "transaction_id": "%invoice.public_id%",
      "affiliation": "aMember",
      "value": %payment.amount%,
      "currency": "USD",
      "tax": 0
      "shipping": 0,
      "items": [
    %foreach_product%
        {
          "id": "%item.item_id%",
          "name": "%item.item_title%",
          "list_name": "Search Results",
          "brand": "Jigsaw",
          "category": "Jigsaw",
          "variant": "",
          "list_position": 1,
          "quantity": %item.qty%,
          "price": '%item.first_total%'
        }
    %endforeach_product%
      ]
    });
    A couple of things I don't get.
    - Will it replace the item between the %%, even if there is "" around it?
    - What does it do about the comma "," between the products? Does it put it in?
    - Has anyone else done this with Google eCommerce tracking? I'd love to see an example.

    Best regards

    Peter

Share This Page