Equivalent of dataLayer.push in Google Tag Manager PHP API
Asked Answered
L

3

9

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?

Legatee answered 12/6, 2015 at 10:44 Comment(2)
Are you sure that is at all possible ? When I look at the API docs I only see functions to set up and manage a GTM container - I don't see any method to send data from a website to a container, which seems to be what you are looking for.Une
No actually I'm not. I sort of assumed this would be the main benefit of it: to enable backend based trackingLegatee
A
7

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.

Avelar answered 27/10, 2015 at 7:10 Comment(0)
D
3

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();
Didynamous answered 30/11, 2017 at 11:9 Comment(0)
C
0

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

Chiquitachirico answered 23/8 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.