Posts tagged with php

I have some google ads running on a Wordpress site running WooCommerce and I've added the global site tag to the header.php of my child theme which also has a google analytics tag, so the tag just looks like this in the header

<!-- global site tag (gtag.js) - google analytics --> <script async src="https://www.googletagmanager.com/gtag/YADDA YADDDA></script> <script>    window.datalayer = window.dataLayer || [];    ...    ...    gtag('config', 'ANALYTICS TAG ID');    gtag('config', 'AD TAG ID'); </script>

This all works good, but now I have to add the event snippet on the conversion page which for WooCommerce is the thankyou.php in the WooCommerce/templates/checkout/ folder I believe. Google specifies this to be placed in the header of that specific page. Should I be adding a function to my functions.php - of my child theme - that hooks into thankyou page and the header? or directly place it into the thankyou.php hook file - of child theme - to overwrite it? Then it is also asking to add code to dynamically pass a value to the transaction_id parameter and value and currency parameters. Event snippet below. I'm confused on how to do this and my last few attempts have ended with a site error.

<!-- Event snippet for DB_Purchase conversion page --> <script> gtag('event', 'conversion', { 'send_to': 'AW-5555555/5555555', 'value': 45.0, 'currency': 'USD', 'transaction_id': ''}); </script> 

placeholder tag used.

I am using:

https://developers.google.com/analytics/devguides/collection/protocol/v1/

for server side tracking.

This is the set-up:

  • Google analytics account.
  • Google adwords account.
  • Adwords account is linked to the analytics account.

I create an ad in adwords, the user clicks the ads, the user visits the third party website, the third party website make a https POST request with the visitor gclid from adwords. This is stored in a mysql database.

In the google adwords account I have an event for conversion created. (Using the offline tracking conversion works, but the only reason why I would prefer to use measurement protocol is because the offline tracking only accepts the conversions after 90 minutes. )

And I send the page views and conversion in this way:

/**  * @param $gclid  * @param $clientId  * @return \TheIconic\Tracking\GoogleAnalytics\AnalyticsResponse  */ private function sendPageView($gclid, $clientId){     $this->analytics         ->setProtocolVersion(1)         ->setTrackingId(self::GLOBAL_TRACKING_ID)         ->setGoogleAdwordsId($gclid)         ->setAnonymizeIp(true)         ->setClientId($clientId);     return $this->analytics->sendPageview(); } /**  * @param $gclid  * @param $clientId  * @return \TheIconic\Tracking\GoogleAnalytics\AnalyticsResponse  */ private function sendConversion($gclid, $clientId, $url){     $this->analytics         ->setProtocolVersion(1)         ->setTrackingId(self::GLOBAL_TRACKING_ID)         ->setGoogleAdwordsId($gclid)         ->setAnonymizeIp(true)         ->setClientId($clientId)         ->setEventAction('s2s')         ->setEventCategory('Lead')         ;     return $this->analytics->sendEvent(); } 

Response:

object(TheIconic\Tracking\GoogleAnalytics\AnalyticsResponse)#1008 (3) {   ["httpStatusCode":protected]=>   int(200)   ["requestUrl":protected]=>   string(164) "https://ssl.google-analytics.com/collect?v=1&tid=UA-1XXXXX-1&gclid=EAIaIQobChMInvrxopLZ5gIVXXXXXXXXXXXXXXXXXXXX_BwE&aip=1&cid=1&ea=s2s&ec=Lead&t=event"   ["responseBody":protected]=>   string(35) "GIF89a�����,D;" } 

So the response is 200, however the conversion is not recorded anywhere, and I am not sure if I should be sending any other parameter, or how to debug the issue.

I want to get Traffic estimation for some keywords via Google Adwords api.

So I'm using the api : https://developers.google.com/adwords/api/docs/guides/traffic-estimator-service

Here there's a option to set maximum amount for CPC per day :

$money = new Money(); $money->setMicroAmount(5000000); $adGroupEstimateRequest->setMaxCpc($money); /* Here they're setting Max cpc value per day */ 

But i want to Set Maximum daily budget for the keyword. Anyways to make it possible please share your ideas.

I am using the Google Oauth2 API to connect to Google Ads and become only one refresh token when my @gmail.com account has read access to two different Google Ads accounts.

I have the account a@gmail.com. This account has read access to the Google Ads accounts b@gmail.com and c@gmnail.com.

When I create two connections to Google Ads with the email a@gmail.com for the accounts b@gmail.com and c@gmail.com, then I receive only one refresh token, for the first connection and none refresh token for the second connection. Why? How can I manage this, to become 2 refresh tokens for each connection? The only way to become a refresh token for the second connection is to go to my account a@gmail.com and to decline the access to my app manually and connect again with c@gmail.com. But then b@gmail.com has no refresh token anymore.

code:

$oauth2 = new OAuth2(             [                 'authorizationUri' => $this->container->getParameter('oauth2.google.adwords.authorizationUri'),                 'tokenCredentialUri' => $this->container->getParameter('oauth2.google.adwords.tokenCredentialUri'),                 'redirectUri' => $this->container->getParameter('domain.system') . $this->container->getParameter(                         'oauth2.google.adwords.redirectUri.advertiser'                     ),                 'clientId' => $this->container->getParameter('oauth2.google.adwords.clientId'),                 'clientSecret' => $this->container->getParameter('oauth2.google.adwords.clientSecret'),                 'scope' => $this->container->getParameter('oauth2.google.adwords.scope')             ]         ); // Create a 'state' token to prevent request forgery.             // Store it in the session for later validation.             $randomState = sha1(openssl_random_pseudo_bytes(1024)) . '---' . $accountId;             $oauth2->setState($randomState);             // Redirect the user to the authorization URL.             $config = [                 // Set to 'offline' if you require offline access.                 'access_type' => 'offline',                 'approval_prompt' => 'force'             ];             // redirect to google ads             return new RedirectResponse($oauth2->buildFullAuthorizationUri($config));