Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing CPA affiliate purchases in GTM enhanced ecommerce

I'm implementing Enhanced Ecommerce on our (mainly affiliate) website through GTM. We have list views and detail views etc.. so implementing impressions and clicks is easy, but for affiliate purchases there is a problem.

We have two payment models for the shops that are showing their products on our site:

  • Cost per Click. I can implement a small purchase on the clickout page.
  • Cost per Acquisition. Here is the problem: The purchases are made on a different website on a different time. Using PHP API's I get the purchases made a few times a day through a cronjob.

How can I create a purchase (preferably using PHP, using javascript is messy on a cronjob) but retain the cookie value so I can link the purchase to the clickout and channel people used to get on our site.

I thought of creating all zero purchases for each clickout and maybe repurchase using the same transaction ID. This might work, but we will end up with thousands of empty purchases.

like image 461
Hans Wassink Avatar asked Nov 28 '16 08:11

Hans Wassink


1 Answers

I ran across a similar problem a while back. Our checkout lives on a different domain. So when Adwords people would checkout after migrating to Universal, I was losing that data at checkout. I think my solution there could help you. This all assumed you're using Universal Analytics and not the old deprecated libraries.

The first thing I do is grab the GA cookie, which is named _ga. Inside it is your GA session. It looks like this (it will be much longer)

GA1.2.3456.7890

The third and fourth number sets (including the period) are the session itself. Parse them out.

Now you want to find some way to store this with the user. I used my PHP session (we pass it in the query string when we jump domains) and stored it there. You'll have to figure something out that works for you here.

On the other site we need to specify the GA session and site within the GA block. Please note that the new site will report these visits as if they belonged to the original site. The UA-XXXX-Y should be from the original site and yourdomain.com should be the new site TLD

ga('create', 'UA-XXXX-Y', { 'cookieDomain': 'yourdomain.com', 'clientId': '3456.7890' });

Now you can pass your purchase metrics in. When a session converts on the new site, the old site will track it, along with any other things that session held (i.e. page impressions, Adwords clicks, etc.). You don't need any messy cron jobs to do this. Just be aware, as I said earlier, that these page visits belong to the original site as far as GA goes. You could try reporting two sets of metrics to get around this, but I have not tried that.

like image 110
Machavity Avatar answered Oct 13 '22 01:10

Machavity