AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

3.8K members online now
3.8K members online now
Learn how to set up goals and Ecommerce tracking, verify accuracy of attribution traffic sources, and discuss funnel visualization, Multi-Channel Funnels, the Goal Flow Report, and Enhanced Ecommerce
Guide Me

How to fire a "pageview" event without webpage

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi, I am trying to meter an app API usage using google analytics. In the server API code (php), I am trying to trigger an event like  ga('send', 'pageview');

but there is not webpage based, can't run client side javascript. Anyway we can get this implemented?

Such that when the event was triggered, google analytics will log that in the "customer dimension" part?



1 Expert replyverified_user

Re: How to fire a "pageview" event without webpage

Top Contributor
# 2
Top Contributor
You need to use the Measurement Protocol, which is a developer tool:
Mike Sullivan, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here.

Re: How to fire a "pageview" event without webpage

Follower ✭ ☆ ☆
# 3
Follower ✭ ☆ ☆
Sample PHP Code
$fields = array(
'payload_data' => '',
'v' => 1,
'tid' => $tid,
'cid' => $cid,
't' => "event",
'ec' => $ecategory,
'ea' => $eaction,
'el' => $elabel,
'ev' => $evalue);
$push = curl_call("", $params, $user_agent);

function curl_call($url, $param, $user_agent)
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/var/www/webserv/tmp/cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/var/www/webserv/tmp/cookies.txt");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, $url . $param);

$output = curl_exec($ch);

$info = curl_getinfo($ch);
//$_SESSION["curl_info"] = $info;
return $info;