1

I have created an affiliate marketing website. Here users will register on my website and shop, however the shopping link will be of amazon.

I need to know how to set up Google Analytics so that it can track which registered user has clicked an affiliate link on my website.

For example I have this amazon link https://www.amazon.in/BassHeads-225-Super-Extra-Headphones/dp/B01M9C51T9/ref=sr_1_1?_encoding=UTF8&pf_rd_i=desktop&pf_rd_m=A1VBAL9TL5WCBF&pf_rd_p=14ffe21a-e5a2-45c9-a9c0-91f47b082bbc&pf_rd_r=94G5Y8CM93G8M5Y2SNS3&pf_rd_t=36701&qid=1554008093&s=gateway&smid=A14CZOWI0VEHLG&sr=8-1

I know I'm supposed to put an onClick event on there somewhere but I don't have any idea how it links to Google Analytics? I am using Google Tag Manager

Is this the correct Onclick code:

onClick="_gaq.push(['_trackEvent', 'Link', 'Click', 'Banner Advert1']);"

If not what do I need to add to track the registered user?

makrand patne
  • 15
  • 1
  • 5
  • Welcome! In order to help others answer, please provide further details about your issue, that you are trying to solve. Explain how you encountered the problem you're trying to solve, and any difficulties that have prevented you from solving it yourself. For further details, please check https://stackoverflow.com/help/how-to-ask – kgrg Mar 29 '19 at 19:26
  • Are you using Google Tag Manager? If you are, then this is pretty easy to achieve and I can give you an example. – MandyShaw Mar 31 '19 at 16:05
  • @MandyShaw Yes. I am using GTM. Please let me know what can I do. Thanks in advance. – makrand patne Mar 31 '19 at 18:22
  • I will put together an answer for you, but please edit your question to explain that you are using GTM, because it currently implies (certainly to me) that you aren't. Thanks. – MandyShaw Mar 31 '19 at 18:47

1 Answers1

0

I have many links to external sites on my website; an example link looks like this:

<a id="Buy" data-itemDescription="(a description)" data-itemValue="2.80" href=http://externalsite?id=6789>

The key things here are the extra attributes before the href: id (used to identify the specific event that occurs when the link is clicked, i.e. in this case a Buy event) and the data-itemDescription and data-itemValue metadata (used in constructing the event label etc.)

The relevant GTM artefacts are as follows:

Trigger:

Buy: Click - Just Links when Click Id contains Buy

User-defined variables (custom Javascript):

ItemDescription:

function() {
  return {{Click Element}}.getAttribute("data-itemDescription");
  }

ItemValue:

function() {
  return {{Click Element}}.getAttribute("data-itemValue");
  }

ItemValueFloat (100 multiplier used because GA didn't like my decimal places - I then divide by 100 at reporting time to get the right answer):

function() {
  return parseFloat({{ItemValue}})*100;
  }

Tag BuyClicked is an Event triggered by the Buy trigger as above, with:

Category = Purchase Tracking

Action = Purchase {{ItemDescription}}

Label = {{Page Path}} : {{Click URL}}

Value = {{ItemValueFloat}}

I also have Non-Interaction Hit set True.

The BuyClicked event is then collected by GA, and reportable on from e.g. Google Data Studio, without my having to do anything further.

If you can't add an id or metadata, you could undoubtedly do the same sort of thing more painfully by handling all clicks through a single trigger and then parsing the Click URL via custom Javascript to get granular Categories, Actions, Labels.

MandyShaw
  • 1,088
  • 3
  • 14
  • 22