Skip to content

Commit 3948959

Browse files
authored
adds docs tags to analytics (GoogleCloudPlatform#278)
1 parent caf65b9 commit 3948959

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

appengine/flexible/analytics/app.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
$app->get('/', function (Application $app, Request $request) {
2929
/** @var Twig_Environment $twig */
3030
$twig = $app['twig'];
31+
$trackingId = $app['GA_TRACKING_ID'];
32+
# [START track_event]
3133
$baseUri = 'http://www.google-analytics.com/';
3234
$client = new GuzzleHttp\Client(['base_uri' => $baseUri]);
33-
$form = [
35+
$formData = [
3436
'v' => '1', # API Version.
35-
'tid' => $app['GA_TRACKING_ID'], # Tracking ID / Property ID.
37+
'tid' => $trackingId, # Tracking ID / Property ID.
3638
# Anonymous Client Identifier. Ideally, this should be a UUID that
3739
# is associated with particular user, device, or browser instance.
3840
'cid' => '555',
@@ -42,7 +44,8 @@
4244
'el' => 'Hearts', # Event label.
4345
'ev' => 0, # Event value, must be an integer
4446
];
45-
$response = $client->request('POST', 'collect', ['form_params' => $form]);
47+
$response = $client->request('POST', 'collect', ['form_params' => $formData]);
48+
# [END track_event]
4649
return $twig->render('index.html.twig', [
4750
'base_uri' => $baseUri,
4851
'response_code' => $response->getStatusCode(),
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
runtime: php
22
env: flex
33

4+
# [START env_variables]
45
env_variables:
56
GA_TRACKING_ID: "YOUR-GA-TRACKING-ID"
6-
7+
# [END env_variables]

0 commit comments

Comments
 (0)