Search code examples
google-analyticse-commerceaffiliate

Affiliate Code In Google Analytics


With enhanced e-commerce reports, there is now a section that reports on 'affiliate code.' However I can't find how that data is populated. Is there something that needs to be pushed into the data layer using a specific attribute? Thanks!


Solution

  • You are probably looking for the affiliation property of a transaction. You can find it referenced in the docs here: https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#action-data

    With regards to pushing it into the dataLayer (by this I assume you are using Google Tag Manager), you should add it as a key value pair in the actionField of the ecommerce.purchase object that you push into the dataLayer.

    Here is the sample code that Google Docs provide that shows the use of affiliation property:

    <script>
    // Send transaction data with a pageview if available
    // when the page loads. Otherwise, use an event when the transaction
    // data becomes available.
    dataLayer.push({
      'ecommerce': {
        'purchase': {
          'actionField': {
            'id': 'T12345',                         // Transaction ID. Required for purchases and refunds.
            'affiliation': 'Online Store',
            'revenue': '35.43',                     // Total transaction value (incl. tax and shipping)
            'tax':'4.90',
            'shipping': '5.99',
            'coupon': 'SUMMER_SALE'
          },
          'products': [{                            // List of productFieldObjects.
            'name': 'Triblend Android T-Shirt',     // Name or ID is required.
            'id': '12345',
            'price': '15.25',
            'brand': 'Google',
            'category': 'Apparel',
            'variant': 'Gray',
            'quantity': 1,
            'coupon': ''                            // Optional fields may be omitted or set to empty string.
           },
           {
            'name': 'Donut Friday Scented T-Shirt',
            'id': '67890',
            'price': '33.75',
            'brand': 'Google',
            'category': 'Apparel',
            'variant': 'Black',
            'quantity': 1
           }]
        }
      }
    });
    </script>