Happyr / GoogleAnalyticsBundle

The Google Analytics Bundle lets you send data (like event tracking) to Google.
49 stars 15 forks source link

Can't install this bundle in Symfony 4.2 or 4.3 #34

Open walva opened 5 years ago

walva commented 5 years ago

Hi there!

I am very interested in using this bundle for our project but we couldn't achieve to install it and make it work.

So I tried to reproduce our error in a brand new project. Here are the step I followed:

-> didn't work because of the error message:

Could not find resource using any discovery strategy. Find more information at http://docs.php-http.org/en/latest/discovery.html#common-errors

at this point, the kernel is compiling correctly and we created the branch master of our test project

Here is the error I have:

Argument 2 passed to Happyr\GoogleAnalyticsBundle\Http\HttpClient::__construct() must be an instance of Psr\Http\Message\RequestFactoryInterface, instance of Nyholm\Psr7\Factory\HttplugFactory given, called in C:\www\sportfinder\httpclient\var\cache\dev\ContainerIewfoAf\getTrackerService.php on line 14

Because the bundle still wasn't working, I tried to use Symfony HttpClient in the other branch use-symfony-client

Here is the error:

Argument 2 passed to Happyr\GoogleAnalyticsBundle\Http\HttpClient::__construct() must be an instance of Psr\Http\Message\RequestFactoryInterface, instance of Nyholm\Psr7\Factory\HttplugFactory given, called in C:\www\sportfinder\httpclient\var\cache\dev\ContainerD52DYTq\getTrackerService.php on line 14

At this point, I honestly don't know what to do :s I'm here to help with my limited knowledge of php http client ecosystem.

Best regards, Benjamin

jon-ht commented 5 years ago

Hi @SulivanDotEu

I encountered the same problem as you and tested most of your installs. In the end, here is what I've done to fix it :

  1. composer require symfony/http-client (if not already in your dependencies)
  2. psr/http-client is required by this bundle, but you can add it as root dependency
  3. composer require nyholm/psr7
  4. composer require happyr/google-analytics-bundle. Here my setup for the bundle
    happyr_google_analytics:
       tracking_id: '%env(GOOGLE_ANALYTICS_TRACKING_ID)%'
       http_client: 'Psr\Http\Client\ClientInterface'
       http_message_factory: 'nyholm.psr7.psr17_factory'

Symfony autowiring is able to resolve Psr\Http\Client\ClientInterface because, in my case, there is only one implementation.

I also made it work with HTTPlug Bundle by configuring a client and then use

happyr_google_analytics:
    tracking_id: '%env(GOOGLE_ANALYTICS_TRACKING_ID)%'
    http_client: 'httplug.client.happyr_analytics'
    http_message_factory: 'nyholm.psr7.psr17_factory'

And httplug.client.happyr_analytics relies on

httplug:
    # ...
    clients:
        # ...
        happyr_analytics:
            http_methods_client: true

I hope it will help

grekpg commented 4 years ago

I install (Symfony 4.3)

composer require symfony/http-client (if not already in your dependencies) psr/http-client is required by this bundle, but you can add it as root dependency composer require nyholm/psr7 composer require happyr/google-analytics-bundle

and composer require php-http/httplug-bundle

config :

happyr_google_analytics: tracking_id: 11111 http_client: 'httplug.client.happyr_analytics' http_message_factory: 'nyholm.psr7.psr17_factory'

httplug: plugins: retry: retry: 1

discovery:
    client: 'auto'

clients:
    happyr_analytics:
        http_methods_client: true
    app:
        http_methods_client: true
        plugins:
            - 'httplug.plugin.content_length'
            - 'httplug.plugin.redirect'

But still have an error

Argument 1 passed to Happyr\GoogleAnalyticsBundle\Http\HttpClient::__construct() must be an instance of Psr\Http\Client\ClientInterface, instance of Http\Client\Common\HttpMethodsClient given,

ok I change

happyr_google_analytics: tracking_id: UA-1634831-41 http_client: 'Psr\Http\Client\ClientInterface' http_message_factory: 'nyholm.psr7.psr17_factory'

now it work. installing this bundle is very complicated