nystudio107 / craft-instantanalytics-ga4

Instant Analytics brings full Google GA4 server-side analytics support to your Twig templates and automatic Craft Commerce integration
Other
3 stars 4 forks source link

instantAnalytics.setApiSecret('xyz') doesn't update API secret #16

Closed mikeymeister closed 1 year ago

mikeymeister commented 1 year ago

When following the example from the docs below:

{% do instantAnalytics.setMeasurementId("G-7DDE6SKB8E") %}
{% do instantAnalytics.setApiSecret('xyz') %}

The api secret is not updated.

Looks like the following is missing from nystudio107\instantanalyticsGa4\ga4\Analytics::setApiSecret on (approx) line 262.

$service->setApiSecret($apiSecret);

Version: 3.0.0-beta.2

khalwat commented 1 year ago

So I tried replicating this... here are my plugin settings:

Screenshot 2023-08-13 at 16 23 12

...and here's the Twig code:

    {% do instantAnalytics.setMeasurementId("G-7DDE6SKB8E") %}
    {% do instantAnalytics.setApiSecret('xyz') %}
    {% dd instantAnalytics %}

Which outputs:

Screenshot 2023-08-13 at 16 24 42

...so it is changing both properties. Is there something I'm missing here?

mikeymeister commented 1 year ago

I've upgraded to the latest v3 version as I was one behind, just to be sure but am still getting the same results. If I follow your example:

Settings: analytics-settings

Template:

{% do instantAnalytics.setMeasurementId("replacement-key") %}
{% do instantAnalytics.setApiSecret("replacement-secret") %}
{% dd instantAnalytics %}

Result: analytics-dump

My suggestion about the code was just noticing a difference between how the setMeasurementId() and setApiSecret functions were different.

/**
     * Set the measurement id.
     *
     * @param string $measurementId
     * @return $this
     */
    public function setMeasurementId(string $measurementId): self
    {
        $service = $this->service();

        if (!$service) {
            throw new InvalidConfigException('instant-analytics-ga4', 'Unable to create GA4 service object');
        }

        $service->setMeasurementId($measurementId);
        return $this;
    }

    /**
     * Set the API secret.
     *
     * @param string $apiSecret
     * @return $this
     */
    public function setApiSecret(string $apiSecret): self
    {
        $service = $this->service();

        if (!$service) {
            throw new InvalidConfigException('instant-analytics-ga4', 'Unable to create GA4 service object');
        }

        return $this;
    }

Maybe I am missing something? Happy to provide any more info, and really appreciate your help with this.

khalwat commented 1 year ago

Ah I think this is specific to the v3 version, it's an oversight. Thanks for the report!

khalwat commented 1 year ago

Addressed in: https://github.com/nystudio107/craft-instantanalytics-ga4/commit/ab4faa9b1da40cc5fa227fd09eef20281a95dd0f