Issue with third party Google Analytics sdk - php

I have code which works above the php 5
its actually GA Library, here is its github project.
I have cloned the project theiconic/php-ga-measurement-protocol
Since I am new to PHP, I have no idea where to put this code, Please help me here this project should be installed via composer via code
{
"require": {
"theiconic/php-ga-measurement-protocol": "^2.0"
}
}
After this step I need to create a file something.php and I need to put the code below, I am having problem on locating autoload.php on my server, Please look at the code below to understand what i am saying.
<?php
//grab the data that Calendly sent in the webhook and store it in a variable called $objCalendlySubmission...
$objCalendlySubmission = json_decode(file_get_contents('php://input'));
//We've passed the Google client_id in Calendly's placeholder for utm_term. Feel free to pass it differently, this is just an example
if(property_exists($objCalendlySubmission->payload->tracking, 'utm_term') && !empty($objCalendlySubmission->payload->tracking->utm_term)) {
$strPageViewed = 'calendly_conversion.html'; // We use different page names depending on what type of event was scheduled via Calendly
sendGoogleAnalyticsPageView($objCalendlySubmission->payload->tracking->utm_term, $strPageViewed);
}
function sendGoogleAnalyticsPageView($strGAClientId, $strURL) {
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol” **I dont know where is it located exactly on my xampp server, Please guide me here**
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup **please help me here**
$analytics
->setProtocolVersion('1')
->setTrackingId('YOUR-GA-UA-ID-GOES-HERE')
->setClientId($strGAClientId)
->setDocumentLocationUrl($strURL);
$analytics->sendPageview();
}
?>
In the above code towards middle line
require_once '/path_to_composer/composer/vendor/autoload.php'; //loads the PHP library for the "Google Analytics Measurement Protocol”
I dont know where is it located exactly on my xampp server, Please guide me here
$analytics = new TheIconic\Tracking\GoogleAnalytics\Analytics(true); //you may have to adjust this path based on your setup
Here is the image of Project folder
Project structure Part 2

Related

GCE Secret Manager display test secret via php application

I am new to Secret manager and I am trying to display a test secret using a php app.
All I get when the app is deployed is an error 500.
I gave my xxxx#appspot.gserviceaccount.com service account the required role according to gcp documentation (Secret Manager Secret Accessor + Storage Object Admin)
I also installed composer from the cloud shell so I really cannnot spot what I am doing the wrong way.
This is my composer.json
{
"require-dev": {
"paragonie/random_compat": "^9.0.0"
},
"require": {
"google/cloud-secret-manager": "^1.2"
}
}
this is how my code looks like:
<?php
use Google\Cloud\SecretManager\V1\SecretManagerServiceClient;
$projectId = 'myproject';
$secretId = 'mysecret';
$versionId = '1';
$client = new SecretManagerServiceClient();
$name = $client->secretVersionName($projectId, $secretId, $versionId);
$response = $client->accessSecretVersion($name);
$payload = $response->getPayload()->getData();
printf('Plaintext: %s', $payload);
?>
Thank you for your help...I don't know what to try anymore :-(
Ok, so I managed to make this work. As a typical noob I made a lot of nonsense ^^ so long story short:
First I have (had?) a bad habit to build my app from the google shell (not sdk). Nothing wrong with that I guess (except it is actually less convenient) but in this usecase you need to link a json file containing access key to your GOOGLE_APPLICATION_CREDENTIALS environnment variable so it will have the right to query secret manager.I did not know how to do that without the sdk. So once the app deployed using the sdk and the json file properly assigned, it was better. Then I had an autoload.php error I managed to fix using this article in french : https://www.journaldunet.fr/web-tech/developpement/1441107-comment-corriger-l-erreur-require-vendor-autoload-php-failed-to-open-stream/
Thank you guys for trying to help me. I learnt one or two interresting things with this issue....Everyday is a school day ^^

Prestashop 1.7 using Import csv function programmatically

I state that I'm not familiar with Prestashop and I'm using version 1.7.6.
I'm trying to understand how I could use the import function from csv file without using of user interface.
I tried to look for documentation on a possible web api but I found nothing.
What I'd like to accomplish is the following scenario:
I have two web applications on the same server
/my_webapp
/my_prestashop
By "my_webapp" I receive a csv file, process it and produce a new csv file.
Now continuing running the process in "my_webapp", I would like to instantiate the ambient of the prestashop application to invoke the import csv function by passing it the new file just created.
Searching the web I found some sample code but, trying to use and adapt it, I am not making it work.
For example, on “my_webapp” folder I just create a “myimport.php” file and call it with two GET parameters.
The following is the call:
localhost/my_webapp/myimport.php?csv=prod.csv&limit=5
note: the file “prod.csv” is on
"path to admin folder"/import
Content of “myimport.php” file:
<?php
$rootPrestashop = '/var/www/html/my_prestashop”;
define('_PS_ADMIN_DIR_', $rootPrestashop.'/admin_shop'); //not sure if this instruction is needed
$pathConfig = $rootPrestashop.'/config/config.inc.php';
$initConfig = $rootPrestashop.'/init.php';
require_once($pathConfig);
require_once($initConfig); //this line throw an error and then I can't test the others!
$importCtrl = new AdminImportControllerCore();
$crossSteps = array();
$limit = $_GET["limit"];
$importCtrl->productImport(false, $limit, $crossSteps, true, 0);
This is what I’m trying to do, but I failed to initialize the environment.
Maybe I’m on the wrong way and there’s a better way.
I ask if anyone can help me understand if I can carry out this process and what would be the correct way.Thanks in advance
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', __DIR__);
}
include _PS_ADMIN_DIR_.'/../config/config.inc.php';
if (!Context::getContext()->employee->isLoggedBack()) {
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminLogin'));
}

