As previously announced via banners and our newsletters, support is no longer available through this platform.

For easier navigation, you can still click on "Submit a Ticket" here, choose the appropriate category, and you'll be redirected to the correct support channel for your plugin.

You can still access your previous tickets and browse public tickets, but please note that responding to tickets is no longer possible.

Paid customers: Please log in to your store account for support.

Pre-purchase questions: Use the support widget in the bottom-right corner of our websites:
https://wpamelia.com
https://wpdatatables.com
https://wpreportbuilder.com

Okay
  Public Ticket #3656242
GTM Tracking & Redirect After Booking
Closed

Comments

  • Ivan started the conversation

    Sharing some code which helps me to trigger a re-direct and custom event in GTM after a successful booking.

    Hope it helps someone and please let me know if you see any issues in the coding.

    Thanks!

    +++

    window.ameliaActions = {
        beforeBooking: function (success = null, error = null, data) {
    //     console.log('Before booking is created HOOK');
    //     console.log(data);
    //     console.log('------------');

    // Determine GTM event name based on Amelia Service name and redirect URL based on the name
            const name = data.componentProps.bookable.name;
            let gtmEventName = '';
            let redirectUrl = '';

            if (name === 'Coaching Call - Individual') {
                gtmEventName = 'bookingCompletedIndividual';
                redirectUrl = '/thank-you-individual';
            } else if (name === 'Coaching Call - Group') {
                gtmEventName = 'bookingCompletedGroup';
                redirectUrl = '/thank-you-group';
            }

    // Trigger custom event for GTM with debugging
            if (window.dataLayer && gtmEventName) {
                console.log(`Pushing event to GTM: ${gtmEventName}`);
                window.dataLayer.push({
                    event: gtmEventName,
                    bookingData: data
                });
            } else {
                console.error('GTM event not pushed: dataLayer or gtmEventName is missing');
            }

    // Redirect if URL is determined
            if (redirectUrl) {
    // Call success callback for the booking to be completed
                success();
                window.location.href = redirectUrl;
            } else {
    // Call success callback for the booking to be completed
                success();
            }
        }
    }

  •  1,718
    Uroš replied

    Hello Ivan,

    Thank you very much for sharing that with other people.

    Hope that this will be useful for a lot of Amelia users.

    Kind Regards, 

    Uros Jovanovic
    [email protected]

    Rate my support

    Try our FREE mapping plugin! MapSVG - easy Google maps, interactive SVG maps, and floor plans, choropleth maps and much more - https://wordpress.org/plugins/mapsvg-lite-interactive-vector-maps/

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables