jdog
jdog

Reputation: 2549

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?

Upvotes: 9

Views: 11862

Answers (3)

Oni4i
Oni4i

Reputation: 1

The only way I found to implement such case is to send data to Google Analytics and then sync these data with GTM

Upvotes: 0

Edd
Edd

Reputation: 683

Use the Google Analytics Measurement Protocol library for PHP.

Example:

<?php
use TheIconic\Tracking\GoogleAnalytics\Analytics;
$analytics = new Analytics(true);
$analytics
    ->setProtocolVersion('1')
    ->setTrackingId('UA-12345678-90')
    ->setClientId('12345678')
    ->setDocumentPath('/mypage')
    ->setIpOverride("123.123.123.123");

$analytics->sendPageview();

Upvotes: 3

Simo Ahava
Simo Ahava

Reputation: 1446

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.

Upvotes: 7

Related Questions