setono/sylius-google-ads-plugin

Google Ads plugin for Sylius.

Installs: 3 746

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 1

Type:symfony-bundle

v1.0.0-alpha.4 2021-01-27 09:13 UTC

README

Latest Version Latest Unstable Version Software License Build Status

This plugin tracks conversions in your Sylius store. It's done with offline conversion tracking instead of the default javascript tracking. It has a few benefits to do this:

  • Easier to control the consent status for a given user
  • Easier to change the value of a given order after the fact
  • No javascripts on your page to track Google Ads, which means faster page load

Installation

Step 1: Install and enable plugin

$ composer require setono/sylius-google-ads-plugin

Add the bundle to your config/bundles.php before the SyliusGridBundle:

<?php
# config/bundles.php

return [
    // ...
    
    Setono\SyliusGoogleAdsPlugin\SetonoSyliusGoogleAdsPlugin::class => ['all' => true], // Added before the grid bundle
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
    
    // ...
];

Step 2: Add configuration

# config/packages/setono_sylius_google_ads.yaml
imports:
    - "@SetonoSyliusGoogleAdsPlugin/Resources/config/app/config.yaml"
# config/routes/setono_sylius_google_ads.yaml
setono_sylius_google_ads:
    resource: "@SetonoSyliusGoogleAdsPlugin/Resources/config/routes.yaml"

That's it!

Usage

Offline conversion tracking works like this:

  1. We collect the gclid query parameter when a user enters the store from clicking on an ad. We save this value in a cookie.
  2. When the same user completes a purchase, we will insert a new row into our conversion table.
  3. We then expose these conversions as CSV data on a URL that you grab in the backend. This URL is then used when setting up the conversion action inside the Google Ads interface.

Step 1: Set up a new conversion action in Sylius

  1. Go to /admin/conversion-actions/new and create a new conversion action. There's a help text on the right explaining how to do it.

  2. When you have created your conversion, you go to the conversion action index (/admin/conversion-actions/) where you find the URL you need to give to Google. It will look something like: https://your-domain.com/en_US/google-ads/conversions/af5717388cb5a610b92c9da43914384cfa8a491e5999e4e9c4e9e0b32204b0dc

Step 2: Set up a matching conversion action in Google Ads

  1. Create a new conversion action inside the Google Ads interface.
  2. Name it the same as you did in Sylius. This is important since Google matches the name.
  3. Create a new upload of conversions. See the image below:

Upload conversions

Advanced usage

Conversions have a state property, which is ready by default. This means that purchase conversions will be downloaded by Google when a customer has completed an order. This is not always the intended behavior. Some times it's more likely that the conversion should first be counted when the order is paid. To fix this, edit the configuration:

# config/packages/setono_sylius_google_ads.yaml
setono_sylius_google_ads:
    default_conversion_states:
        purchase: !php/const Setono\SyliusGoogleAdsPlugin\Model\ConversionInterface::STATE_PENDING

and run this command periodically:

$ php bin/console setono:sylius-google-ads:process-pending-conversions