How to use Httpful PHP Library

I'm trying to learn REST, and thought it might be good to start with a PHP REST client such as Httpful. I just can't seem to get it to work. I downloaded the httpful.phar file and placed it in my working directory. Then created a simple php file with the following contents from an example on the their site:
<?php
// Point to where you downloaded the phar
include('httpful.phar');
$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = Request::get($uri)->send();
echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
?>
I've tried multiple examples on the site, but only get a blank page when I load it in my browser.
Thanks for any help you can give!
This library uses Namespaces. Either use a complete classname or use the class
With a complete Classname:
\Httpful\Request::get($uri)->send();
With a use:
use Httpful\Request;
Request::get($uri)->send();
The sample code sadly is very incomplete on the website, but you can get the hint from sample below topic "INSTALL OPTION 1: PHAR" or from the actual source code inside the phar.
http://phphttpclient.com/

YouTubePartner.php not found

Our main goal is to upload audio references to match and automatically claim videos in Youtube. We work ok PHP.
We’re following this example:
[Uploading a new reference, so YouTube can automatically generate claims for newly uploaded videos on behalf of the asset's owner]
https://developers.google.com/youtube/partner/code_samples/php#uploading_a_new_reference__so_youtube_can_automatically_generate_claims_for_newly_uploaded_videos_on_behalf_of_the_asset_s_owner
(second half of the doc):
// Call set_include_path() as needed to point to your client library.
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
require_once 'Google/Service/YouTubePartner.php'; // <--- This file doesn't exist!
session_start();
We got it through the old API (Google API PHP Client 0.6.7) and the "Google_YouTubePartnerService.php" file we found here: https://developers.google.com/youtube/partner/client_libraries , but this isn’t useful because we need "Service account" authentication, and the API doesn’t work with this.
So, we tried with Google API PHP Client 1.0.0 unsuccessfully. We get the authentication but we need to find this file Google/Service/YouTubePartner.php called by the example on the URL mentioned above: https://developers.google.com/youtube/partner/code_samples/php#uploading_a_new_reference__so_youtube_can_automatically_generate_claims_for_newly_uploaded_videos_on_behalf_of_the_asset_s_owner
Thanks for your help!
Looks like Content ID PHP library wasn't updated for 1.0 version on the site.
Just got it updated. Thanks for the warning. https://developers.google.com/youtube/partner/clientlib/Google-youtubePartner-v1-20140110-php-1.0.0-alpha.zip

Tumblr API in PHP File structure

I'm trying to use the Tumblr API (PHP) and I cant seem to get all the required files to load correctly.
The Tumblr API can be found here: https://github.com/tumblr/tumblr.php
First thing I found out is that it doesnt include OAuth, so after some searching I found the files on github and uploaded them to my server.
Now it's saying it needs Guzzle. OK, got that uploaded now, but I cant seem to get all the Guzzle files to load up... Example error message:
Interface 'Guzzle\Common\HasDispatcherInterface' not found in /TumblrTest/Guzzle/Common/AbstractHasDispatcher.php
There's a HasDispatcherInterface.php file in that path...
Do the files need to be in a special order? I tried putting all .php files into a folder, and then using require_once I searched for all *.php files in that folder, but that didnt work...
Sorry for a super noob question, any help would be greatly appriciated! Let me know if there's any other info i need to give to help answer this question!
-D
UPDATE: I still have no idea how the above works, but I found a way around it... I actually think it might be easier then figuring the above out!! The following PHP code does what i need it to do, which is grab the posts of the provided user:
$apikey = **[insert api key here]**;
$limit = $_POST['limit'];
$user = $_POST['user'];
$tumblr=$user . ".tumblr.com";
$apidata = json_decode(file_get_contents("http://api.tumblr.com/v2/blog/$tumblr/posts/photo?api_key=$apikey&limit=$limit"));
$mypostsdata = $apidata->response->posts;
$myposts = array();
$j = 0;
foreach($mypostsdata as $postdata) {
$post["photo_url"] = $postdata->photos[0]->original_size->url;
$post["width"] = $postdata->photos[0]->original_size->width;
$post["height"] = $postdata->photos[0]->original_size->height;
$myposts[$j] = $post;
$j++;
}
echo json_encode($myposts);
For some reason I cant get it to pull a list of people i'm following and then get their posts, but oh well...
The tumblr.php Readme might be a bit confusing.
The package depends on other packages. All can be installed via composer.
Go to the http://getcomposer.org and read this carfully, if you are used to the concept, you will start rewriting all you classes to fit the composer dependency manager ;-)
to make it short:
install composer globally and
go into a blank directory and
type in your terminal
composer require tumblr/tumblr
you should get all the classes and the other projects in a dir called vendor.
before you do anything you need to require the autoload.php file.
And check out the concept of namespaces in php.

Categories