Search code examples
angulargoogle-analyticsgoogle-tag-managerangulartics2

How to pass ecommerce object in Angulartics2 eventTrack(this.angulartics2.eventTrack.next({ action: 'myAction', properties: {myproperties})?


I am able to send basic event to ga using angulartics2 eventtrack as follows,

this.angulartics2.eventTrack.next({ action: 'myAction', properties: { category: 'myCategory', label: 'mylabel', value: 'myvalue' }})

If I pass ecommerce object to the same eventTrack, the ecommerce data is not sent.

 this.angulartics2.eventTrack.next({ action: 'myAction', properties: { category: 'myCategory', label: 'mylabel', value: 'myvalue', 
                                    ecommerce: {
                                        'detail': {
                                        'products': 'AnalyticsObject.Products'
                                      }
                                    } 
                                }
                            });  

The data sent to ga is, data sent to ga seen in ga debugger

Can somebody help? Thanks in advance.


Solution

  • I had the same problem, the main issue here is that the ecommerce object is not passed through by the library. If you look at the reference:

    https://github.com/angulartics/angulartics2/blob/master/src/providers/gtm/angulartics2-gtm.ts#L52

    So to push the ecommerce data you'll have to push it to the datalayer yourself or wait for a merge request to be accepted:

    https://github.com/angulartics/angulartics2/pull/102

    I push the ecommerce data to the datalayer in the code instead, not the best solution but for now it works.