User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

Google deprecated ga.js (Classic Analytics) in favor of analytics.js (Universal Analytics) in 2014. Sites still running _gaq.push calls risk silent data loss: the legacy library may stop receiving updates at any time, custom dimensions replace custom variables with a hard limit of 5 slots vs. 20, and cross-domain tracking semantics changed entirely. Manual migration is error-prone because argument order differs between the two APIs. For example, _trackEvent takes 4 positional strings while ga('send','event',...) uses named fields. This converter parses each _gaq.push call, identifies the method signature, remaps arguments to the Universal Analytics equivalent, and outputs clean ga() calls. It handles the snippet replacement, ecommerce plugin loading, campaign timeouts (converted from milliseconds to seconds), sample rates, and domain configuration. It does not guess intent. Lines it cannot map are flagged with a comment so you can review them manually.

google analytics ga.js analytics.js universal analytics code converter migration tool gaq push javascript converter

Formulas

The converter applies a deterministic mapping function for each ga.js call. Given an input statement S containing a method call m with arguments a1, a2, โ€ฆ, an, the output is:

O = Map(m, [a1, a2, โ€ฆ, an])

where Map is a lookup dictionary of 26 method signatures. Some methods require argument reordering. For _trackEvent:

_gaq.push(["_trackEvent", cat, act, lbl, val]) โ†’ ga("send", "event", cat, act, lbl, val)

For time-based settings, a unit conversion is applied:

seconds = milliseconds1000

Where m is the ga.js method name string, ai are the original positional arguments, O is the output Analytics.js statement, cat = event category, act = event action, lbl = event label, val = numeric event value. Lines that contain no recognized ga.js pattern pass through unmodified. Unmappable methods are preserved as comments prefixed with /* UNMAPPED */.

Reference Data

ga.js MethodAnalytics.js EquivalentNotes
_setAccountga('create', id, 'auto')Tracker creation
_trackPageviewga('send', 'pageview')Optional page path argument preserved
_trackEventga('send', "event", ...)Category, Action, Label, Value mapped positionally
_setCustomVarga('set', "dimension" + index, value)Slot index becomes dimension number; scope dropped
_addTransga('ecommerce:addTransaction', {...})Requires ecommerce plugin
_addItemga('ecommerce:addItem', {...})Requires ecommerce plugin
_trackTransga('ecommerce:send')Dispatches queued transactions
_setDomainNamega('create', id, {cookieDomain: ...})Merged into create call
_setAllowLinkerga('require', 'linker')Requires linker plugin
_linkga('linker:decorate', ...)Cross-domain link decoration
_setAllowHash// removedHash-based cookies no longer used
_setCookiePathga('create', id, {cookiePath: ...})Merged into create options
_setSampleRatega('create', id, {sampleRate: ...})Value is percentage (0 - 100)
_setSiteSpeedSampleRatega('create', id, {siteSpeedSampleRate: ...})Default is 1%
_setCampaignCookieTimeoutga('create', id, {campaignTimeout: ...})Converted from ms to seconds
_setVisitorCookieTimeout// removedNo direct equivalent; use cookie expiration
_trackSocialga('send', "social", ...)Network, Action, Target mapped
_trackTimingga('send', "timing", ...)Category, Variable, Value, Label
_setAllowAnchorga('create', id, {allowAnchor: ...})Boolean preserved
_anonymizeIpga('set', "anonymizeIp", true)GDPR-relevant setting
_requirega('require', pluginName)Plugin loading
_get// not directly mappableUse ga(function(t){t.get(...)})
_deleteCustomVarga('set', "dimension" + index, '')Set to empty string
_setSessionCookieTimeoutga('create', id, {sessionTimeout: ...})Converted from ms to minutes
_addOrganic// removedOrganic source config no longer supported
_addIgnoredOrganic// removedBranded terms exclusion handled in GA UI
_addIgnoredRef// removedReferral exclusions handled in GA UI

Frequently Asked Questions

Yes. If the input uses the named-tracker pattern (e.g., _gaq.push(['tracker._trackPageview'])), the converter extracts the tracker name and prefixes the Analytics.js call accordingly: ga('tracker.send', 'pageview'). The create call also receives the name option.
ga.js custom variables use _setCustomVar(index, name, value, scope) with index values 1 through 5. The converter maps them to ga('set', "dimension" + index, value). The scope parameter (page, session, visitor) has no direct Analytics.js equivalent in code - you must configure scope in the Google Analytics admin. The converter adds a comment reminding you of the original scope.
The converter detects _addTrans, _addItem, and _trackTrans calls and converts them to the ecommerce plugin syntax. It also inserts ga('require', 'ecommerce') before the first ecommerce call if it is not already present. Argument positions are mapped to named fields (id, affiliation, revenue, shipping, tax, etc.).
Yes. If the input contains the classic ga.js async snippet (var ga = document.createElement('script')... with google-analytics.com/ga.js), the converter replaces the entire block with the standard Analytics.js snippet including the minified inline loader and the analytics.js URL.
ga.js _setCampaignCookieTimeout accepts milliseconds. Analytics.js campaignTimeout uses seconds. The converter divides the value by 1000. Similarly, _setSessionCookieTimeout (milliseconds) is converted to sessionTimeout in minutes by dividing by 60000. The converter rounds to the nearest integer and adds a comment showing the original value.
Methods like _addOrganic, _addIgnoredOrganic, _addIgnoredRef, _setAllowHash, and _setVisitorCookieTimeout have no Analytics.js equivalent. The converter comments them out and adds a note explaining that the functionality is either removed or must be configured through the Google Analytics admin interface. No data is silently dropped.
ga.js supports two push formats: array-based (_gaq.push(['_trackPageview'])) and function-based (_gaq.push(function() { var t = _gat._getTrackerByName(); ... })). The converter handles array-based calls fully. Function-based pushes are preserved verbatim with a /* MANUAL REVIEW NEEDED */ comment, because they typically contain imperative logic that cannot be mechanically translated.