Search code examples
phpgoogle-tag-manager

Equivalent of dataLayer.push in Google Tag Manager PHP API


I need to record virtual Page Events with the Google Tag Manager PHP API.

So far I have this code:

    $client = new Google_Client();
    $client->setApplicationName("Partner Inquiry");
    $client->setDeveloperKey("xxxxxxxx");

    $service = new Google_Service_TagManager($client);

    $eventName = new Google_Service_TagManager_Parameter();
    $eventName->setList( array(
        'event' => 'VirtualPageview',
        'virtualPageURL' => '/partnerInquiry/partnerName',
        'virtualPageTitle' => 'Partner Inquiry - Partner Name'
    ));

What do I call now.

My IDE autocompletion finds

    $service->accounts

but how do I fire the event collection?


Solution

  • There is no server-to-server tracking with GTM. Even in mobile GTM, the container is first downloaded, and then interacted with as a local resource.

    Google Tag Manager for the web is a JavaScript injector, which adds custom code into the document object model of a web page. Thus it has no tracking or data collection capabilities of its own. That's one of the major benefits: you are not reliant on Google's services other than the initial library download. Everything else takes place in the client's browser.