segmentio / segmentio/analytics.js-integrations

[google-analytics] Preset clientId

Open
#202 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
125
Forks
136
Avg merge
2h 45m
Merged PRs (30d)
1

Description

Hi, in Google Analytics it is possible to preset the client id like this:

ga('create', 'UA-XXXXX-Y', 'auto', {
  'clientId': 'ourOwnDefinedId'
});

Sadly the Segment library does not allow customisations to this call. Having this option would help us a lot to tie everything together with server-side events. We generate an id per session and would like to pass this into GA as clientId.

The config for the create call is set up here:
https://github.com/segmentio/analytics.js-integrations/blob/79ae188cb3f0c0ef4c2178fd95cb7daae4a22639/integrations/google-analytics/lib/index.js#L123

Is there some precedence for programmatically passing options into analytics.js? My first thought was a global like:

const SEGMENT_GOOGLE_ANALYTICS_CLIENT_ID=<whatever custom logic I need to get it>;

Before the Segment snippet.

Segment support pointed me here from ticket 355364

Thanks! Let me know if you need more information.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in integrations/google-analytics/lib/index.js at the linked create-call configuration around line 123, and review how this integration accepts options. Determine how a caller could provide a custom Google Analytics clientId, then verify that the create call uses it without breaking existing configuration behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
analytics
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.