The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Affiliate Marketing
    4. Passing Google Analytics Variables Through Javascript?

    Passing Google Analytics Variables Through Javascript?

    Affiliate Marketing
    2 2 1.4k
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • drewhammond
      drewhammond last edited by

      Alright so here's my situation and hopefully someone can help...

      I want to be able to pass Google Analytics variables onto my affiliate links so I have some better conversion tracking data (not PPC traffic so no easy dynamic keyword insertion variables).

      I want to do something like this:

      User searches "keyword" in Google > User lands on mysite.com > search data is assigned to global variables that I can use in my affiliate link redirect script.

      afflink.com/?id=123&keyword=[GA keyword variable]

      Anybody know how I would go about doing that? I've seen other Non-GA tracking scripts do this but I can't figure it out here and it's driving me crazy!

      Thanks,
      Drew

      EDIT: Just figured it out after a lot of guess and testing... I'm not sure if the way I'm doing it is the fastest, most optimized way but it works.

      Solution: I can pull the GA cookie and break it down to retrieve the keyword using PHP. For anyone searching for this in the future, here's how I did it:

      $gacookie = $_COOKIE['__utmz'];
      $keyword = substr(strstr($gacookie, 'utmctr='),7);

      ?>

      Then I can use the $keyword variable wherever I need it. I haven't actually tested this on a live site yet but everything is working fine as of right now.

      If anyone has a better solution please feel free to answer.

      1 Reply Last reply Reply Quote 0
      • moldybacon
        moldybacon last edited by

        I'm not sure if this is what you mean..

        You want the keyword from a google search to show up on your afflink?

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        • First post
          Last post
        • Why do my Google Analytics campaign URLs not show up in reports?
          NHA_DistanceLearning
          NHA_DistanceLearning
          0
          3
          5.3k

        • How to rank in google local listings with multiple entities?
          mememax
          mememax
          0
          7
          550

        • Google Penalty
          wgr_strategic
          wgr_strategic
          0
          7
          535

        • Who are the top google adsense websites
          lethal0r
          lethal0r
          0
          3
          516

        • How accurate is google analytics?
          OlgaG
          OlgaG
          0
          2
          1.9k

        • How Google Shopping Relevance Determined?
          BlinkWeb
          BlinkWeb
          0
          2
          1.6k

        • How long will it take for Google to forgive us?
          footsteps
          footsteps
          0
          3
          1.4k

        Get started with Moz Pro!

        Unlock the power of advanced SEO tools and data-driven insights.

        Start my free trial
        Products
        • Moz Pro
        • Moz Local
        • Moz API
        • Moz Data
        • STAT
        • Product Updates
        Moz Solutions
        • SMB Solutions
        • Agency Solutions
        • Enterprise Solutions
        • Digital Marketers
        Free SEO Tools
        • Domain Authority Checker
        • Link Explorer
        • Keyword Explorer
        • Competitive Research
        • Brand Authority Checker
        • Local Citation Checker
        • MozBar Extension
        • MozCast
        Resources
        • Blog
        • SEO Learning Center
        • Help Hub
        • Beginner's Guide to SEO
        • How-to Guides
        • Moz Academy
        • API Docs
        About Moz
        • About
        • Team
        • Careers
        • Contact
        Why Moz
        • Case Studies
        • Testimonials
        Get Involved
        • Become an Affiliate
        • MozCon
        • Webinars
        • Practical Marketer Series
        • MozPod
        Connect with us

        Contact the Help team

        Join our newsletter
        Moz logo
        © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
        • Accessibility
        • Terms of Use
        • Privacy