Google AdWords Integration

  • Posts: 151
  • Thank you received: 4
  • Hikashop Business
5 months 2 weeks ago #326377

-- HikaShop version -- : 4.2.1
-- Joomla version -- : 3.9.20
-- PHP version -- : 7.3

Hi, I'm struggling to find a working solution to this both in your documentation and on the forum. I've recently signed up to google ads and I'd like to track the number of conversions (sales).

I've edited the file after_end.php with the following code (ads account changed) as advised on google ads;

<!-- Global site tag (gtag.js) - Google Ads: 10233xxxx -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-10233xxxx"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'AW-102334xxxx');
</script>
<!-- Event snippet for Sales conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-102334xxxx/8io-COii1OgBEPn7--cD',
      'value': '<?php echo $this->order->order_full_price;?>',
      'currency': 'GBP',
      'transaction_id': ''
  });
</script>

Plenty of sales have gone through but Google Ads is still seeing as unverified (which means it's not working).

a) Am I adding it to the correct file in Hikashop?
and b) what does the plugin - HikaShop Google Dynamic Remarketing (conversion tracking) actually do?



Thanks

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 72763
  • Thank you received: 11096
  • MODERATOR
5 months 2 weeks ago #326463

Hi,

1. It depends on the payment method you're using. It could have to be done in the "end.php" view file for some payment methods like authorize.net in AIM mode.
However, in the large majority of payment methods, it's indeed after_end.php where you want to add your code.

2. This plugin allows to link the adwords and the display of product details pages:
support.google.com/google-ads/answer/2476688?hl=en
It's different than linking sales to adwords like you're trying to do.

3. You have two problems with your code:
- You need to round the order_full_price to two decimals. So
<?php echo $this->order->order_full_price;?>
should be:
<?php echo round($this->order->order_full_price,2);?>
- You need to add the order id ion the transaction_id parameter:
<?php echo $this->order->order_id; ?>

Please Log in or Create an account to join the conversation.

  • Posts: 151
  • Thank you received: 4
  • Hikashop Business
5 months 2 weeks ago #326473

Thanks Nicolas.

I've updated the code and will await an order to see if it's tracked.

Thanks again.

Please Log in or Create an account to join the conversation.

  • Posts: 151
  • Thank you received: 4
  • Hikashop Business
5 months 3 days ago #327153

OK, I've updated after_end.php page as follows

<head>
<!-- Event snippet for Sales conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-10xxxx21/8io-COii1Ogxxxn7--cD',
      'value': '<?php echo round($this->order->order_full_price,2);?>',
      'currency': 'GBP',
      'transaction_id': '<?php echo $this->order->order_id; ?>'
  });
</script>
</head>
But I'm still not seeing it marked as verified on google ads?

I have the conversion tracking global js added to all pages via the template I'm using and can see that ok too.

Please Log in or Create an account to join the conversation.

  • Posts: 72763
  • Thank you received: 11096
  • MODERATOR
5 months 2 days ago #327155

Hi,

As I said before, the file to edit might be different based on the payment method you're using and how you configured it.
Which payment method are you using for your tests ? And how did you configure it ?
Also, you need to make sure that the gtag function is defined by the script from GA on the page where you're adding that code. Otherwise, it will result in a javascript error.

Please Log in or Create an account to join the conversation.

  • Posts: 151
  • Thank you received: 4
  • Hikashop Business
5 months 1 day ago #327299

Hi Nicolas, we're using the default Hikashop credit card payment plugin (offline processing mode).

What do you mean by "the gtag function is defined by the script from GA on the page where you're adding that code"?

Please Log in or Create an account to join the conversation.

  • Posts: 72763
  • Thank you received: 11096
  • MODERATOR
5 months 16 hours ago #327323

Hi,

1. With that payment method, there is no redirection to a payment gateway and then the payment gateway redirects back to the "after_end" view file.
Instead, the thank you page is directly displayed by the "end" view file.
So yes, you're actually not editing the correct view file for your payment method.

2. In your javascript code, you have a call to the gtag function. That's a function defined by the GA javascript file. So that javascript file needs to be included on the page where the call to the gtag function is done, or it will result in a javascript error.
For example, check:
developers.google.com/analytics/devguides/collection/gtagjs
You can see there in the example code that on top of having the javascript call to the gtag function, there is the line:
<script async src=" www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID "></script>
which actually defines the gtag function.
If you don't have that line in the current page, then your javascript code won't work.

Please Log in or Create an account to join the conversation.

  • Posts: 151
  • Thank you received: 4
  • Hikashop Business
4 months 2 weeks ago #327789

Ok, it took a while for google to start tracking conversions but it is now working great. Might be worth trying to integrate this better with a plugin or something as it's not straightforward and you really need to understand the effectiveness of paying google $$ every Month.

Hope this helps someone else.

Thanks for your help with this Nicolas.

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.079 seconds
Powered by Kunena Forum