Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 465
jdog Avatar asked Jun 12 '15 10:06

jdog


2 Answers

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.

like image 112
Simo Ahava Avatar answered Nov 15 '22 21:11

Simo Ahava


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();
like image 36
Edd Avatar answered Nov 15 '22 20:11

Edd