• robertrosanke

    (@robertrosanke)


    Hello,
    we have changed our setup to server side tagging.

    If we process the conversion and remarketing tags via the server container, then conversion/remarketing tracking will not work. E.g. for the “purchase” event.

    The problem is that GTM4WP fires the “purchase” event directly when the page is accessed.


    However, the Tag Manager does not need to be fully loaded at this point.
    With a classic tag manager setup, this is not a problem.
    However, this doesn’t work with server side tagging.

    The GTM container must be loaded when the “purchase” event is sent.
    Then it works.

    As a solution we tried the following approach.
    It works for us.

    // duracelltomi-google-tag-manager/public/frontend.php, ~ line 1254:
    
    
    $js_script_inline= "document.addEventListener('wfa-google-tag-manager/page-view', (e) => {
      $datalayer_push_code
    }, {once: true});";
    		
    
    wp_add_inline_script( 'gtm4wp-additional-datalayer-pushes', $js_script_inline, 'after' );

    “wfa-google-tag-manager/page-view” is a custom event that we fire via custom HTML Snippet when GTM is ready. And GTM4WP’s inline frontend JS code will only be executed when our GTM container is ready.

    If GTM4WP listens to this event and only then fires the “purchase” event, then server side conversion tracking works.

    It would be good if GTM4WP had a plugin option where you could store a JS event name. If filled in, then wait for this event before sending events.

    add_action('wp_head', function(){
    ?>
    <script>document.addEventListener('<?php echo esc_js( $plguin_settings["event_name"] ); ?>', ()=> gtm4wp_woocommerce_process_inline_js_events(), {once:true});</script>
    <?php
    }, 1);

    gtm4wp_woocommerce_process_inline_js_events() calls the inline script loaded at the end of body tag.

    Something like that. It’s just a rough draft now.

    What do you think about it?

    Maybe all tracking-relevant scripts should simply wait until the event has taken place. Use data-src instead of src for GTM4WP scripts. When the event occurs, set src and all scripts will be executed + the associated events will be sent to the GTM container. Would probably be functional too?!

Viewing 1 replies (of 1 total)
  • Thread Starter robertrosanke

    (@robertrosanke)

    Important: The problem here only exists if events are processed on the server side tagging container. If you don’t use SST, you shouldn’t have any problems in this regard.

Viewing 1 replies (of 1 total)
  • The topic ‘Add plugin option: Improve conversion tracking with server side tagging’ is closed to new replies.