Java script to push data to Google tag manager

Silverstripe Version: 3.2

Question: I have a demo for a script and I want someone to help with this script

Details of your query go here

// Include any relevant code. If you have a lot of code, link to a gist instead.

        'event': 'purchase',
        'ecommerce': {
          'purchase': {
            'actionField': {
              'id': 'T12345',                 // Transaction ID. Required for purchases and refunds.
              'affiliation': 'Mob',      // i.e. Donation site. e.g. 
Mob, Donation, etc. 
              'revenue': '35.00',             // Total transaction value (incl. tax and shipping)
            'products': [{                        // List of productFieldObjects.
                'name': 'Donation - {{dynamic}}', // i.e. donation type monthly or single
                'id': '12345',
                'price': '30.00',
                'brand': Donation',
                'category': 'Donation',
                'variant': 'Mob',           // i.e. Donation site. e.g. Mob, Donation, etc. 
                'quantity': 1
        'donationType': '{{dynamic}}'              //i.e. monthly or single

Could you expand on your question a little? What help do you need?


I want java script that push to data layer in google tag manager. We have a donation form and I want to know how I can get the entered information before sending it to database and send data to google tag manager. any help?

I think I would send the data after it had been submitted / stored, that way you know you’ve actually captured everything, and the page doesn’t have to wait for the JS events to finish before redirecting.

The simplest way is to put your script template into the confirmation page you show on a successful submission and push the submitted data into that.

How have you created the form? If you can post the code for your form handler, controller, etc. then it will be easier to offer some specific suggestions